1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-10-18 06:14:21 +00:00

Replace and deprecate float.Round method

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-10-23 19:31:13 +02:00
parent bae000770c
commit 80ba8d5dd9
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5

View file

@ -3,12 +3,8 @@ package float
import "math" import "math"
// Round returns a float rounded according to "Round to nearest, ties away from zero" IEEE floaing point rounding rule // 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 { func Round(x float64) float64 {
var absx, y float64 return math.Round(x)
absx = math.Abs(x)
y = math.Floor(absx)
if absx-y >= 0.5 {
y += 1.0
}
return math.Copysign(y, x)
} }