Function nearly_equal

Source
pub const fn nearly_equal(a: f32, b: f32, options: ComparisonOptions) -> bool
Expand description

Compares two floating point numbers a and b to see if they are nearly equal.

This function uses both relative and absolute comparisons to handle cases where the values differ by a small but significant amount due to floating-point precision limitations.

  • origin: https://stackoverflow.com/questions/4915462/how-should-i-do-floating-point-comparison

ยงPanics

Ensure that epsilon is within a reasonable range:

  • It should not be smaller than the smallest representable float (FLT_EPSILON)
  • It should not be equal to or greater than 1.0 to avoid overly lenient comparisons