assert_all_close

Macro assert_all_close 

Source
macro_rules! assert_all_close {
    ($src:expr, $dst:expr  $(, $msg:literal $(, $($args:tt),*)?)?) => { ... };
}
Expand description

Asserts that two slices of floating-point values are approximately equal element-wise within a small tolerance (epsilon).

This is useful for comparing arrays of computed values where exact equality is not expected due to rounding errors.

  • Uses the machine epsilon for the floating-point type as the tolerance.
  • Element-wise crate::assert_close.

§Parameters

  • $src: Source slice (implements iter()).
  • $dst: Destination slice (same length as $src).
  • $msg: (optional) Custom failure message. Defaults to "{len} elements". Supports formatting arguments just like format!.

§Panics

  • If the lengths differ.
  • If any pair of elements differ by more than T::epsilon().

§Examples

let a = vec![1.0, 2.0, 3.0];
let b = vec![1.0 + 1e-16, 2.0, 3.0];

assert_all_close!(a, b); // OK
assert_all_close!(a, b, "Vectors must match"); // Custom message