Re: [Python-Dev] Examples for PEP 572

2018年7月04日 11:24:39 -0700

On Wed, Jul 04, 2018 at 08:33:17PM +0300, Ivan Pozdeev via Python-Dev wrote:
> >>while total != (total := total + term):
> >>  term *= mx2 / (i*(i+1))
> >>  i += 2
> >>return total
[...]
> It took me a few minutes to figure out that this construct actually 
> checks term == 0.
That's badly wrong.
Hint: it's floating point code. total and term are floats, so things 
like this are possible:
py> total = 9.5e95
py> term = 1.2
py> total + term == total
True
As you can see, term is nothing even close to zero.
> So, this example abuses the construct to do something it's not designed 
> to do: perform an unrelated operation before checking the condition.
Well, that's one opinion.
> (Cue attempts to squeeze ever mode code here.) I would fail it in review.
Okay.
-- 
Steve
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to