[issue41598] rnd() + rndup() in math

Steven D'Aprano report at bugs.python.org
Sat Aug 22 01:17:02 EDT 2020


Steven D'Aprano <steve+python at pearwood.info> added the comment:

Marco, it is better to give a description of the functionality required rather than a simplistic and incorrect implementation :-)

(Not that I am likely to provide a better implementation without a lot of study.)

Regardless of whether you or I agree with the decision to move to Banker's Rounding, that was done about a decade ago, and it matches decisions made by other languages such as Julia. Changing the default will break people's code and we do not do that lightly, or at all, without a very good reason.

As Tim Peters describes here:

https://mail.python.org/pipermail/python-dev/2008-January/075873.html

many older languages implemented rounding by "add half and chop", more because it was cheap than for its mathematical properties.

Are you satisfied that adding a rounding mode to the built-in `round` function is a better solution than a series of functions in the math module? If so, I will change the title to reflect that.

Vedran: I don't think the availability of different rounding modes will have any effect at all on whether or not people believe floats are real decimal numbers rather than binary floats. People already believe that. I think we are better off acknowledging that there are reasonable use-cases for different rounding modes even when using floats.

According to this:

https://www.gnu.org/software/libc/manual/html_node/Rounding.html

IEEE-754 only requires four rounding modes, defaulting to the same Banker's Rounding that Python uses. Wikipedia says there are five:

https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules


Regardless of whether there are four or five, I see no technical reason why we couldn't offer the full set of eight used by the decimal module.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41598>
_______________________________________


More information about the Python-bugs-list mailing list