[Python-ideas] checking for identity before comparing built-in objects
Chris Angelico
rosuav at gmail.com
Tue Oct 9 10:44:45 CEST 2012
On Tue, Oct 9, 2012 at 7:19 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> 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.
But if you know that that's a possibility, you simply code your
condition the other way:
while error > epsilon:
find_a_better_approximation()
Which will then immediately terminate the loop if error bonks to NaN.
ChrisA
More information about the Python-ideas
mailing list