assert_nearly!() { /* proc-macro */ }Expand description
Asserts that the given comparison is nearly true using the provided tolerance.
On panic, this macro will print the values of the comparison with their debug representations as well as the values of the provided tolerance.
The comparison can be:
a == bfor testing whether a is nearly equal to ba != bfor testing whether a is not nearly equal to b
The tolerance used can be:
epsfor an absolute epsilon toleranceulpsfor an ulps based tolerancetolfor an absolute epsilon and ulps based tolerancedefaultfor an absolute epsilon and ulps based tolerance using default values
ยงExamples
use nearly::{assert_nearly, Tolerance};
let a: f32 = 1.0;
let b: f32 = 1.0;
// use absolute epsilon tolerance
assert_nearly!(a == b, eps = 0.01);
// use ulps based tolerance
assert_nearly!(a == b, ulps = 5);
// use absolute epsilon and ulps based tolerance
assert_nearly!(a == b, eps = 0.01, ulps = 5);
assert_nearly!(a == b, tol = Tolerance::new(0.01, 5));
// use default absolute epsilon and default ulps based tolerance
assert_nearly!(a == b);