4 ms·
adding min/max to a language made 10 years ago is kinda crazy when you think about it. Really looking log/slog package, it seems neat and was deeply needed.
by h1fra 3y ago
adding min/max to a language made 10 years ago is kinda crazy when you think about it.
Really looking log/slog package, it seems neat and was deeply needed.
- jakear 3y agoHah, I just went down a whole rabbit hole on super-logarithms and tetration wondering why you found it so critical as to warrant standard-library inclusion.
- thiht 3y agoNote that min/max were already available in the math package, but they’re a bit inconvenient to use (lots of casting to do)
- dchest 3y agoWhile 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.