diff options
| author | Raymond Hettinger <python@rcn.com> | 2008-01-24 02:00:25 (GMT) |
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2008-01-24 02:00:25 (GMT) |
| commit | eb461904eb277c5a92a7d2672f941cb095cf1a93 (patch) | |
| tree | 22cb59dd7e4f90b0aa699b0fbdc5244032bd831d /Lib/rational.py | |
| parent | cf10926088c1e8a4f2d3097e095fa0fd7d5d681a (diff) | |
| download | cpython-eb461904eb277c5a92a7d2672f941cb095cf1a93.zip cpython-eb461904eb277c5a92a7d2672f941cb095cf1a93.tar.gz cpython-eb461904eb277c5a92a7d2672f941cb095cf1a93.tar.bz2 | |
Minor clean-up and more tests.
Diffstat (limited to 'Lib/rational.py')
| -rwxr-xr-x | Lib/rational.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/rational.py b/Lib/rational.py index 5d21a8f..070e593 100755 --- a/Lib/rational.py +++ b/Lib/rational.py @@ -179,7 +179,9 @@ class Rational(RationalAbc): for e in reversed(seq): n, d = d, n n += e * d - return cls(n, d) + if seq: + return cls(n, d) + return cls(0) def as_continued_fraction(self): 'Return continued fraction expressed as a list' @@ -200,7 +202,7 @@ class Rational(RationalAbc): # Still needs rounding rules as specified at # http://en.wikipedia.org/wiki/Continued_fraction cf = cls.from_float(f).as_continued_fraction() - result = new = Rational(0, 1) + result = Rational(0) for i in range(1, len(cf)): new = cls.from_continued_fraction(cf[:i]) if new.denominator > max_denominator: |
