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:
parent
3777ca42ae
commit
11b74a803f
18
pep-3141.txt
18
pep-3141.txt
|
@ -205,8 +205,12 @@ totally ordered except for NaNs (which this PEP basically ignores). ::
|
||||||
def __round__(self, ndigits:Integral=None):
|
def __round__(self, ndigits:Integral=None):
|
||||||
"""Rounds self to ndigits decimal places, defaulting to 0.
|
"""Rounds self to ndigits decimal places, defaulting to 0.
|
||||||
|
|
||||||
If ndigits is omitted or None, returns an Integral, otherwise
|
If ndigits is omitted or None, returns an Integral,
|
||||||
returns a Real. Rounds half toward even.
|
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
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -428,9 +432,13 @@ functions. All of these return Integrals rather than Reals.
|
||||||
least Integral ``>= x``.
|
least Integral ``>= x``.
|
||||||
|
|
||||||
4. ``__round__(self)``, called from ``round(x)``, which returns the
|
4. ``__round__(self)``, called from ``round(x)``, which returns the
|
||||||
Integral closest to ``x``, rounding half toward even. There is also
|
Integral closest to ``x``, rounding half as the type chooses.
|
||||||
a 2-argument version, ``__round__(self, other)``, called from
|
``float`` will change in 3.0 to round half toward even. There is
|
||||||
``round(x, y)``, which should return a Real.
|
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
|
Because the ``int()`` conversion implemented by ``float`` (and by
|
||||||
``decimal.Decimal``) is equivalent to but less explicit than
|
``decimal.Decimal``) is equivalent to but less explicit than
|
||||||
|
|
Loading…
Reference in New Issue