diff --git a/plugins/Math.py b/plugins/Math.py index 1b2b47f9a..f05e1f929 100644 --- a/plugins/Math.py +++ b/plugins/Math.py @@ -90,6 +90,12 @@ class Math(callbacks.Privmsg): _mathEnv = {'__builtins__': types.ModuleType('__builtins__'), 'i': 1j} _mathEnv.update(math.__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'((?:(? diff --git a/test/test_Math.py b/test/test_Math.py index c472e28c5..f71051463 100644 --- a/test/test_Math.py +++ b/test/test_Math.py @@ -56,6 +56,9 @@ class MathTestCase(PluginTestCase, PluginDocumentation): def testCalcImaginary(self): self.assertResponse('calc 3 + sqrt(-1)', '3+i') + + def testCalcFloorWorksWithSqrt(self): + self.assertNotError('calc floor(sqrt(5))') def testRpn(self): self.assertResponse('rpn 5 2 +', '7')