[][src]Macro ntest::assert_about_eq

macro_rules! assert_about_eq {
    ($a:expr, $b:expr, $eps:expr) => { ... };
    ($a:expr, $b:expr,$eps:expr,) => { ... };
    ($a:expr, $b:expr) => { ... };
    ($a:expr, $b:expr,) => { ... };
}

Compare floating point values or vectors of floating points wether they are approximately equal. The default value for epsilon is 1.0e-6.

Examples

Compare two floating point values which are about equal:

assert_about_eq!(42.00000001f32, 42.0f32);

Explicitly set an epsilon value. This test should fail:

assert_about_eq!(42.001f32, 42.0f32, 1.0e-4);

Compare two vectors or arrays of floats which are about equal:

assert_about_eq!(vec![1.100000001, 2.1], vec![1.1, 2.1], 0.001f64);

Arrays can be compared to a length of up to 32. See the MaxDifference implementation for more details:

assert_about_eq!([1.100000001, 2.1], [1.1, 2.1], 0.001f64);