]> git.donarmstrong.com Git - lilypond.git/commitdiff
* python/rational.py: python 2.3 compat.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 5 Dec 2005 13:54:28 +0000 (13:54 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 5 Dec 2005 13:54:28 +0000 (13:54 +0000)
* python/rational.py: PD rational number class.

ChangeLog
python/rational.py

index 1ef20720a9a05e021a973eabec32553361a9d406..4d68a41a6346e8e5917f223c715b218931adb296 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2005-12-05  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * python/rational.py: python 2.3 compat.
+
        * scripts/musicxml2ly.py (NonDentedHeadingFormatter.format_headi):
        option formatting, lilypond style.
 
index 1c0206dee76ec688f70679039cd560306734c049..e3c93d9c17c55745d352f132325ce63cea793de8 100644 (file)
@@ -95,8 +95,6 @@ class Rational(object):
             return Rational(self._n + self._d * other, self._d)
         elif isinstance(other, (float, complex)):
             return float(self) + other
-        elif isinstance(other, _decimal.Decimal):
-            return self.decimal() + other
         else:
             return NotImplemented
     __radd__ = __add__
@@ -108,8 +106,6 @@ class Rational(object):
             return Rational(self._n - self._d * other, self._d)
         elif isinstance(other, (float, complex)):
             return float(self) - other
-        elif isinstance(other, _decimal.Decimal):
-            return self.decimal() - other
         else:
             return NotImplemented
     def __rsub__(self, other):
@@ -117,8 +113,6 @@ class Rational(object):
             return Rational(other * self._d - self._n, self._d)
         elif isinstance(other, (float, complex)):
             return other - float(self)
-        elif isinstance(other, _decimal.Decimal):
-            return other - self.decimal()
         else:
             return NotImplemented
     def __mul__(self, other):
@@ -128,8 +122,6 @@ class Rational(object):
             return Rational(self._n * other, self._d)
         elif isinstance(other, (float, complex)):
             return float(self) * other
-        elif isinstance(other, _decimal.Decimal):
-            return self.decimal() * other
         else:
             return NotImplemented
     __rmul__ = __mul__
@@ -140,8 +132,6 @@ class Rational(object):
             return Rational(self._n, self._d * other)
         elif isinstance(other, (float, complex)):
             return float(self) / other
-        elif isinstance(other, _decimal.Decimal):
-            return self.decimal() / other
         else:
             return NotImplemented
     __div__ = __truediv__
@@ -150,8 +140,6 @@ class Rational(object):
             return Rational(other * self._d, self._n)
         elif isinstance(other, (float, complex)):
             return other / float(self)
-        elif isinstance(other, _decimal.Decimal):
-            return other / self.decimal()
         else:
             return NotImplemented
     __rdiv__ = __rtruediv__
@@ -184,9 +172,6 @@ class Rational(object):
                 return float(self) ** other
     def __rpow__(self, other):
         return other ** float(self)
-    def decimal(self):
-        """Return a Decimal approximation of self in the current context."""
-        return _decimal.Decimal(self._n) / _decimal.Decimal(self._d)
     def round(self, denominator):
         """Return self rounded to nearest multiple of 1/denominator."""
         int_part, frac_part = divmod(self * denominator, 1)
@@ -211,15 +196,6 @@ def rational_from_exact_float(x):
     else:
         return Rational(mantissa * 2 ** exponent)
 
-def rational_from_exact_decimal(x):
-    """Returns the exact Rational equivalent of x."""
-    sign, mantissa, exponent = x.as_tuple()
-    sign = (1, -1)[sign]
-    mantissa = sign * reduce(lambda a, b: 10 * a + b, mantissa)
-    if exponent < 0:
-        return Rational(mantissa, 10 ** (-exponent))
-    else:
-        return Rational(mantissa * 10 ** exponent)
 
 
 def rational_approx_smallest_denominator(x, tolerance):