summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/fractions.rst (renamed from Doc/library/rational.rst)40
-rw-r--r--Doc/library/numbers.rst10
2 files changed, 25 insertions, 25 deletions
diff --git a/Doc/library/rational.rst b/Doc/library/fractions.rst
index 8ed702f..af6ed76 100644
--- a/Doc/library/rational.rst
+++ b/Doc/library/fractions.rst
@@ -1,29 +1,29 @@
-:mod:`rational` --- Rational numbers
+:mod:`fractions` --- Rational numbers
====================================
-.. module:: rational
+.. module:: fractions
:synopsis: Rational numbers.
.. moduleauthor:: Jeffrey Yasskin <jyasskin at gmail.com>
.. sectionauthor:: Jeffrey Yasskin <jyasskin at gmail.com>
.. versionadded:: 2.6
-The :mod:`rational` module defines an immutable, infinite-precision
-Rational number class.
+The :mod:`fractions` module defines an immutable, infinite-precision
+Fraction number class.
-.. class:: Rational(numerator=0, denominator=1)
- Rational(other_rational)
- Rational(string)
+.. class:: Fraction(numerator=0, denominator=1)
+ Fraction(other_fraction)
+ Fraction(string)
The first version requires that *numerator* and *denominator* are
instances of :class:`numbers.Integral` and returns a new
- ``Rational`` representing ``numerator/denominator``. If
+ ``Fraction`` representing ``numerator/denominator``. If
*denominator* is :const:`0`, raises a :exc:`ZeroDivisionError`. The
- second version requires that *other_rational* is an instance of
+ second version requires that *other_fraction* is an instance of
:class:`numbers.Rational` and returns an instance of
- :class:`Rational` with the same value. The third version expects a
+ :class:`Fraction` with the same value. The third version expects a
string of the form ``[-+]?[0-9]+(/[0-9]+)?``, optionally surrounded
by spaces.
@@ -31,39 +31,39 @@ Rational number class.
:class:`numbers.Rational` and is immutable and hashable.
-.. method:: Rational.from_float(flt)
+.. method:: Fraction.from_float(flt)
- This classmethod constructs a :class:`Rational` representing the
+ This classmethod constructs a :class:`Fraction` representing the
exact value of *flt*, which must be a :class:`float`. Beware that
- ``Rational.from_float(0.3)`` is not the same value as ``Rational(3,
+ ``Fraction.from_float(0.3)`` is not the same value as ``Fraction(3,
10)``
-.. method:: Rational.from_decimal(dec)
+.. method:: Fraction.from_decimal(dec)
- This classmethod constructs a :class:`Rational` representing the
+ This classmethod constructs a :class:`Fraction` representing the
exact value of *dec*, which must be a
:class:`decimal.Decimal`.
-.. method:: Rational.__floor__()
+.. method:: Fraction.__floor__()
Returns the greatest :class:`int` ``<= self``. Will be accessible
through :func:`math.floor` in Py3k.
-.. method:: Rational.__ceil__()
+.. method:: Fraction.__ceil__()
Returns the least :class:`int` ``>= self``. Will be accessible
through :func:`math.ceil` in Py3k.
-.. method:: Rational.__round__()
- Rational.__round__(ndigits)
+.. method:: Fraction.__round__()
+ Fraction.__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 ``Rational(1, 10**ndigits)`` (logically, if
+ nearest multiple of ``Fraction(1, 10**ndigits)`` (logically, if
``ndigits`` is negative), again rounding half toward even. Will be
accessible through :func:`round` in Py3k.
diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst
index 6ee8f27..7a5f105 100644
--- a/Doc/library/numbers.rst
+++ b/Doc/library/numbers.rst
@@ -106,7 +106,7 @@ Notes for type implementors
Implementors should be careful to make equal numbers equal and hash
them to the same values. This may be subtle if there are two different
-extensions of the real numbers. For example, :class:`rational.Rational`
+extensions of the real numbers. For example, :class:`fractions.Fraction`
implements :func:`hash` as follows::
def __hash__(self):
@@ -201,11 +201,11 @@ in :class:`complex`, and both :meth:`__radd__` s land there, so ``a+b
Because most of the operations on any given type will be very similar,
it can be useful to define a helper function which generates the
forward and reverse instances of any given operator. For example,
-:class:`rational.Rational` uses::
+:class:`fractions.Fraction` uses::
def _operator_fallbacks(monomorphic_operator, fallback_operator):
def forward(a, b):
- if isinstance(b, (int, long, Rational)):
+ if isinstance(b, (int, long, Fraction)):
return monomorphic_operator(a, b)
elif isinstance(b, float):
return fallback_operator(float(a), b)
@@ -217,7 +217,7 @@ forward and reverse instances of any given operator. For example,
forward.__doc__ = monomorphic_operator.__doc__
def reverse(b, a):
- if isinstance(a, RationalAbc):
+ if isinstance(a, Rational):
# Includes ints.
return monomorphic_operator(a, b)
elif isinstance(a, numbers.Real):
@@ -233,7 +233,7 @@ forward and reverse instances of any given operator. For example,
def _add(a, b):
"""a + b"""
- return Rational(a.numerator * b.denominator +
+ return Fraction(a.numerator * b.denominator +
b.numerator * a.denominator,
a.denominator * b.denominator)