From f8a8343c92f8ab54614660c235c6e6c18e5464db Mon Sep 17 00:00:00 2001 From: Reinier Heeres Date: Sun, 18 Nov 2007 19:34:59 +0000 Subject: Included support for rational numbers --- (limited to 'mathlib.py') 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() -- cgit v0.9.1