special case (inf,-inf,nan) float problems.

Jeremy R Van Haren vanharen at cycletime.com
Fri Apr 6 03:51:26 EDT 2001


Let me start of by saying I'm using 1.5.2, so maybe the problem's have
been fixed in 2.0, but searches don't seem to help.

Problem #1:
A float that is set to Nan compares == to just about any other floating
number.  I would think that 

to test:
python
>>> print float ('nan') == 0.0
1
>>> print float ('nan') == 0.1
1


which lead me to my second problem.  In order to actually compare
against nan I compare against the string representation, however:

Problem #2
on 1.5.2 on RedHat linux 6.2 I get
>>> print `float('-inf')`,`float('inf')`,`float('nan')`
-inf inf nan

however with 1.5.2 on Solaris 7 I get
>>> print `float('-inf')`,`float('inf')`,`float('nan')`
-Infinaty Infinaty NaN


I've worked around both of these issues, but I think they are both
problems.  Does anybody know if this has been taken care of in 2.0?



More information about the Python-list mailing list