[Python-Dev] Examples for PEP 572

Terry Reedy tjreedy at udel.edu
Thu Jul 5 01:13:13 EDT 2018


On 7/4/2018 2:32 PM, Sven R. Kunze wrote:
> Sorry for adding yet another mail. :-(
> 
> On 04.07.2018 10:54, Serhiy Storchaka wrote:
>> Sorry, this PEP was rewritten so many times that I missed your Appendix.
>>
>>> while total != (total := total + term):
>>>     term *= mx2 / (i*(i+1))
>>>     i += 2
>>> return total
>>
> 
> This very example here caught my eye.
> 
> Isn't total not always equal to total

Repeat response given elsewhere.  No.  Python has limited precision 
floats, not reals.  Floats do not obey laws of real numbers.

 >>> 1e50 + 1e34 == 1e50
True
 >>> 1e50 + 1e35 == 1e50
False

Basic numerical analysis operation: approximate infinite sum of 
decreasing terms by summing terms until they become small enough that 
they can be ignored.


-- 
Terry Jan Reedy




More information about the Python-Dev mailing list