[][src]Macro float_eq::float_eq

macro_rules! float_eq {
    ($a:expr, $b:expr, $($eq:ident <= $max_diff:expr),+) => { ... };
    ($a:expr, $b:expr, $($eq:ident <= $max_diff:expr),+,) => { ... };
}

Checks if two floating point expressions are equal to each other.

Comparisons are applied in order from left to right, shortcutting to return early if a positive result is found.

When comparing composite types, variants that use a uniform max_diff value across all fields are also available:

Examples

let a: f32 = 4.0;
let b: f32 = 4.000_002_5;

assert!(float_eq!(a, 3.999_999_6, rmax <= 2.0 * f32::EPSILON));
assert!(float_eq!(a - b, 0.0, abs <= 0.000_01));
assert!(float_eq!(a, b, abs <= 0.000_01, ulps <= 10));