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

Stefan Behnel <[email protected]>
Newsgroups gmane.comp.python.pyrex
Message-ID <[email protected]>
Hi,

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?
> 
> I tried this on MacOSX using 2.3:
> 
>>>> x = float('nan')
>>>> y = float('nan')
>>>> x == y
> True
> 
> But isn't that wrong? Aren't nans supposed to compare
> unequal to anything else, including themselves? What
> does 2.6 do here?

That looks platform specific to me. At least in 2.5, I don't get that:

  Python 2.5.1 (r251:54863, Mar  7 2008, 04:10:12)
  [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> a = float('nan')
  >>> b = float('nan')
  >>> a == b
  False

Same for the C code in Cython. That's why the test case doesn't check it:

http://hg.cython.org/cython-devel/file/02e2efe1bce5/tests/run/specialfloat.pyx

Stefan
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.