[Numpy-discussion] What is the logical value of nan?
Charles R Harris
charlesr.harris@gmail....
Wed Mar 11 10:16:42 CDT 2009
On Wed, Mar 11, 2009 at 8:24 AM, Bruce Southey <bsouthey@gmail.com> wrote:
> Sturla Molden wrote:
> > Charles R Harris wrote:
> >
> >> #include <math.h>
> >> #include <stdio.h>
> >>
> >> int main() {
> >> double nan = sqrt(-1);
> >> printf("%f\n", nan);
> >> printf("%i\n", bool(nan));
> >> return 0;
> >> }
> >>
> >> $ ./nan
> >> nan
> >> 1
> >>
> >>
> >> So resolved, it is True.
> >>
> > Unless specified in the ISO C standard, I'd say this is system and
> > compiler dependent.
> >
> > Should NumPy rely on a specific binary representation of NaN?
> >
> > A related issue is the boolean value of Inf and -Inf.
> >
> > Sturla Molden
> > _______________________________________________
> > Numpy-discussion mailing list
> > Numpy-discussion@scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> >
> This is one link that shows the different representation of these
> numbers in IEEE 754:
> http://www.psc.edu/general/software/packages/ieee/ieee.php
> It is a little clearer than Wikipedia:
> http://en.wikipedia.org/wiki/IEEE_754-1985
>
> Numpy's nan/NaN/NAN, inf/Inf/PINF, and NINF are not nothing so not zero.
> 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.
>
> 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.
>
> However, I noticed that the standard has just been revised that may
> eventually influence Numpy:
> http://en.wikipedia.org/wiki/IEEE_754r
> http://en.wikipedia.org/wiki/IEEE_754-2008
>
> Note this defines the min/max behavior:
>
> * |min(x,NaN) = min(NaN,x) = x|
> * |max(x,NaN) = max(NaN,x) = x|
>
>
We have this behavior in numpy with the fmax/fmin functions.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090311/425eeff1/attachment.html
More information about the Numpy-discussion
mailing list