Clamp
Description
Pure function returning value constrained to the inclusive range [min, max]. If min is greater than max the result is min.
When to use
Use Clamp whenever a number must stay within a defined range, such as a percentage that should never exceed 100 or an index that must stay within array bounds. Both integer and decimal values are accepted. It replaces a combination of Min and Max with a single, self-documenting node. Wire it directly after arithmetic operations whose result may drift outside acceptable limits.
Pins
Input pins
| Pin | Type | Default | Notes |
|---|---|---|---|
| Value | generic(integer, decimal) | 0 | The number to constrain. |
| Min | generic(integer, decimal) | 0 | The inclusive lower bound. |
| Max | generic(integer, decimal) | 100 | The inclusive upper bound. If less than min, the result is min. |
Output pins
| Pin | Type | Notes |
|---|---|---|
| Result | generic(integer, decimal) | The value constrained to [min, max]. |
Example
Ensure a user-supplied brightness level stays between 0 and 255. Wire the raw user
input (integer or decimal) into the Value input of Clamp with Min set to 0 and Max
set to 255. The Result output is guaranteed to be within the valid range regardless
of what the user supplies, making downstream processing safe.