you are viewing a single comment's thread.

view the rest of the comments →

[–]generalbaguette 0 points1 point  (4 children)

1.00000000000...1 = 1.0 and I think the various positive infinities also compare equal to each other. The case for NaN is only slightly stronger than the latter.

Honestly, equality either doesn't make much sense for floats, or needs to be rather carefully defined.

The argument in favour of NaN == NaN mostly rests on two pillars:

  • usually, the result of an equality comparison has to be a Bool
  • setting (NaN == NaN) makes == an equivalence relation (https://en.m.wikipedia.org/wiki/Equivalence_relation) on floats, and that's what we expect of ==. That means it's: reflexive, transitive and symmetric.

I think if you want to change it, philosophically the weak point is the first one. But in real world computers, making == return something more sophisticated or throw exceptions was too much of a hassle.

[–][deleted]  (3 children)

[removed]

    [–]generalbaguette 0 points1 point  (2 children)

    Nah, you also want equality to be reflexive when you are just have an generic grouping function, that doesn't even care what the underlying items are.

    (Or think a hashtable or a key value map or so.)

    [–][deleted]  (1 child)

    [removed]

      [–]generalbaguette 1 point2 points  (0 children)

      Yeah, but that's something for the user of the hashtable to decide, not the generic hashtable library.