test for nan

Peter Maas fpetermaas at netscape.net
Thu Apr 1 09:38:48 EST 2004


Michael Hudson wrote:
> There can be more than one NaN, by the way.

I know that but if all NaNs have the same distinct algorithmic behaviour
that's not a problem.

>>This leads to
>>
>>def isNaN(x):
>>     return (x == x) == False
> 
> 
> This will work with 2.3 on Windows (I believe), current CVS on Windows
> (if compiled with VC7.1), current CVS on Linux (assuming an even
> vaguely recent gcc), but not current CVS on Windows compiled with VC6,
> nor Python 2.3 on Linux/gcc.  Confused yet?

No:

def isNaN1(x):
     return x != x

def isNaN2(x):
     return (x == 0) and (x == 1)

if sys.platform == 'win32' and '2.3' in sys.version:
         isNaN = isNaN1
elif sys.platform == 'win32' and 'good_CVS_VC_stuff' in sys.version:
         isNaN = isNaN1
elif sys.platform == 'win32' and 'bad_CVS_VC_stuff' in sys.version:
         isNaN = isNaN2
elif sys.platform == 'linux2':
         isNaN = isNaN2
else:
     raise Exception, "Roll your own isNaN() for platform " \
         "%s and version %s\n" % (sys.platform, sys.version)

bad/good_CVS_VC_stuff has to be worked out, don't have the version strings
available.

Mit freundlichen Gruessen,

Peter Maas

-- 
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas at mplusr.de
-------------------------------------------------------------------



More information about the Python-list mailing list