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
Enhancement: math.RoundOut #33417
Comments
There are Round and RoundToEven which do exactly what you say unless I am missing something. Please update your proposal clarifying what is missing in those functions that you require otherwise. Thanks. |
Would the following exhibit the behavior you want? func RoundOut(x float64) float64 {
return math.Copysign(math.Ceil(math.Abs(x)), x)
} Note that your proposed behavior is "round away from zero", which is non-standard. I'm not exactly sure why one would want to round -1.3 down to -2.0 as well as 1.3 to 2.0. Can you please explain your use case? |
Sorry I missed that this is about rounding also 1.3 to 2 apart from 1.7 to 2. In any case, the question still stands to explain the use case for this and why does this need to be in the standard library. |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
Ceil and Floor don't quite do what most people expect them to, for negative numbers for example. It would be helpful to provide a convenience method
RoundOut
, which rounds all positive numbers up, and all negative numbers down.This can be implemented in JavaScript as
math.Sign(x) * math.Ceil(math.Abs(x))
, but Go doesn't quite have the same Sign() behavior.The text was updated successfully, but these errors were encountered: