clamp
Clamps a real number to a specified interval.
Syntax
-
clamp(x, a, b)
-
x
is a real number -
a
is a real number -
b
is a real number
-
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
.