diff options
author | Reinier Heeres <rwh@rwh.(none)> | 2008-02-17 23:52:16 (GMT) |
---|---|---|
committer | Reinier Heeres <rwh@rwh.(none)> | 2008-02-17 23:52:16 (GMT) |
commit | 18fc43a2e3ea1e143108848c203007a4c17b6dcc (patch) | |
tree | 72e27e8e1df2015027dc8b386e046a27b701df62 | |
parent | 8ee6390e4a21151176acb7e134a79835531eb898 (diff) |
Fix Decimal operator issues, #6478
-rw-r--r-- | mathlib.py | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -222,15 +222,27 @@ class MathLib: return self.d(math.fabs(x)) def add(self, x, y): + if isinstance(x, Decimal) or isinstance(y, Decimal): + x = self.d(x) + y = self.d(y) return x + y def sub(self, x, y): + if isinstance(x, Decimal) or isinstance(y, Decimal): + x = self.d(x) + y = self.d(y) return x - y def mul(self, x, y): + if isinstance(x, Decimal) or isinstance(y, Decimal): + x = self.d(x) + y = self.d(y) return x * y def div(self, x, y): + if isinstance(x, Decimal) or isinstance(y, Decimal): + x = self.d(x) + y = self.d(y) if y == 0: return None else: @@ -238,8 +250,14 @@ class MathLib: def pow(self, x, y): if self.is_int(y): - return float(x) ** int(y) + if self.is_int(x): + return long(x) ** int(y) + else: + return float(x) ** int(y) else: + if isinstance(x, Decimal) or isinstance(y, Decimal): + x = self.d(x) + y = self.d(y) return self.d(math.pow(float(x), float(y))) def sqrt(self, x): |