mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Fixed bug in calc.
This commit is contained in:
parent
46cf8bb6fd
commit
d25b3894d7
@ -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))
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user