Development · Evolving reference
Clamp
Restricts a value to one ordered inclusive numeric interval.
Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →
Module std.math
import std.math;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
fn
pub const fn Clamp<T>(Value: T, Minimum: T, Maximum: T) -> T where T: Numeric, CopyableRestricts a value to one ordered inclusive numeric interval. T: Copyable supported numeric representation. Value: Value to constrain; a NaN input propagates. Minimum: Inclusive lower bound. Maximum: Inclusive upper bound. Return: Value when in range, otherwise the selected bound; no allocation. Warning: Reversed or NaN bounds fatal-trap rather than silently swapping endpoints.
Documentation snapshot: October 24, 2026 About versions ↗