mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Minor clean-up and more tests.
This commit is contained in:
parent
cf10926088
commit
eb461904eb
2 changed files with 15 additions and 2 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue