Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReinier Heeres <reinier@heeres.eu>2007-11-18 13:57:40 (GMT)
committer Reinier Heeres <reinier@heeres.eu>2007-11-18 13:57:40 (GMT)
commit29e05573dd8f69fe474433dac8873fab7aeda6f0 (patch)
tree656b9ed786a101c13733c69287682eedcbbaca27
parente1d3a590bb967f00dbf95348bbd3f45afdfbf397 (diff)
Fixed large factorial issue
-rw-r--r--eqnparser.py2
-rw-r--r--mathlib.py26
2 files changed, 23 insertions, 5 deletions
diff --git a/eqnparser.py b/eqnparser.py
index 4895918..3264da2 100644
--- a/eqnparser.py
+++ b/eqnparser.py
@@ -545,7 +545,7 @@ class EqnParser:
return None
res = of([left_val, right_val])
- _logger.debug('OP: %s, %s ==> %s', self.ml.format_number(left_val), self.ml.format_number(right_val), self.ml.format_number(res))
+ _logger.debug('OP: %s (%r), %s (%r) ==> %s (%r)', self.ml.format_number(left_val), left_val, self.ml.format_number(right_val), right_val, self.ml.format_number(res), res)
left_val = res
right_val = None
op = None
diff --git a/mathlib.py b/mathlib.py
index 77ab2c2..6693bc6 100644
--- a/mathlib.py
+++ b/mathlib.py
@@ -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):