This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Error on handling nan
Type: enhancement Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: bseiwald, mark.dickinson, mike.verdone, tim.peters
Priority: normal Keywords:

Created on 2003-05-14 12:12 by bseiwald, last changed 2022-04-10 16:08 by admin. This issue is now closed.

Messages (5)
msg16005 - (view) Author: Bernhard Seiwald (bseiwald) Date: 2003-05-14 12:12
We found some strange behavior of the handling of "nan"
if "nan" is used in if-statements.

We use Python 2.2 (python2-2.2.2-11.7.3.src.rpm).
In the following i show the results of the
"experiments" with "nan", "inf" and usual floats:


$ python
Python 2.2.2 (#1, Jan 30 2003, 21:26:22) 
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> a=float(1.2345)
>>> b=float("inf")
>>> c=float("nan")
>>> if a==b:
...  print "equal"
... 
>>> if a==c:
...  print "equal"
... 
equal
>>> if b==c:
...  print "equal"
... 
equal


Bernhard Seiwald seiwald@itp.tugraz.at
msg16006 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-05-15 01:48
Logged In: YES 
user_id=31435

Sorry, but all behavior in the presence of NaNs and infinities 
and signed zeroes is a platform- and release- dependent 
accident.  Even that float("inf") didn't raise an exception for 
you is an accident (e.g., in Python 2.2.2 on Windows, it 
does raise an exception).

I've added this to PEP 42's "non-accidental 754 support" 
feature request; you may also be interested in PEP 754 
(support for 754 special values).  Python has no 754 story 
now.  If you want it to have one, consider volunteering work 
toward that end.
msg57173 - (view) Author: Mike Verdone (mike.verdone) Date: 2007-11-06 18:34
For the benefit of those who stumble here through Google, here's a
workaround I've discovered for NaN testing. This is BAD:

value == float('NaN')

But this seems to work ok:

str(value) == str(float('NaN'))
msg113916 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-14 17:50
Reclassifying as out of date.  NaN handling in Python 2.6 and later is non-accidental.
msg113917 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-14 17:51
(and math.isnan is the recommended way to test for a nan).
History
Date User Action Args
2022-04-10 16:08:45adminsetgithub: 38501
2010-08-14 17:51:29mark.dickinsonsetmessages: + msg113917
2010-08-14 17:50:24mark.dickinsonsetresolution: later -> out of date
messages: + msg113916
2010-08-14 16:50:29ezio.melottisetnosy: + mark.dickinson
2007-11-06 18:34:30mike.verdonesetnosy: + mike.verdone
messages: + msg57173
title: Error on handling nan -> Error on handling nan
2003-05-14 12:12:01bseiwaldcreate