mirror of
https://github.com/Luzifer/go_helpers.git
synced 2024-12-24 13:01:21 +00:00
Replace and deprecate float.Round method
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
bae000770c
commit
80ba8d5dd9
1 changed files with 3 additions and 7 deletions
|
@ -3,12 +3,8 @@ package float
|
|||
import "math"
|
||||
|
||||
// Round returns a float rounded according to "Round to nearest, ties away from zero" IEEE floaing point rounding rule
|
||||
//
|
||||
// Deprecated: Starting with Go1.10 this should be replaced with math.Round()
|
||||
func Round(x float64) float64 {
|
||||
var absx, y float64
|
||||
absx = math.Abs(x)
|
||||
y = math.Floor(absx)
|
||||
if absx-y >= 0.5 {
|
||||
y += 1.0
|
||||
}
|
||||
return math.Copysign(y, x)
|
||||
return math.Round(x)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue