func clamp(x float64) float64 {
return max(0, min(1, x))
}
With ordinary functions, the arguments are assigned types too soon, and you get integer types for 0 and 1 in the above code. In C++ you might make the types explicit: template<typename T>
T clamp(T x) {
return std::max<T>(0, std::min<T>(1, x));
}
That’s not meant to be exactly the way you’d write these functions, but just a little bit of sample code to show how the typing is different.Obviously these sample functions don't take into account all the intricacies of float min/max functions.
const x = min(a, b)
assuming a and b are const.It helps to document intent.
Probably not so useful for min, but it can be more useful for more complex functions.
The proposal's real conclusion was "the decision cannot be resolved by empirical data or technical arguments."
Personally I try to avoid using floats for calculations if I can (unless it's obviously warranted), I've encountered far too many foot guns from using them, though honestly the same can be said about integers in some situations too. I wish there was a package like math/big that was more accessible, I find the current interface for it pretty abysmal.