[Python-ideas] checking for identity before comparing built-in objects

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Oct 9 10:52:01 CEST 2012


On Oct 9, 2012 9:20 AM, "Greg Ewing" <greg.ewing at canterbury.ac.nz> wrote:
>
> Oscar Benjamin wrote:
>>
>> The main purpose of quiet NaNs is to propagate through computation
>> ruining everything they touch.
>
>
> But they stop doing that as soon as they hit an if statement.
> It seems to me that the behaviour chosen for NaN comparison
> could just as easily make things go wrong as make them go
> right. E.g.
>
>    while not (error < epsilon):
>       find_a_better_approximation()
>
> If error ever ends up being NaN, this will go into an
> infinite loop.

I should expect that an experienced numericist would be aware of the
possibility of a NaN and make a trivial modification of your loop to take
advantage of the simple fact that any comparison with NaN returns false. It
is only because you have artificially placed a not in the while clause that
it doesn't work. I would have tested for error>eps without even thinking
about NaNs.

Oscar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121009/af958072/attachment.html>


More information about the Python-ideas mailing list