]> git.donarmstrong.com Git - lilypond.git/commitdiff
* python/rational.py: PD rational number class.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 5 Dec 2005 13:49:59 +0000 (13:49 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 5 Dec 2005 13:49:59 +0000 (13:49 +0000)
* Documentation/user/converters.itely (Invoking musicxml2ly):  new node.

Documentation/user/converters.itely
lily/hyphen-engraver.cc
python/rational.py

index 9d46c6d97c579a7ec85c52d168151a349236d487..2e774821c25809536812012cb26a19c384d59388 100644 (file)
@@ -14,6 +14,7 @@ sequencers and XML converters.  Refer to the
 @menu
 * Invoking midi2ly::            Importing MIDI.
 * Invoking etf2ly::             Importing Finale.
+* Invoking musicxml2ly::        
 * Invoking abc2ly::             Importing ABC.          
 * Invoking mup2ly::             Importing MUP. 
 * Generating LilyPond files::   
index 8628033eb945492cc25478bb000fcc8bf8ed851f..0f54038353711516dba07a74393f3aad481ef370 100644 (file)
@@ -129,6 +129,7 @@ Hyphen_engraver::stop_translation_timestep ()
 #include "translator.icc"
 
 ADD_ACKNOWLEDGER (Hyphen_engraver, lyric_syllable);
+
 ADD_TRANSLATOR (Hyphen_engraver,
                /* doc */ "Create lyric hyphens",
                /* create */ "LyricHyphen",
index fc6fd169b5084390d1cdf7b9abc43dff0a0f36f6..1c0206dee76ec688f70679039cd560306734c049 100644 (file)
@@ -198,65 +198,69 @@ class Rational(object):
         else:
            numerator = int_part + 1
         return Rational(numerator, denominator)
-    @staticmethod
-    def from_exact_float(x):
-        """Returns the exact Rational equivalent of x."""
-        mantissa, exponent = _math.frexp(x)
-        mantissa = int(mantissa * 2 ** 53)
-        exponent -= 53
-        if exponent < 0:
-            return Rational(mantissa, 2 ** (-exponent))
-        else:
-            return Rational(mantissa * 2 ** exponent)
-    @staticmethod
-    def 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)
-    @staticmethod
-    def approx_smallest_denominator(x, tolerance):
-        """
-        Returns a Rational approximation of x.
-        Minimizes the denominator given a constraint on the error.
-        
-        x = the float or Decimal value to convert
-        tolerance = maximum absolute error allowed,
-                    must be of the same type as x
-        """
-        tolerance = abs(tolerance)
-        n = 1
-        while True:
-            m = int(round(x * n))
-            result = Rational(m, n)
-            if abs(result - x) < tolerance:
-                return result
-            n += 1
-    @staticmethod
-    def approx_smallest_error(x, maxDenominator):
-        """
-        Returns a Rational approximation of x.
-        Minimizes the error given a constraint on the denominator.
-        
-        x = the float or Decimal value to convert
-        maxDenominator = maximum denominator allowed
-        """
-        result = None
-        minError = x
-        for n in xrange(1, maxDenominator + 1):
-            m = int(round(x * n))
-            r = Rational(m, n)
-            error = abs(r - x)
-            if error == 0:
-                return r
-            elif error < minError:
-                result = r
-                minError = error
-        return result
+
+
+
+def rational_from_exact_float(x):
+    """Returns the exact Rational equivalent of x."""
+    mantissa, exponent = _math.frexp(x)
+    mantissa = int(mantissa * 2 ** 53)
+    exponent -= 53
+    if exponent < 0:
+        return Rational(mantissa, 2 ** (-exponent))
+    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):
+    """
+    Returns a Rational approximation of x.
+    Minimizes the denominator given a constraint on the error.
+
+    x = the float or Decimal value to convert
+    tolerance = maximum absolute error allowed,
+                must be of the same type as x
+    """
+    tolerance = abs(tolerance)
+    n = 1
+    while True:
+        m = int(round(x * n))
+        result = Rational(m, n)
+        if abs(result - x) < tolerance:
+            return result
+        n += 1
+
+
+def rational_approx_smallest_error(x, maxDenominator):
+    """
+    Returns a Rational approximation of x.
+    Minimizes the error given a constraint on the denominator.
+
+    x = the float or Decimal value to convert
+    maxDenominator = maximum denominator allowed
+    """
+    result = None
+    minError = x
+    for n in xrange(1, maxDenominator + 1):
+        m = int(round(x * n))
+        r = Rational(m, n)
+        error = abs(r - x)
+        if error == 0:
+            return r
+        elif error < minError:
+            result = r
+            minError = error
+    return result
 
 def divide(x, y):
     """Same as x/y, but returns a Rational if both are ints."""