Tim Peters <t...@python.org> added the comment:

See "wisdom" earlier ;-) It's ad hoc trickery that seemingly can't be explained 
without showing the precise implementation in use today. As already mentioned, 
frexp() trickery _can_ be explained: exactly what you'd get if left-to-right HW 
multiplication were performed with an unbounded exponent, over- and 
under-flowing if and only if the infinite precision exponent at the end 
"doesn't fit". It completely eliminates spurious over-/under-flow. If someone 
wants that, it would be suitable for an fprod() function (which, like fsum(), 
makes strong guarantees at real cost).

Precisely which cases does this other thing protect against? Is there any way 
to characterize them beyond "well, try it and see"?

If there's an actual problem here, doesn't it deserve to be fixed? Just making 
it "less common" in some unquantifiable, unexplainable way seems unprincipled, 
and _possibly_ even harmful (e.g., by making it harder to provoke the 
underlying still-there problem without white box adversarial testing).


> Presumably that is why numpy uses pairwise summation instead of
> straight addition for example.

Loss of precision in fp summation is an extremely common real-life problem with 
real-life consequences.  That's why you can find dozens of papers, over the 
decades, on schemes to improve that. Adding a vector of a million floats is 
common; multiplying a vector of even a hundred floats is rare.

Similarly, scaled hypot implementations have been re-invented dozens of times. 
Etc.  When there's "a real" problem in fp life, it's hard _not_ to find mounds 
of prior art trying to address it.

You can find a few pieces on avoiding spurious under-/over-flow when chaining 
multiplies and divides, primarily older papers talking about 32-bit float 
formats with very limited dynamic range. The common advice: rearrange the 
handful of inputs in the source code by hand, based on your application 
knowledge of their likely magnitudes, to make left-to-right evaluation "safe".

----------

_______________________________________
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