Clamp
Constrains x to the range [lower, upper].
Wikipedia
Clamp (function)WikidataQ5125465Clamp(x, lower, upper)x if it's already in Details
- Constrains a value to
: below lower it returns lower, above upper it returns upper, otherwise x unchanged. - All three arguments are required; a 1-argument
defaulting to the range is not yet supported. - Idempotent: clamping an already-clamped value changes nothing.
- Doesn't validate that lower
upper; with the bounds swapped it just falls through whichever comparison fires first.