about_eq

Function about_eq 

Source
pub fn about_eq(a: f32, b: f32, granularity: f32) -> bool
Expand description

f32 equality used in floating-point units.

  • NaN values are equal.
  • INFINITY values are equal.
  • NEG_INFINITY values are equal.
  • Finite values are equal if they fall in the same bucket sized by granularity.

Note that this definition of equality is symmetric, reflexive, and transitive. This is slightly different them equality defined by minimal distance epsilon, in some cases abs(a - b) < granularity can be true and not equal because they are near a bucket threshold. In practice this does not mather given sufficient small granularity, it is more stable due to the transitive property and enables the about_eq_hash function to always output the same hash for the same values.