[][src]Macro float_eq::assert_float_ne

macro_rules! assert_float_ne {
    ($left:expr, $right:expr, $eq1:ident <= $max_diff_1:expr, $eq2:ident <= $max_diff_2:expr, $eq3:ident <= $max_diff_3:expr) => { ... };
    ($left:expr, $right:expr, $eq1:ident <= $max_diff_1:expr, $eq2:ident <= $max_diff_2:expr) => { ... };
    ($left:expr, $right:expr, $eq1:ident <= $max_diff_1:expr) => { ... };
    ($left:expr, $right:expr, $($eq:ident <= $max_diff:expr,)+) => { ... };
    ($left:expr, $right:expr, $eq1:ident <= $max_diff_1:expr, $eq2:ident <= $max_diff_2:expr, $eq3:ident <= $max_diff_3:expr, $($arg:tt)+) => { ... };
    ($left:expr, $right:expr, $eq1:ident <= $max_diff_1:expr, $eq2:ident <= $max_diff_2:expr, $($arg:tt)+) => { ... };
    ($left:expr, $right:expr, $eq1:ident <= $max_diff_1:expr, $($arg:tt)+) => { ... };
}

Asserts that two floating point expressions are not equal to each other.

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

On panic, this macro will print the values of the expressions with their debug representations, with additional information from the comparison operations (using FloatEqDebug, FloatEqAllDebug and FloatDiff).

Like assert!, this macro has a second form, where a custom panic message can be provided.

Examples

let a: f32 = 4.;
let b: f32 = 4.1;

assert_float_ne!(a, 3.9999990, rel <= f32::EPSILON);
assert_float_ne!(a - b, 0., abs <= 0.00001, rel <= f32::EPSILON);
assert_float_ne!(a - b, 0., abs <= 0.00001, ulps <= 10);

assert_float_ne!(a - b, 0., abs <= 0.00001, ulps <= 10, "Checking that {} != {}", a, b);

let c = [1.000_000_2f32, -2.0];
let d = [1.0f32, -2.000_002];
assert_float_ne!(c, d, abs_all <= 0.000_000_1, ulps <= [2, 7]);