Mark Dickinson <dicki...@gmail.com> added the comment:

@AVicennA: 4.39 *is* the correctly-rounded result for `round(4.395, 2)`. Modulo 
(as-yet unreported) bugs, `round` does correct-rounding (in the IEEE 754 sense) 
in all cases. I was pointing out that your `my_round` does not solve the 
problem you think it does: presumably you'd consider the "correct" result for 
`round(4.395, 2)` to be `4.4`, so you'd like `my_round(4.395, 2)` to return 
`4.4`?

> Do you have any suggestion to solve this problem?

The "problem" presumably being that two-argument `round` gives surprising 
results, to those who haven't thought about the implications of binary 
floating-point?

Unfortunately, there's no easy solution here. Discouraging use of two-argument 
round, and perhaps eventually deprecating it, is one possibility; there are few 
really good use-cases for two-argument round - most of the common use-cases 
involve rounding for reporting purposes, and that's better handled by string 
formatting. Keeping two-argument round and documenting the issue is another, 
and that's the solution the Python core devs have chosen. A more drastic 
solution would be to have Python's numeric literals use decimal floating-point 
by default instead of binary floating-point, so that we finally have a What You 
See Is What You Get behaviour for floating-point. That would be a huge change 
with many implications, and it's definitely way out of scope for this issue.

If you want to discuss this further, please feel free to do so, but not here: 
this isn't the right forum for that discussion.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39059>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to