mirror of
https://github.com/Luzifer/go_helpers.git
synced 2024-12-25 13:31: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"
|
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)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue