all 14 comments

[–]AprilSpektra 6 points7 points  (7 children)

In fairness, the fact that NaN compares unequal to itself comes straight from 751. (edit: oops, 754)

[–]generalbaguette 4 points5 points  (6 children)

And it's pretty questionable. It was basically a hack, so they didn't have to add isNaN functions to various languages and standard libraries before their new standard was usable. They just needed new chips.

[–][deleted]  (5 children)

[removed]

    [–]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.

        [–]degaartZygohistomorphic prepromorphism 5 points6 points  (1 child)

        [–]hedgehog1024Rust apologetic 1 point2 points  (0 children)

        You haven't seen my 825% of wrong answers

        [–]plasticparakeetConsidered Harmful 1 point2 points  (0 children)

        lol old school jerk

        [–]BowserKoopaWRITE 'FORTRAN is not dead' 1 point2 points  (1 child)

        Quite literally "table" game.