mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-12 05:02:32 +01:00
Added dup to rpn and fixed bug with calc and rpn commands that they couldn't do negative values.
This commit is contained in:
parent
0bcffe0d3e
commit
1795229d85
@ -502,15 +502,15 @@ class FunCommands(callbacks.Privmsg):
|
|||||||
def _complexToString(self, x):
|
def _complexToString(self, x):
|
||||||
real = x.real
|
real = x.real
|
||||||
imag = x.imag
|
imag = x.imag
|
||||||
if real < 1e-12 and imag < 1e-12:
|
if -1e-12 < real < 1e-12 and -1e-12 < imag < 1e-12:
|
||||||
return '0'
|
return '0'
|
||||||
if int(real) == real:
|
if int(real) == real:
|
||||||
real = int(real)
|
real = int(real)
|
||||||
if int(imag) == imag:
|
if int(imag) == imag:
|
||||||
imag = int(imag)
|
imag = int(imag)
|
||||||
if real < 1e-12:
|
if -1e-12 < real < 1e-12:
|
||||||
real = 0
|
real = 0
|
||||||
if imag < 1e-12:
|
if -1e-12 < imag < 1e-12:
|
||||||
imag = 0
|
imag = 0
|
||||||
if imag == 0:
|
if imag == 0:
|
||||||
return str(real)
|
return str(real)
|
||||||
@ -550,6 +550,9 @@ class FunCommands(callbacks.Privmsg):
|
|||||||
except Exception, e:
|
except Exception, e:
|
||||||
irc.reply(msg, debug.exnToString(e))
|
irc.reply(msg, debug.exnToString(e))
|
||||||
|
|
||||||
|
_rpnEnv = {
|
||||||
|
'dup': lambda s: s.extend([s.pop()]*2),
|
||||||
|
}
|
||||||
def rpn(self, irc, msg, args):
|
def rpn(self, irc, msg, args):
|
||||||
"""<rpn math expression>
|
"""<rpn math expression>
|
||||||
|
|
||||||
@ -577,11 +580,13 @@ class FunCommands(callbacks.Privmsg):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
stack.append(f)
|
stack.append(f)
|
||||||
|
elif arg in self._rpnEnv:
|
||||||
|
self._rpnEnv[arg](stack)
|
||||||
else:
|
else:
|
||||||
arg2 = stack.pop()
|
arg2 = stack.pop()
|
||||||
arg1 = stack.pop()
|
arg1 = stack.pop()
|
||||||
stack.append(eval('%s%s%s' % (arg1, arg, arg2),
|
s = '%s%s%s' % (arg1, arg, arg2)
|
||||||
self._mathEnv, self._mathEnv))
|
stack.append(eval(s, self._mathEnv, self._mathEnv))
|
||||||
if len(stack) == 1:
|
if len(stack) == 1:
|
||||||
irc.reply(msg, str(self._complexToString(complex(stack[0]))))
|
irc.reply(msg, str(self._complexToString(complex(stack[0]))))
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user