python 2.3.4 for windows: float("NaN") throws exception

Tim Peters tim.peters at gmail.com
Thu Jan 13 10:23:07 EST 2005


[asmirnov1234567890 at yahoo.com]
> my python 2.3.4 for windows refuse to execute line float("NaN"). It
> says:
>
> >>> float("NaN")
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> ValueError: invalid literal for float(): NaN
> 
> The same line works as expected on Linux and Solaris with python 2.3.4.
> Could anybody explain what is possibly wrong here? is it bug or
> feature?

Neither -- all Python behavior in the presence of float NaNs,
infinities, or signed zeroes is a platform-dependent accident.  In
this specific case, the accident is that the platform C runtime
string->double functions on your Linux and Solaris boxes recognize
"NaN", but Microsoft's string->double functions do not.  Microsoft's
libraries can't even read back the strings they *produce* for
NaNs.(usually "-1.#IND").



More information about the Python-list mailing list