Nan with Python 2.5 on Windows
How do I build Nan with Python 2.5 on Windows?
float('nan')
with a mistake ValueError: invalid literal for float(): nan
Summary of answers: Neither float('inf')
nor float('nan')
does it work with Python 2.5 and Windows. This is a bug that has been fixed in Python 2.6.
If you are using numpy you can use numpy.inf
and numpy.nan
.
If you want a workaround without numpy, you can use an expression that overflows, for example 1e1000
to get inf, and 1e1000 / 1e1000
or 1e1000 - 1e1000
to get nan.
source to share
Upgrade your Python distribution if possible. The behavior you conduct is considered a mistake. (Note: Cython .)
Canonically, Python should support this definition in a nan
cross-platform way. This behavior appears to have been fixed in Python 2.6 and 3.0.
Of course this works in Linux Python versions:
$ python2.4
Python 2.4.3 (#1, Sep 21 2011, 19:55:41)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> float('nan')
nan
$ python2.5
Python 2.5.2 (r252:60911, Jun 26 2008, 10:20:40)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> float('nan')
nan
source to share