Open
Description
Clamping numbers between an upper and lower bound is a relatively-common task, specially in graphics domain.
- https://en.wikipedia.org/wiki/Clamping_(graphics)
- DotNet's math
- Android's MathUtils
- CSS math function
Currently, Java and Scala standard library does not offer such functionality, so users need to write something like max(LOWER_BOUND, min(VALUE, UPPER_BOUND))
which is error-prone.
I propose adding clamp
function to math
.
Adding clamp
to numeric types (e.g. Int
or Double
) may be good to have, in analogus to max
/min
.