clamp

num clamp(num x, num a, num b)

num - any numeric type (int or fixed)

Description

Limits x to the range [a; b]. If x falls in the range, returns x.

If x is less than a, returns a.

If x is greater than b, returns b.

Examples

clamp(7, 6, 8) -> 7
clamp(5, 6, 8) -> 6
clamp(8, 6, 8) -> 8
clamp(0.25, 0.2, 0.3) -> 0.25
clamp(0.15, 0.2, 0.3) -> 0.2
clamp(0.35, 0.2, 0.3) -> 0.3