Update PEP 3141 according to the conclusion of

http://mail.python.org/pipermail/python-dev/2008-January/075921.html. Different
types may have different rounding behavior, but float will definitely
round-to-even.
This commit is contained in:
Jeffrey Yasskin 2008-01-07 00:25:37 +00:00
parent 3777ca42ae
commit 11b74a803f
1 changed files with 13 additions and 5 deletions

View File

@ -205,8 +205,12 @@ totally ordered except for NaNs (which this PEP basically ignores). ::
def __round__(self, ndigits:Integral=None):
"""Rounds self to ndigits decimal places, defaulting to 0.
If ndigits is omitted or None, returns an Integral, otherwise
returns a Real. Rounds half toward even.
If ndigits is omitted or None, returns an Integral,
otherwise returns a Real, preferably of the same type as
self. Types may choose which direction to round half. For
example, float rounds half toward even, and Decimal rounds
it according to the current context.
"""
raise NotImplementedError
@ -428,9 +432,13 @@ functions. All of these return Integrals rather than Reals.
least Integral ``>= x``.
4. ``__round__(self)``, called from ``round(x)``, which returns the
Integral closest to ``x``, rounding half toward even. There is also
a 2-argument version, ``__round__(self, other)``, called from
``round(x, y)``, which should return a Real.
Integral closest to ``x``, rounding half as the type chooses.
``float`` will change in 3.0 to round half toward even. There is
also a 2-argument version, ``__round__(self, ndigits)``, called
from ``round(x, ndigits)``, which should return a Real.
In 2.6, ``math.floor``, ``math.ceil``, and ``round`` will continue to
return floats.
Because the ``int()`` conversion implemented by ``float`` (and by
``decimal.Decimal``) is equivalent to but less explicit than