diff options
author | Reinier Heeres <reinier@heeres.eu> | 2007-11-18 13:57:40 (GMT) |
---|---|---|
committer | Reinier Heeres <reinier@heeres.eu> | 2007-11-18 13:57:40 (GMT) |
commit | 29e05573dd8f69fe474433dac8873fab7aeda6f0 (patch) | |
tree | 656b9ed786a101c13733c69287682eedcbbaca27 /mathlib.py | |
parent | e1d3a590bb967f00dbf95348bbd3f45afdfbf397 (diff) |
Fixed large factorial issue
Diffstat (limited to 'mathlib.py')
-rw-r--r-- | mathlib.py | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -88,9 +88,17 @@ class MathLib: return None def d(self, val): - s = '%.10e' % val - d = Decimal(s) - return d.normalize() + if isinstance(val, Decimal): + return val + elif type(val) is types.FloatType or type(val) is types.IntType: + s = '%.10e' % val + d = Decimal(s) + return d.normalize() + elif type(val) is types.StringType or type(val) is types.LongType: + d = Decimal(val) + return d.normalize() + else: + return None def parse_number(self, s): try: @@ -115,6 +123,8 @@ class MathLib: n = self.d(n) elif type(n) is types.FloatType: n = self.d(n) + elif type(n) is types.LongType: + n = self.d(n) elif not isinstance(n, Decimal): return _('Error: unsupported type') (sign, digits, exp) = n.as_tuple() @@ -171,6 +181,12 @@ class MathLib: return ret def is_int(self, n): + if type(n) is types.IntType: + return True + + if not isinstance(n, Decimal): + n = self.d(n) + (sign, d, e) = n.normalize().as_tuple() return e >= 0 @@ -244,10 +260,12 @@ class MathLib: if n == 0: return 1 - res = n + n = long(n) + res = long(n) while n > 2: res *= n - 1 n -= 1 + return res def sin(self, x): |