summaryrefslogtreecommitdiffstats
path: root/Doc/library/fractions.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/fractions.rst')
-rw-r--r--Doc/library/fractions.rst18
1 files changed, 18 insertions, 0 deletions
diff --git a/Doc/library/fractions.rst b/Doc/library/fractions.rst
index 1deea64..9ef1230 100644
--- a/Doc/library/fractions.rst
+++ b/Doc/library/fractions.rst
@@ -46,6 +46,24 @@ Rational number class.
:class:`decimal.Decimal`.
+.. method:: Fraction.limit_denominator(max_denominator=1000000)
+
+ Finds and returns the closest :class:`Fraction` to ``self`` that
+ has denominator at most max_denominator. This method is useful for
+ finding rational approximations to a given floating-point number::
+
+ >>> Fraction('3.1415926535897932').limit_denominator(1000)
+ Fraction(355, 113)
+
+ or for recovering a rational number that's represented as a float::
+
+ >>> from math import pi, cos
+ >>> Fraction.from_float(cos(pi/3))
+ Fraction(4503599627370497L, 9007199254740992L)
+ >>> Fraction.from_float(cos(pi/3)).limit_denominator()
+ Fraction(1, 2)
+
+
.. method:: Fraction.__floor__()
Returns the greatest :class:`int` ``<= self``. Will be accessible