[Pyrex] special floats generate incorrect C code when used as compile-time constants

Robert Kern robert.kern at gmail.com
Sat Apr 26 00:19:50 CEST 2008


Greg Ewing wrote:
> Stefan Behnel wrote:
>> As of 2.6, float('inf') and float('nan') will be guaranteed to work
> 
> Does it also provide a way of testing whether a value
> is an inf or nan?

Yes, math.isinf() and math.isnan().

> I tried this on MacOSX using 2.3:
> 
>  >>> x = float('nan')
>  >>> y = float('nan')
>  >>> x == y
> True
> 
> But isn't that wrong?

Very. Possibly, at that point someone added an optimization to reuse the Python 
object so "x is y" short-circuited the floating-point comparison.

> Aren't nans supposed to compare
> unequal to anything else, including themselves? What
> does 2.6 do here?

2.5.2 on OS X and every other platform I have ever remembered using (including 
Python 2.3 on OS X 10.3, IIRC; I don't have access anymore to check) gave the 
correct answer.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Pyrex mailing list