Re:Math.min(Math.max(num, min), max)
by vortico on Thursday August 20, 2020 @03:00PM
(#24227236)
Why do you prefer to leave undefined behavior?
[ Parent
| on HN ]
Re:Math.min(Math.max(num, min), max)
by resu_nimda on Thursday August 20, 2020 @03:53PM
(#24228001)
I'm not sure what you mean. The behavior of the max() and min() functions is perfectly well defined. The terms "maximum" and "minimum" are well defined. If I were using those terms I would likely consider the case where max < min to be an error, or have some other meaning, like an empty range.
If I wanted it to automatically flip the values to ensure a sensible range is defined, I would probably use "a" and "b" or "endpoint1" and "endpoint2" or something, because "max" has now become "max or min," which is not the same.