[issue13060] make round() floating-point errors less hurtful

Mark Dickinson report at bugs.python.org
Thu Sep 29 17:35:56 CEST 2011


Mark Dickinson <dickinsm at gmail.com> added the comment:

> This is mathematically wrong ...

No, it's not 'mathematically wrong'.  There are many different rounding conventions in use, and no single universally agreed convention for rounding halfway cases.  Python chooses to use unbiased rounding[1] here, which matches the rounding used for all other basic arithmetic operations.

Other comments:

(1) I agree that round-half-up might be a useful convention to have available.  But...

(2) Depending on any sort of predictable rounding behaviour for *decimal* halfway cases when using *binary* floats is fraught with peril.  If you really care about these halfway cases going in a particular direction (whether it's away from zero, towards +infinity, towards even, towards odd, etc.) then you should really be using Decimal.







[1] http://en.wikipedia.org/wiki/Rounding#Round_half_to_even

----------

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


More information about the Python-bugs-list mailing list