X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=python%2Frational.py;h=5a9ee629b3bcdc56328f9ecc9b9a4951d4fabe56;hb=abf536ef2c251ebf13d7ad9ed432fc3bbb9c5c63;hp=705829e120835269894d3991ad28013208d1d598;hpb=553420c40402e0c5d60363a9078a6bb7584815bc;p=lilypond.git diff --git a/python/rational.py b/python/rational.py index 705829e120..5a9ee629b3 100644 --- a/python/rational.py +++ b/python/rational.py @@ -38,13 +38,18 @@ class Rational(object): raise TypeError('denominator must have integer type') if not denominator: raise ZeroDivisionError('rational construction') - # Store the fraction in reduced form as _n/_d - factor = _gcf(numerator, denominator) - self._n = numerator // factor - self._d = denominator // factor + self._d = denominator + self._n = numerator + self.normalize_self() + # Cancel the fraction to reduced form + def normalize_self(self): + factor = _gcf(self._n, self._d) + self._n = self._n // factor + self._d = self._d // factor if self._d < 0: self._n = -self._n self._d = -self._d + def numerator(self): return self._n