Clamp
Constrains a value to a [min, max] range. Returns min if the input
is below, max if above, the input otherwise.
Category: Math Returns: matches the input type; see overloads.
Signature
Clamp(value, min, max)
The runtime picks the overload that matches the argument types. Mixing
types (e.g. clamping an int with decimal bounds) routes through the
number overload.
Overloads
| Args | Returns | Notes |
|---|---|---|
(int, int, int) | int | All-integer; result is integer. |
(decimal, decimal, decimal) | decimal | All-decimal; result is decimal. |
(number, number, number) | number | Fallback when types can’t be statically resolved (e.g. variable inputs). |
Examples
Clamp(hp, 0, maxHp) // pin hp to a valid range
Clamp(score + bonus, 0, 100) // ceiling at 100 after addition
Clamp(temperature, -40, 50) // bounded weather variable