summaryrefslogtreecommitdiffstats
path: root/Lib/fractions.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-08-11 21:40:59 (GMT)
committerGitHub <noreply@github.com>2019-08-11 21:40:59 (GMT)
commitf03b4c8a48f62134799d368b78da35301af466a3 (patch)
tree43a5a1282521e4164e63e05674dc7830319700ec /Lib/fractions.py
parent09a1872a8007048dcdf825a476816c5e3498b8f8 (diff)
downloadcpython-f03b4c8a48f62134799d368b78da35301af466a3.zip
cpython-f03b4c8a48f62134799d368b78da35301af466a3.tar.gz
cpython-f03b4c8a48f62134799d368b78da35301af466a3.tar.bz2
bpo-37819: Add Fraction.as_integer_ratio() (GH-15212)
Diffstat (limited to 'Lib/fractions.py')
-rw-r--r--Lib/fractions.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py
index 7443bd3..e774d58 100644
--- a/Lib/fractions.py
+++ b/Lib/fractions.py
@@ -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.