[Numpy-discussion] What is the logical value of nan?

Christopher Barker Chris.Barker@noaa....
Wed Mar 11 12:06:52 CDT 2009

Sturla Molden wrote:
> Why not raise an exception when NaN is evaluated in a boolean
> context? bool(NaN) has no obvious interpretation, so it should be
> considered an error.


Though there is clearly a lot of legacy around this, so maybe it's best
to follow C convention (sigh).

Bruce Southey wrote:
> Also, I think that conversion to an integer should be an error for
> all of these because there is no equivalent representation of these
> floating point numbers as integers and I think that using zero for
> NaN is wrong.


A silent wrong conversion is MUCH worse than an exception!

As for MATLAB, it was entirely doubles for a long time -- I don't think
it's a good example of well thought-out float<->integer interactions.

> Now for the other two special representations, I would presume that 
> Numpy's PZERO (positive zero) and NZERO (negative zero) are treated
> as nothing. Conversion to integer for these should be zero.


> Note this defines the min/max behavior:
> * |min(x,NaN) = min(NaN,x) = x| * |max(x,NaN) = max(NaN,x) = x|

nice -- it's nice to have these defined -- of course, who knows how long 
it will be (never?) before compilers/libraries support this.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the Numpy-discussion mailing list