Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/mathlib.py
diff options
context:
space:
mode:
authorReinier Heeres <reinier@heeres.eu>2007-11-18 19:34:59 (GMT)
committer Reinier Heeres <reinier@heeres.eu>2007-11-18 19:34:59 (GMT)
commitf8a8343c92f8ab54614660c235c6e6c18e5464db (patch)
treec61d024118ce3dc7ca3da8b9e210a65601b9f6e6 /mathlib.py
parent29e05573dd8f69fe474433dac8873fab7aeda6f0 (diff)
Included support for rational numbers
Diffstat (limited to 'mathlib.py')
-rw-r--r--mathlib.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/mathlib.py b/mathlib.py
index 6693bc6..ff17de5 100644
--- a/mathlib.py
+++ b/mathlib.py
@@ -20,6 +20,7 @@
import types
import math
from decimal import Decimal
+from rational import Rational
import random
import logging
@@ -103,7 +104,10 @@ class MathLib:
def parse_number(self, s):
try:
d = Decimal(s)
- return Decimal(s)
+ if self.is_int(d):
+ return int(d)
+ else:
+ return Decimal(s)
except Exception, inst:
return None
@@ -125,6 +129,8 @@ class MathLib:
n = self.d(n)
elif type(n) is types.LongType:
n = self.d(n)
+ elif isinstance(n, Rational):
+ n = self.d(float(n))
elif not isinstance(n, Decimal):
return _('Error: unsupported type')
(sign, digits, exp) = n.as_tuple()