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 steven.daprano
Recipients marco_ocram, mark.dickinson, rhettinger, ronaldoussoren, steven.daprano, stutzbach, tim.peters, veky
Date 2020-08-25.02:46:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1598323571.03.0.866319182895.issue41598@roundup.psfhosted.org>
In-reply-to
Content
Okay Marco, I'm changing the title to reflect the new API (support for rounding modes rather than new round functions) and pushed the version to 3.10, since 3.9 is in feature freeze (no new features).

This will probably need to be discussed on Python-Ideas, and maybe a PEP written, but provided it is not too controversial it may not be a big complicated PEP and I'm happy to help.

There is certainly a history of people requesting something like this:

https://kingant.net/2019/01/rounding-numbers-in-python-2-and-python-3/

https://mail.python.org/archives/list/python-dev@python.org/thread/34QNDXZBMP6RR4P6NZFFIJK6YODEWSVK/


It will help very much if Mark, Raymond and Tim either support this idea or at least don't object. (Adding Tim to the nosy list.)

See also relevant discussion here:

https://bugs.python.org/issue32956


In my innocence, I don't think that this will be a very difficult feature to implement. Out of the five IEEE-754 rounding modes:

- Round to nearest, ties away to even already exists, so no extra work needs to be done.

- Round to nearest, ties away from zero was already implemented in Python 2, so we can just(?) resurrect that.

- Round toward 0 (truncation or chop) is equivalent to rounding down for positive numbers and rounding up for negatives, so if we can implement those, we get round towards 0.

- And I think that rounding up and rounding down are symmetrical, so if you can do one, you can do the other.

As Vedran correctly points out, the tricky part is adjusting for the difference between decimal digits and bits.

Dotnet provides rounding modes for Math.Round:

https://docs.microsoft.com/en-us/dotnet/api/system.midpointrounding?view=netcore-3.1


So does Julia:

http://www.jlhub.com/julia/manual/en/function/round

http://www.jlhub.com/julia/manual/en/function/get_rounding


so I think that there is precedence for this in other languages.
History
Date User Action Args
2020-08-25 02:46:11steven.dapranosetrecipients: + steven.daprano, tim.peters, rhettinger, ronaldoussoren, mark.dickinson, stutzbach, veky, marco_ocram
2020-08-25 02:46:11steven.dapranosetmessageid: <1598323571.03.0.866319182895.issue41598@roundup.psfhosted.org>
2020-08-25 02:46:11steven.dapranolinkissue41598 messages
2020-08-25 02:46:10steven.dapranocreate