test for nan

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Thu Apr 1 09:25:08 EST 2004


John Hunter wrote:
> Out of curiosity, are there any platforms where this is known to fail?
> 
>   def is_nan(x):
>       return str(x).lower().find('nan')>=0

Yes...

Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on 
win32

IDLE 1.0.2
 >>> def is_nan(x):
	return str(x).lower().find('nan') >= 0

 >>> inf=float('1e9999')
 >>> inf
1.#INF
 >>> nan=inf-inf
 >>> is_nan(nan)
False
 >>> nan
-1.#IND

-- 
"Codito ergo sum"
Roel Schroeven



More information about the Python-list mailing list