-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
math: consider adding IEEE TiesToEven rounding to math package #21748
Comments
CC @griesemer |
|
I ended up with |
Change https://golang.org/cl/61211 mentions this issue: |
I already had a tested implementation, so I've included it for review. The larger question is still whether or not the project wants to support the last IEEE mode. |
C99 defines a function The name Since we tend to follow C, this is all by way of saying that I think |
Now that we have |
I'd lean towards |
@griesemer, is there a decision on adding |
I'm in favor, for completeness sake, but there was no formal decision (by the proposal committee) yet. |
OK but let's just do RoundToEven. |
IEEE 754-2008 specifies 5 rounding-direction attributes with 4 implemented by the math package:
roundTiesToEven
:RoundTiesToEven
(proposed) (wasRint
)roundTiesToAway
:Round
roundTowardPositive
:Ceil
roundTowardNegative
:Floor
roundTowardZero
:Trunc
No other rounding-attributes are specified by IEEE 754. There have been various proposals in the past requesting highly configurable esoteric rounding modes beyond IEEE. I don't believe they should be considered for the math package.
I'd suggest using the following signature:
func RoundTiesToEven(float64) float64
Most people generally prefer TiesToAway for common usage (hence #20100). However TiesToEven has statistical properties that are preferable for some applications. Implementations of IEEE 754 are required to provide TiesToEven.
For comparison, other languages provide support for TiesToEven:
rint
Math.rint
round
Pro:
Con:
The text was updated successfully, but these errors were encountered: