Why float('Nan') == float('Nan') is False

Grant Edwards grant.b.edwards at gmail.com
Wed Feb 13 14:53:43 EST 2019


On 2019-02-13, Schachner, Joseph <Joseph.Schachner at Teledyne.com> wrote:

> This makes some sense because NAN is Not A Number, so any comparison
> to a number fails.

Ah, but you now seem to be conflating "comparison fails" with
"comparison has a boolean value of False".

The alternative to (nan == nan) => False is probably not (nan == nan)
=> True: it's (nan == nan) => exception.  Towards that end, the IEEE
standard provides for something called a "signalling NaN".  I'm not
aware of any Python implementations that support signalling NaNs.

Floating point is sort of the quantum mechanics of computer science.
At first glance, it seems sort of weird.  But after you work with it a
while, it gets even worse.

-- 
Grant Edwards               grant.b.edwards        Yow! Jesuit priests are
                                  at               DATING CAREER DIPLOMATS!!
                              gmail.com            




More information about the Python-list mailing list