Macro assert_float_eq::expect_f64_near
source · macro_rules! expect_f64_near {
($a:expr, $b:expr, $n:expr) => { ... };
($a:expr, $b:expr) => { ... };
}
Expand description
Expect two 64-bit floats are within n
steps of each other.
Returns an error if the two floats are more than n
steps away
from each other.
a
- First float.b
- Second float.n
- Step tolerance between floats.
Each step is derived from the previous float by incrementing
the float’s bits, as if they were an integer, by 1.
For example, the next float from 1e-45 (0x00000001
) would be
3e-45 (0x00000002
).
Examples
assert!(expect_f64_near!(5e-324, 2.5e-323).is_ok());
assert!(expect_f64_near!(5e-324, 2.5e-323, 3).is_err());
assert!(expect_f64_near!(5e-324, 5e-323, 9).is_ok());
assert!(expect_f64_near!(5e-324, 5e-323, 8).is_err());
assert!(expect_f64_near!(3e300, 3.0000000000000025e+300).is_ok());