diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2008-02-12 21:31:59 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2008-02-12 21:31:59 (GMT) |
commit | e1b824793a4b10d5119459b47546b122a17c18b4 (patch) | |
tree | de1aaf1ef801c1fe278f5de4920a8a8c4ccbab78 /Doc | |
parent | a37430a0cec991f341ca637410371532c8e3720c (diff) | |
download | cpython-e1b824793a4b10d5119459b47546b122a17c18b4.zip cpython-e1b824793a4b10d5119459b47546b122a17c18b4.tar.gz cpython-e1b824793a4b10d5119459b47546b122a17c18b4.tar.bz2 |
Implementation of Fraction.limit_denominator.
Remove Fraction.to_continued_fraction and
Fraction.from_continued_fraction
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/fractions.rst | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Doc/library/fractions.rst b/Doc/library/fractions.rst index 7f6019f..adc70c6 100644 --- a/Doc/library/fractions.rst +++ b/Doc/library/fractions.rst @@ -46,6 +46,24 @@ Fraction 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 |