Re:Math.min(Math.max(num, min), max)
by parliament32 on Thursday August 20, 2020 @12:22PM
(#24224866)
Python also doesn't have a built-in clamp function (I think there might be one in numpy), I usually use
Throw it in a function with some asserts if you're worried about x not being a number and giving you weird results.
[ Parent
| on HN ]
There is indeed one in numpy : https://numpy.org/doc/stable/reference/generated/numpy.clip....