1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/// Assert that two numbers are almost equal to each other. /// /// On panic, this macro will print the values of the expressions with their /// debug representations. #[macro_export] macro_rules! assert_almost_eq { ($a:expr, $b:expr, $prec:expr) => ( let diff = ($a - $b).abs(); if diff > $prec { panic!(format!( "assertion failed: `abs(left - right) = {:.1e} < {:e}`, \ (left: `{}`, right: `{}`)", diff, $prec, $a, $b)); } ); }