Skip to content

Specify rounding mode as half to even #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 23, 2020
Merged

Specify rounding mode as half to even #93

merged 3 commits into from
Nov 23, 2020

Conversation

kgryte
Copy link
Contributor

@kgryte kgryte commented Nov 23, 2020

This PR

  • specifies the rounding mode as half to even, rather than half away from zero. This follows NumPy and Python 3.x, rather than C and Python 2.7 round half away from zero behavior.

@rgommers
Copy link
Member

Thanks for the fix @kgryte.

includes a TODO to consider whether round should support alternative rounding modes

My preference would be not to bother, since this is mostly a niche detail and current libraries don't implement multiple options.

I did a quick scan of NumPy issues, and while this question (e.g., why does round(0.5) give 0?) is asked multiple times, no one argues an alternative matters to them.

For reference, here is the rationale for the rule: numpy/numpy#3382 (comment), Round-0.5-to-the-nearest-even, the rule numpy uses, is usually considered the best option for serious numerical code because it rounds up just as often as it rounds down, thus avoiding a source of statistical bias.

@kgryte
Copy link
Contributor Author

kgryte commented Nov 23, 2020

Removed TODO.

@rgommers rgommers merged commit 1f71c4d into main Nov 23, 2020
@rgommers rgommers deleted the patch-round branch November 23, 2020 22:12
@rgommers
Copy link
Member

Thanks, merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants