Skip to main content

approx_ne

Macro approx_ne 

Source
macro_rules! approx_ne {
    ($lhs:expr, $rhs:expr) => { ... };
    ($lhs:expr, $rhs:expr, rtol <= $rtol:expr) => { ... };
    ($lhs:expr, $rhs:expr, atol <= $atol:expr) => { ... };
    ($lhs:expr, $rhs:expr, rtol <= $rtol:expr, atol <= $atol:expr) => { ... };
    ($lhs:expr, $rhs:expr, atol <= $atol:expr, rtol <= $rtol:expr) => { ... };
}
Expand description

Checks if two values are not approximately equal.

Returns true if the values are not approximately equal (differ beyond the specified tolerances), false otherwise. This is the logical negation of approx_eq!.

§Syntax

approx_ne!(left, right)                          // Default tolerances
approx_ne!(left, right, atol <= tolerance)       // Custom absolute tolerance
approx_ne!(left, right, rtol <= tolerance)       // Custom relative tolerance
approx_ne!(left, right, atol <= a, rtol <= r)    // Both tolerances
approx_ne!(left, right, rtol <= r, atol <= a)    // Order doesn't matter

§Examples

use lox_test_utils::approx_ne;

// Values that differ significantly
assert!(approx_ne!(1.0, 2.0));
assert!(approx_ne!(1.0, 1.1));

// Values within epsilon are considered equal, so approx_ne returns false
assert!(!approx_ne!(1.0, 1.0 + f64::EPSILON));

// Custom tolerances
assert!(approx_ne!(1.0, 1.1, atol <= 0.01));
assert!(!approx_ne!(1.0, 1.001, atol <= 0.01));

§See Also