3 ms·
While it's true that it had math.Min/Max, it's not just the inconvenience of castings that this solves. You can't cast uint64 to float64 and expect the function
by dchest 3y ago
While it's true that it had math.Min/Max, it's not just the inconvenience of castings that this solves. You can't cast uint64 to float64 and expect the function to return the correct result, e.g.:
x1 := uint64(9007199254740993)
x2 := uint64(9007199254740992)
fmt.Println(uint64(math.Max(float64(x1), float64(x2))))
will print 9007199254740992.
min/max and math.Min/Max are not equivalent.
The correct way to write min/max before was to use comparison operators. math.Min/Max was there because it requires tricky special cases for handling -Inf, Inf, NaN, and negative zero.