clamp

fnT1 clamp(T1, T2, T3)(T1 val, T2 lower, T3 upper)

Clamps val into the given bounds. Result has the same type as val.

Parameters

valThe value to _clamp.
lowerThe _lower bound of the _clamp.
upperThe _upper bound of the _clamp.

Returns

lower if val is less than lower, upper if val is greater than

upper, and val in all other cases. Comparisons are made correctly (using lessThan and the return value is converted to the return type using the standard integer coversion rules

greaterThan) even if the signedness of T1, T2,

and T3 are different.