clamp — return a value clamped to a given range with strict typechecking
current value
minimum allowable value
maximum allowable value
This macro does strict typechecking of min/max to make sure they are of the same type as val. See the unnecessary pointer comparisons.