Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/mathlib.py
diff options
context:
space:
mode:
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()