-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Change default rounding mode to TIES_EVEN
#10414
Comments
This might be controversial, but should we change this before 1.0? It's probably better to change now than any point later. |
I'm on board with changing it for 1.0. Other languages allow setting the default rounding mode. Should we consider the same? It can appear later of needed. |
@bcardiff do you mean globally? |
Yes |
Is there any other language that allows that? Well, maybe if it's a compile flag... But then, what if a lib expects a default round mode but you change it? Or what would be the use case? If the default is configurable then you would always want to specify a value to make sure you get the behavior you want, making the default useless. |
@asterite Yes, Ruby - for |
Julia, libc and java links shared previously shows how to set the current global rounding mode. That's why I mentioned it. For apps it might not be useful. For numerical processing it might. Again, is not mandatory on my end. |
A number of languages have global configuration. Julia and libc as noted in the OP. Java on the other hand has a I'm not very familiar with the specifics though. We shouldn't rush an implemementation. Having a global setting would surely be nice to offer a fallback mechanic. But is should be fine with just changing the default. If it breaks someone's code and they need to change the default rounding mode back globally, it's always possible to re-implement |
For people in the future who will undoubtedly be confused by the new default: Does this mean we should expect 0.5 to round to 0, 1.5 to round to 2, 2.5 to also round to 2, and 3.5 to round to 4, etc? As opposed to the rules many of were taught as children to "round up when equidistant" (which I believe is the "rounds away [from zero]" method). |
Yes, exactly. The new No doubt this may be confusing when you expect
To show this in an example. numbers = [0.5, 1.5, 2.5, 3.5, 4.5]
numbers.sum # => 12.5
numbers.sum(&.round(:ties_even)) # => 12.0
numbers.sum(&.round(:ties_away)) # => 15.0 The actual sum of these five numbers is Thus |
#10413 introduces a new rounding mode which rounds ties to the next even number (also known as "Banker's roundin").
This rounding mode should be used as default for
Number#round
. The current default,TIES_AWAY
has a bias towards larger magnitude.TIES_EVEN
is recommended as dedault mode by IEEE-754 and many other languages use it as default including Julia, libc, Java.The text was updated successfully, but these errors were encountered: