Assign NaN, get zero

Stefan van der Walt stefan at
Sat Nov 11 15:54:49 CST 2006

On Sat, Nov 11, 2006 at 06:30:06PM -0300, Lisandro Dalcin wrote:
> On 11/11/06, Stefan van der Walt <stefan at> wrote:
> > NaN (or inf) is a floating point number, so seeing a zero in integer
> > representation seems correct:
> >
> > In [2]: int(N.nan)
> > Out[2]: 0L
> >
> Just to learn myself: Why int(N.nan) should be 0? Is it C behavior?

As far as I know (and please correct me if I'm wrong), nan's are just
a specific bit pattern set in memory when an invalid floating point
operation occurs (in IEEE 754 nan's are represented by an exponent of
all 1's and a non-zero mantissa).

Most integer representations have no way of indication an invalid
result (and C provides no such conversion, as far as I am aware), so
nan's are interpreted as 0 (which could have been any arbitrary number
for that matter, although 0 seems a logical choice).


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

More information about the Numpy-discussion mailing list