bpo-37819: Add Fraction.as_integer_ratio() (GH-15212) (GH-15215)
(cherry picked from commit f03b4c8a48f62134799d368b78da35301af466a3)
Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
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 @@
(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.