3 ms·
The expression Math.min(Math.max(num, min), max) is symmetric in min and num, so it doesn’t matter whether you interchange min and num (or, for that matter, max
by Someone 6y ago
The expression Math.min(Math.max(num, min), max) is symmetric in min and num, so it doesn’t matter whether you interchange min and num (or, for that matter, max and num, but that is harder to see from that way to define the ‘clamp’ function)
- f00zz 6y agoGood point, thanks. (Though I've just checked gcc's definition of std::clamp and it looks like __glibcxx_assert(!(__hi < __lo)); return (__val < __lo) ? __lo : (__hi < __val) ? __hi : __val; so order of arguments does matter there.)
- Someone 6y agoSelf reply: Oops. That ‘for that matter’ part isn’t true, as it would mean you could permute the arguments any way you wished.