expression
Approximate floating-point equality
For finite measurements near the same scale, choose an absolute tolerance based on the measurement error. For wide magnitude ranges, a combined relative and absolute tolerance is more useful. Expected stdout (not executed): true Common mistake: A single fixed tolerance is not appropriate for every magnitude; reject nonfinite inputs or handle them separately.
Formal Syntax & Structure
rust syntaxrust
(a - b).abs() <= toleranceWorking Example
Example Snippetrust
fn main() { let a = 0.1_f64 + 0.2; let b = 0.3_f64; println!("{}", (a-b).abs() <= 1e-12);}