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.rst35
1 files changed, 30 insertions, 5 deletions
diff --git a/Doc/library/fractions.rst b/Doc/library/fractions.rst
index 81b419e..59e6b1b 100644
--- a/Doc/library/fractions.rst
+++ b/Doc/library/fractions.rst
@@ -5,7 +5,6 @@
:synopsis: Rational numbers.
.. moduleauthor:: Jeffrey Yasskin <jyasskin at gmail.com>
.. sectionauthor:: Jeffrey Yasskin <jyasskin at gmail.com>
-.. versionadded:: 2.6
**Source code:** :source:`Lib/fractions.py`
@@ -80,7 +79,7 @@ another rational number, or from a string.
and should be treated as immutable. In addition,
:class:`Fraction` has the following methods:
- .. versionchanged:: 2.7
+ .. versionchanged:: 3.2
The :class:`Fraction` constructor now accepts :class:`float` and
:class:`decimal.Decimal` instances.
@@ -91,16 +90,16 @@ another rational number, or from a string.
value of *flt*, which must be a :class:`float`. Beware that
``Fraction.from_float(0.3)`` is not the same value as ``Fraction(3, 10)``
- .. note:: From Python 2.7 onwards, you can also construct a
+ .. note:: From Python 3.2 onwards, you can also construct a
:class:`Fraction` instance directly from a :class:`float`.
.. method:: from_decimal(dec)
This class method constructs a :class:`Fraction` representing the exact
- value of *dec*, which must be a :class:`decimal.Decimal`.
+ value of *dec*, which must be a :class:`decimal.Decimal` instance.
- .. note:: From Python 2.7 onwards, you can also construct a
+ .. note:: From Python 3.2 onwards, you can also construct a
:class:`Fraction` instance directly from a :class:`decimal.Decimal`
instance.
@@ -126,6 +125,32 @@ another rational number, or from a string.
Fraction(11, 10)
+ .. method:: __floor__()
+
+ Returns the greatest :class:`int` ``<= self``. This method can
+ also be accessed through the :func:`math.floor` function:
+
+ >>> from math import floor
+ >>> floor(Fraction(355, 113))
+ 3
+
+
+ .. method:: __ceil__()
+
+ Returns the least :class:`int` ``>= self``. This method can
+ also be accessed through the :func:`math.ceil` function.
+
+
+ .. method:: __round__()
+ __round__(ndigits)
+
+ The first version returns the nearest :class:`int` to ``self``,
+ rounding half to even. The second version rounds ``self`` to the
+ nearest multiple of ``Fraction(1, 10**ndigits)`` (logically, if
+ ``ndigits`` is negative), again rounding half toward even. This
+ method can also be accessed through the :func:`round` function.
+
+
.. function:: gcd(a, b)
Return the greatest common divisor of the integers *a* and *b*. If either