|
|
|
|
|
by klodolph
1100 days ago
|
|
Making them builtins allows them to work as you’d expect with cases like, 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.