a.index(float('nan')) fails

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Oct 25 22:44:37 EDT 2012


On Thu, 25 Oct 2012 22:04:52 -0400, Terry Reedy wrote:

> It is a consequence of the following, which some people (but not all)
> believe is mandated by the IEEE standard.
> 
>  >>> nan = float('nan')
>  >>> nan is nan
> True

The IEEE 754 standard says nothing about object identity. It only 
discusses value equality.

>  >>> nan == nan
> False

IEEE 754 states that all NANs compare unequal to everything, including 
NANs with the same bit value. It doesn't make an exception for 
comparisons with itself.

I'm not entirely sure why you suggest that there is an argument about 
what IEEE 754 says about NANs. As far as I can see, the argument is 
whether or not language designers should pick and choose which bits of 
the standard they want to follow, thus taking a step backwards to the 
chaos of numerical computing prior to the IEEE 754 standard.

Seriously, there are some real horror stories about numerical computing 
back in the Bad Old Days. Like computers where 1.0/x could give a divide-
by-zero error even though x == 0 returned False.



-- 
Steven



More information about the Python-list mailing list