mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-06-15 19:27:21 +02:00
Fixed the sqrt bug submitted by kmj.
This commit is contained in:
parent
f3b49e4e88
commit
78eafe3fa6
@ -90,6 +90,12 @@ class Math(callbacks.Privmsg):
|
|||||||
_mathEnv = {'__builtins__': types.ModuleType('__builtins__'), 'i': 1j}
|
_mathEnv = {'__builtins__': types.ModuleType('__builtins__'), 'i': 1j}
|
||||||
_mathEnv.update(math.__dict__)
|
_mathEnv.update(math.__dict__)
|
||||||
_mathEnv.update(cmath.__dict__)
|
_mathEnv.update(cmath.__dict__)
|
||||||
|
def _sqrt(x):
|
||||||
|
if isinstance(x, complex) or x < 0:
|
||||||
|
return cmath.sqrt(x)
|
||||||
|
else:
|
||||||
|
return math.sqrt(x)
|
||||||
|
_mathEnv['sqrt'] = _sqrt
|
||||||
_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]+|'
|
||||||
@ -178,7 +184,7 @@ class Math(callbacks.Privmsg):
|
|||||||
except NameError, e:
|
except NameError, e:
|
||||||
irc.error('%s is not a defined function.' % str(e).split()[1])
|
irc.error('%s is not a defined function.' % str(e).split()[1])
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
irc.error(utils.exnToString(e))
|
irc.error(str(e))
|
||||||
|
|
||||||
def icalc(self, irc, msg, args):
|
def icalc(self, irc, msg, args):
|
||||||
"""<math expression>
|
"""<math expression>
|
||||||
|
@ -57,6 +57,9 @@ class MathTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
def testCalcImaginary(self):
|
def testCalcImaginary(self):
|
||||||
self.assertResponse('calc 3 + sqrt(-1)', '3+i')
|
self.assertResponse('calc 3 + sqrt(-1)', '3+i')
|
||||||
|
|
||||||
|
def testCalcFloorWorksWithSqrt(self):
|
||||||
|
self.assertNotError('calc floor(sqrt(5))')
|
||||||
|
|
||||||
def testRpn(self):
|
def testRpn(self):
|
||||||
self.assertResponse('rpn 5 2 +', '7')
|
self.assertResponse('rpn 5 2 +', '7')
|
||||||
self.assertResponse('rpn 1 2 3 +', 'Stack: [1, 5]')
|
self.assertResponse('rpn 1 2 3 +', 'Stack: [1, 5]')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user