bpo-37819: Add Fraction.as_integer_ratio() (GH-15212) (GH-15215)

(cherry picked from commit f03b4c8a48)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2019-08-11 15:02:23 -07:00 committed by Raymond Hettinger
parent 9500bbe937
commit 5ba1cb0393
4 changed files with 23 additions and 0 deletions

View file

@ -216,6 +216,14 @@ class Fraction(numbers.Rational):
(cls.__name__, dec, type(dec).__name__))
return cls(*dec.as_integer_ratio())
def as_integer_ratio(self):
"""Return the integer ratio as a tuple.
Return a tuple of two integers, whose ratio is equal to the
Fraction and with a positive denominator.
"""
return (self._numerator, self._denominator)
def limit_denominator(self, max_denominator=1000000):
"""Closest Fraction to self with denominator at most max_denominator.