Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

The algorithm stops all spurious overflows and underflows.  If favorable 
cancellations exist, it finds them.

Algorithm in Words
------------------

For every x in the sequence, multiply onto the total if possible.

If x and "total" can't be combined without overflow/underflow, then x is given 
a "side" depending on |x| > 1.0.  This indicates whether multiplying by x would 
increase the magnitude or decrease it.

Note that "total" has the same side as "x". If one would increased magnitude 
and the other would decreased it, then our "total *= x" would have succeeded.

The list "s" has the other pending multiplies.  Each of them are on the same 
side — either they all increase the magnitude or they all decrease it.  The 
direction is stored in the "s_side" variable.

If "x" is on the same side as everything else in "s", we just append it.  No 
cancels are possible.

If "x" and "t" are on the opposite side of the elements in "s", then we 
multiply the big/little pairs to get favorable cancellations.  Any t_i will 
successfully combine with any s_i.

At the end of the loop, "total" and "s" are both on the same side and no 
further favorable cancellations are possible.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41458>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to