Skip to content

Clamp

Constrains x to the range [lower, upper].

Clamp(x, lower, upper)x if it's already in , else the nearer bound.

Domain: Arithmetic

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.

Examples

See also: Min, Max