[Python-Dev] Return type of round, floor, and ceil in 2.6 (original) (raw)

Jeffrey Yasskin jyasskin at gmail.com
Sat Jan 5 19:56:49 CET 2008


On Jan 5, 2008 8:56 AM, Guido van Rossum <guido at python.org> wrote:

I think the consensus is against round-to-even in 3.0 -- this requires a PEP update as well as code changes. (Sorry for having caused so much extra work, I should have flagged this earlier.)

I'm not convinced that speed is a real issue in this case, since this is only the explicit round() operation and not rounding for arithmetic operations. But consistency with other languages is important.

Does the following patch to the PEP represent the consensus? If so, I'll check it in, and update the py3k branch and wikipedia article to match. I've allowed each type to define its own half-rounding behavior so that Decimal can follow the current context, and float can, once there's a portable way to set it (like C99's fesetround), follow the current rounding mode (if people want that at the time).

Index: pep-3141.txt

--- pep-3141.txt (revision 59739) +++ pep-3141.txt (working copy) @@ -206,7 +206,10 @@ """Rounds self to ndigits decimal places, defaulting to 0.

         If ndigits is omitted or None, returns an Integral, otherwise

@@ -428,14 +431,15 @@ least Integral >= x.

  1. __round__(self), called from round(x), which returns the

Because the int() conversion implemented by float (and by decimal.Decimal) is equivalent to but less explicit than trunc(), let's remove it. (Or, if that breaks too much, just add a -deprecation warning.) +deprecation warning.) In 2.6, math.floor, math.ceil, and +round will continue to return floats.

complex.__{divmod,mod,floordiv,int,float}__ also go away. It would be nice to provide a nice error message to help confused porters, but

-- Namasté, Jeffrey Yasskin



More information about the Python-Dev mailing list