mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Math.calc: allow factorial for smallish numbers
This commit is contained in:
parent
1aeb847509
commit
97c7d0a9c3
@ -110,13 +110,18 @@ class Math(callbacks.Plugin):
|
|||||||
return math.sqrt(x)
|
return math.sqrt(x)
|
||||||
def _cbrt(x):
|
def _cbrt(x):
|
||||||
return math.pow(x, 1.0/3)
|
return math.pow(x, 1.0/3)
|
||||||
|
def _factorial(x):
|
||||||
|
if x<=10000:
|
||||||
|
return math.factorial(x)
|
||||||
|
else:
|
||||||
|
raise Exception('factorial argument too large')
|
||||||
_mathEnv['sqrt'] = _sqrt
|
_mathEnv['sqrt'] = _sqrt
|
||||||
_mathEnv['cbrt'] = _cbrt
|
_mathEnv['cbrt'] = _cbrt
|
||||||
_mathEnv['abs'] = abs
|
_mathEnv['abs'] = abs
|
||||||
_mathEnv['max'] = max
|
_mathEnv['max'] = max
|
||||||
_mathEnv['min'] = min
|
_mathEnv['min'] = min
|
||||||
_mathSafeEnv = dict([(x,y) for x,y in _mathEnv.items()
|
_mathSafeEnv = dict([(x,y) for x,y in _mathEnv.items()])
|
||||||
if x not in ['factorial']])
|
_mathSafeEnv['factorial'] = _factorial
|
||||||
_mathRe = re.compile(r'((?:(?<![A-Fa-f\d)])-)?'
|
_mathRe = re.compile(r'((?:(?<![A-Fa-f\d)])-)?'
|
||||||
r'(?:0x[A-Fa-f\d]+|'
|
r'(?:0x[A-Fa-f\d]+|'
|
||||||
r'0[0-7]+|'
|
r'0[0-7]+|'
|
||||||
|
@ -114,7 +114,7 @@ class MathTestCase(PluginTestCase):
|
|||||||
self.assertNotError('calc (1600 * 1200) - 2*(1024*1280)')
|
self.assertNotError('calc (1600 * 1200) - 2*(1024*1280)')
|
||||||
self.assertNotError('calc 3-2*4')
|
self.assertNotError('calc 3-2*4')
|
||||||
self.assertNotError('calc (1600 * 1200)-2*(1024*1280)')
|
self.assertNotError('calc (1600 * 1200)-2*(1024*1280)')
|
||||||
self.assertError('calc factorial(99)')
|
self.assertError('calc factorial(20000)')
|
||||||
|
|
||||||
def testCalcNoNameError(self):
|
def testCalcNoNameError(self):
|
||||||
self.assertNotRegexp('calc foobar(x)', 'NameError')
|
self.assertNotRegexp('calc foobar(x)', 'NameError')
|
||||||
@ -139,7 +139,7 @@ class MathTestCase(PluginTestCase):
|
|||||||
self.assertResponse('icalc 1^1', '0')
|
self.assertResponse('icalc 1^1', '0')
|
||||||
self.assertResponse('icalc 10**24', '1' + '0'*24)
|
self.assertResponse('icalc 10**24', '1' + '0'*24)
|
||||||
self.assertRegexp('icalc 49/6', '8.16')
|
self.assertRegexp('icalc 49/6', '8.16')
|
||||||
self.assertNotError('icalc factorial(99)')
|
self.assertNotError('icalc factorial(20000)')
|
||||||
|
|
||||||
def testRpn(self):
|
def testRpn(self):
|
||||||
self.assertResponse('rpn 5 2 +', '7')
|
self.assertResponse('rpn 5 2 +', '7')
|
||||||
|
Loading…
Reference in New Issue
Block a user