Re: special floats generate incorrect C code when used as compile-time constants

Robert Kern <[email protected]>
Newsgroups gmane.comp.python.pyrex
Organization The Church of Last Thursday
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.