diff options
author | Reinier Heeres <reinier@heeres.eu> | 2007-11-18 19:34:59 (GMT) |
---|---|---|
committer | Reinier Heeres <reinier@heeres.eu> | 2007-11-18 19:34:59 (GMT) |
commit | f8a8343c92f8ab54614660c235c6e6c18e5464db (patch) | |
tree | c61d024118ce3dc7ca3da8b9e210a65601b9f6e6 /mathlib.py | |
parent | 29e05573dd8f69fe474433dac8873fab7aeda6f0 (diff) |
Included support for rational numbers
Diffstat (limited to 'mathlib.py')
-rw-r--r-- | mathlib.py | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -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() |