Floating point ULPs comparisons of special values

The ULPS based comparisons in float_eq are less well specified than I would like. They aren't currently treating +/-INF or NaN values as special cases, although 0.0 == -0.0 is handled correctly.

As such, I've some questions I'd be interested to have input on:

  1. Would you expect NaNs to be handled in ULPs comparisons as they are for standard floating point comparisons? (i.e. all comparisons of any NaN value returns false, even if they are within the specified number of bits of one another). I'm near certain this should be the case but I'd be interested if anyone has an opposing opinion.

  2. How might you expect/like the infinities act when compared to nearby values in terms of ULPs? In more concrete terms, should the following continue to be allowed or should the behaviour be changed, given that the actual values are technically an infinite distance from one another?:

let inf = f32::INFINITY;
let prev = f32::from_bits(inf.to_bits() - 1);
assert_float_eq!(inf, prev, ulps <= 1); // currently passes

Thank you for your time :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.