diff --git a/plugins/Math.py b/plugins/Math.py index 26c73edbf..e1f779621 100644 --- a/plugins/Math.py +++ b/plugins/Math.py @@ -127,6 +127,7 @@ class Math(callbacks.Privmsg): text = privmsgs.getArgs(args) text = text.translate(string.ascii, '_[] \t') text = text.replace('lambda', '') + #debug.printf(text) def handleMatch(m): s = m.group(1) if s.startswith('0x'): @@ -138,8 +139,12 @@ class Math(callbacks.Privmsg): i = int(s) else: i = float(s) - return str(complex(i)) + x = complex(i) + if x == abs(x): + x = abs(x) + return str(x) text = self._mathRe.sub(handleMatch, text) + #debug.printf(text) try: x = complex(eval(text, self._mathEnv, self._mathEnv)) irc.reply(msg, self._complexToString(x)) diff --git a/test/test_Math.py b/test/test_Math.py index 8a36bf89c..24d7ba154 100644 --- a/test/test_Math.py +++ b/test/test_Math.py @@ -42,6 +42,7 @@ class MathTestCase(PluginTestCase, PluginDocumentation): self.assertResponse('calc -((-5)**.5)', '-2.2360679775i') self.assertNotRegexp('calc [9, 5] + [9, 10]', 'TypeError') self.assertError('calc [9, 5] + [9, 10]') + self.assertNotError('calc degrees(2)') def testRpn(self): self.assertResponse('rpn 5 2 +', '7')