[issue34376] Improve accuracy of math.hypot() and math.dist()

Tim Peters report at bugs.python.org
Sun Aug 12 12:00:36 EDT 2018


Tim Peters <tim at python.org> added the comment:

Sure, if we make more assumptions.  For 754 doubles, e.g., scaling isn't needed if `1e-100 < absmax < 1e100` unless there are a truly ludicrous number of points.  Because, if that holds, the true sum is between 1e-200 and number_of_points*1e200, both far from being near trouble.

Then the summation loop gets mostly duplicated (with and without scaling), a platform-dependent assumption is introduced, and we need two test-and-branches to determine which to run.  In the common two-argument cases, it saves one division in return.

Note that without the current form of scaling, we lose the guarantee that the sum is exact when all the arguments are the same (because they're all scaled to exactly 1.0 then, but in general each x*x loses half the product bits without scaling).  I don't care about that myself, but Serhiy seems to.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34376>
_______________________________________


More information about the Python-bugs-list mailing list