[issue4707] round() shows undocumented behaviour

Jeffrey Yasskin report at bugs.python.org
Sat Dec 20 20:44:01 CET 2008


Jeffrey Yasskin <jyasskin at gmail.com> added the comment:

When PEP 3141 says something should be Real, that includes both int and
float as possibilities (since Real is a supertype of Integral), so it's
consistent with the PEP for round(int, int) to return an int, and I
agree with Mark that round(25, -1) ought to return an int. Making that
change would be slightly backwards-incompatible, but IIRC, int is
supposed to be usable everywhere float is, so there should be very few
programs it would break. So my vote's to change it, for 3.0.1 if possible.

The documentation is a little too strict on __round__ implementations by
requiring round(x, y) to return the same type as x, but I think it
should still encourage __round__ to return the same type.

And, uh, oops for writing those bugs. Is your guess for round(25.0,
-1)==30.0 that 25.0*(1/10.0) is slightly more than 2.5 on some systems?

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4707>
_______________________________________


More information about the Python-bugs-list mailing list