mirror of
https://github.com/python/cpython.git
synced 2025-08-13 13:29:13 +00:00
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:
parent
9500bbe937
commit
5ba1cb0393
4 changed files with 23 additions and 0 deletions
|
@ -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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue