std-method

Floating-point clamp

Limit a normalized control value to a valid interval. The bounds must be ordered and cannot be NaN; a NaN input remains NaN. Expected stdout (not executed): 1 true Common mistake: Clamping is not a substitute for checking nonfinite values.

Formal Syntax & Structure

rust syntaxrust
x.clamp(min, max) -> f64

Working Example

Example Snippetrust
fn main() {    let gain = 1.25_f64;    println!("{}", gain.clamp(0.0, 1.0));    println!("{}", f64::NAN.clamp(0.0, 1.0).is_nan());}
Rust Reference