Fixed bug in calc.

This commit is contained in:
Jeremy Fincher 2003-08-15 00:42:35 +00:00
parent 46cf8bb6fd
commit d25b3894d7
2 changed files with 7 additions and 4 deletions

View File

@ -386,7 +386,7 @@ class FunCommands(callbacks.Privmsg):
_mathEnv.update(cmath.__dict__)
_mathInt = re.compile(r'(?<!\d|\.)(\d+)(?!\d+|\.|\.\d+)')
_mathHex = re.compile(r'(0x[A-Fa-f\d]+)')
_mathOctal = re.compile(r'(^|[^\dA-Fa-f])(0[0-7]+)')
_mathOctal = re.compile(r'(^|[^\dA-Fa-f.])(0[0-7]+)')
def _complexToString(self, x):
real = x.real
imag = x.imag
@ -425,11 +425,11 @@ class FunCommands(callbacks.Privmsg):
i = long(literal, 8)
return '%s%s.0' % (previous, i)
text = self._mathHex.sub(hex2float, text)
#debug.printf('After unhexing: %r' % text)
debug.printf('After unhexing: %r' % text)
text = self._mathOctal.sub(oct2float, text)
#debug.printf('After unocting: %r' % text)
debug.printf('After unocting: %r' % text)
text = self._mathInt.sub(r'\1.0', text)
#debug.printf('After uninting: %r' % text)
debug.printf('After uninting: %r' % text)
try:
x = complex(eval(text, self._mathEnv, self._mathEnv))
irc.reply(msg, self._complexToString(x))

View File

@ -39,3 +39,6 @@ class FunCommandsTest(PluginTestCase):
def testRot13(self):
for s in nicks[:10]: # 10 is probably enough.
self.assertResponse('rot13 [rot13 %s]' % s, s)
def testCalc(self):
self.assertResponse('calc 5*0.06', str(5*0.06))