Function unit_test_utils::nearly_equal
source · Expand description
Whether two floats are nearly equal (up to specified tolerance)
Arguments
a
first floatb
second floatrel_tol
relative tolerance (must be positive)abs_tol
absolute tolerance (must be positive)
Results
Returns true if and only if a
is nearly equal to b
.
In particular, this function will return true if and only if BOTH of the following conditions are satisfied
a==b
, e.g., if the two floats are identical or both equal to infinity|a-b| <= max(abs_tol, rel_tol*max(|a|, |b|))
The function will return false if either of a
or b
is NaN
.
It works with f64
and f32
Panics
The function will panic if the specified relative or absolute tolerance is not positive.