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

Charles R Harris charlesr.harris at gmail.com
Tue Mar 10 18:35:51 EDT 2009


On Tue, Mar 10, 2009 at 4:19 PM, Timothy Hochberg <tim.hochberg at ieee.org>wrote:

>
>
> On Tue, Mar 10, 2009 at 2:49 PM, Charles R Harris <
> charlesr.harris at gmail.com> wrote:
>
>>
>>
>> On Tue, Mar 10, 2009 at 3:16 PM, Stéfan van der Walt <stefan at sun.ac.za>wrote:
>>
>>> 2009/3/10 Pauli Virtanen <pav at iki.fi>:
>>> > Nonzero Python object, hence True. Moreover, it's also True in Python:
>>>
>>> Also in C:
>>>
>>> #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.
>>
>
> I appear to be late to the party, but IMO it should raise an exception in
> those cases where it's feasible to do so.
>
>
That also seems reasonable to me. There is also the unresolved issue of
whether casting nan to an integer should raise an exception, currently it is
just converted to 0.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090310/6a62c177/attachment.html>


More information about the NumPy-Discussion mailing list