[Numpy-discussion] What is the logical value of nan?
Bruce Southey
bsouthey at gmail.com
Wed Mar 11 10:24:31 EDT 2009
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 at 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|
Bruce
More information about the NumPy-Discussion
mailing list