This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients AVicennA, docs@python, koobs, mark.dickinson, ned.deily, paul.moore, ronaldoussoren, steven.daprano, terry.reedy, tim.golden, zach.ware
Date 2019-12-16.19:37:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576525080.22.0.300062580752.issue39059@roundup.psfhosted.org>
In-reply-to
Content
@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.
History
Date User Action Args
2019-12-16 19:38:00mark.dickinsonsetrecipients: + mark.dickinson, terry.reedy, paul.moore, ronaldoussoren, tim.golden, ned.deily, steven.daprano, docs@python, zach.ware, koobs, AVicennA
2019-12-16 19:38:00mark.dickinsonsetmessageid: <1576525080.22.0.300062580752.issue39059@roundup.psfhosted.org>
2019-12-16 19:38:00mark.dickinsonlinkissue39059 messages
2019-12-16 19:37:59mark.dickinsoncreate