The value to clamp.
The _lower bound of the clamp.
The _upper bound of the clamp.
Returns val, if it is between lower and upper. Otherwise returns the nearest of the two.
assert(clamp(2, 1, 3) == 2); assert(clamp(0, 1, 3) == 1); assert(clamp(4, 1, 3) == 3); assert(clamp(1, 1, 1) == 1); assert(clamp(5, -1, 2u) == 2);
Clamps a value into the given bounds.
This functions is equivalent to max(lower, min(upper,val)).