assert_float_relative_eq

Macro assert_float_relative_eq 

Source
macro_rules! assert_float_relative_eq {
    ($a:expr, $b:expr, $epsilon:expr) => { ... };
    ($a:expr, $b:expr) => { ... };
}
Expand description

Assert the relative error between two values is less than epsilon.

Panics if |(a - b) / a| > epsilon. If a.is_infinite(), then this will never panic. If a.is_nan(), then this will always panic.

  • a - First float.
  • b - Second float.
  • epsilon - Relative error tolerance between floats (defaults to 1.0e-6).

ยงExamples

assert_float_relative_eq!(4.0, 3.0, 0.25);
assert_float_relative_eq!(1.0, 0.5 + 0.5);