Macro assert_eq_float::assert_eq_float
source · macro_rules! assert_eq_float { (@standard $left:ident, $right:ident, $error:ident) => { ... }; (@custom $left:ident, $right:ident, $error:ident; $($arg:tt)+) => { ... }; ($left:expr, $right:expr $(,)?) => { ... }; ($left:expr, $right:expr; $($arg:tt)+) => { ... }; ($left:expr, $right:expr, $error:expr $(,)?) => { ... }; ($left:expr, $right:expr, $error:expr; $($arg:tt)+) => { ... }; }
Expand description
Asserts that two float expressions are (approximately) equal to each other.
On panic, this macro will print the values of the expressions with their debug representations.
Like assert_eq!
, this macro has a second form, where a custom
panic message can be provided.
§Examples
use assert_eq_float::assert_eq_float;
let a = 3.0;
let b = 1.0 + 2.0;
assert_eq_float!(a, b);
assert_eq_float!(a, b; "we are testing addition with {} and {}", a, b);
assert_eq_float!(a, b, 1e-7); // use a fixed error
Note that when setting a custom panic message, you should use a semicolon ;
instead of a comma ,
.