pub fn nearly_equal<T>(a: T, b: T, rel_tol: T, abs_tol: T) -> boolwhere
    T: Float + Zero,
Expand description

Whether two floats are nearly equal (up to specified tolerance)

Arguments

  • a first float
  • b second float
  • rel_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.