Algosim documentation: clamp

clamp

Clamps a real number to a specified interval.

Syntax

Description

If a ≤ b then clamp(x, a, b) returns x clamped to the interval [a, b].

That is, clamp(x, a, b) = x if x ∈ [a, b], clamp(x, a, b) = a if x < a, and clamp(x, a, b) = b if x > b.

If a > b then clamp(x, a, b) returns a.

Hence,

clamp(x, a, b) = max(a, min(x, b))

for all real numbers x, a, and b.

See also