Syntax
- float clamp(x, min, max)
Parameters
- x—floatThe number to clamp.
- min—floatLower bound of range to which x is clamped. Minimum value returned.
- max—floatUpper bound of range to which x is clamped. Maximum value returned.
Returns
Returns min if x is less than min, max if x is greater than max, and x otherwise.
Description
The clamp function clamps x to the range [min, max].
Related
Examples
example.1
clamp(1.5, 0, 1)
# result = 1
example.2
clamp(-11, -10, 10)
# result = -10