Result of ``a is b''
Erik Max Francis
max at alcyone.com
Fri Mar 19 15:54:56 EST 2004
Andrew Koenig wrote:
> I'm pretty sure that IEEE floating point requires NaN to be defined in
> such
> a way that if x is NaN, then x == x must yield False.
That's correct. Python itself doesn't do this, though:
Python 2.3.3 (#1, Dec 22 2003, 23:44:26)
[GCC 3.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 1e3000
>>> a
inf
>>> a/a
nan
>>> n = a/a
>>> n == n
True
>>>
[Similar things are shown for Python on Solaris 8.]
But the following C program:
#include <stdio.h>
int main(void)
{
double a = 1e3000;
double n = a/a;
printf("%f, %f, %d\n", a, n, a == n);
return 0;
}
prints
inf, nan, 0
on Intel Linux.
--
__ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Chance favors the trained mind.
-- Louis Pasteur
More information about the Python-list
mailing list