From 1795229d85fe139e504e0b0d82dd6c53f93a68f7 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 6 Sep 2003 05:25:05 +0000 Subject: [PATCH] Added dup to rpn and fixed bug with calc and rpn commands that they couldn't do negative values. --- plugins/FunCommands.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/FunCommands.py b/plugins/FunCommands.py index 55a7da1ec..f27bd1edf 100644 --- a/plugins/FunCommands.py +++ b/plugins/FunCommands.py @@ -502,15 +502,15 @@ class FunCommands(callbacks.Privmsg): def _complexToString(self, x): real = x.real 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' if int(real) == real: real = int(real) if int(imag) == imag: imag = int(imag) - if real < 1e-12: + if -1e-12 < real < 1e-12: real = 0 - if imag < 1e-12: + if -1e-12 < imag < 1e-12: imag = 0 if imag == 0: return str(real) @@ -550,6 +550,9 @@ class FunCommands(callbacks.Privmsg): except Exception, e: irc.reply(msg, debug.exnToString(e)) + _rpnEnv = { + 'dup': lambda s: s.extend([s.pop()]*2), + } def rpn(self, irc, msg, args): """ @@ -577,11 +580,13 @@ class FunCommands(callbacks.Privmsg): return else: stack.append(f) + elif arg in self._rpnEnv: + self._rpnEnv[arg](stack) else: arg2 = stack.pop() arg1 = stack.pop() - stack.append(eval('%s%s%s' % (arg1, arg, arg2), - self._mathEnv, self._mathEnv)) + s = '%s%s%s' % (arg1, arg, arg2) + stack.append(eval(s, self._mathEnv, self._mathEnv)) if len(stack) == 1: irc.reply(msg, str(self._complexToString(complex(stack[0])))) else: