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

Raymond Hettinger report at bugs.python.org
Fri Aug 10 16:40:32 EDT 2018


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

> What results for all components equal? hypot(1.0, 1.0, ..., 1.0)

The scaled summation will be exact (all elements scale to 1.0 and frac is always 0.0).

> Would it give a performance benefit if get rid of multiplication 
> and division, and scale by the power of two approximation of the 
> max using ldexp()?

You're right that the multiplication and division are the most expensive part (the adds and subtracts are cheaper and can be done in parallel with subsequent memory fetches).  See the attached Clang and GCC-8 disassemblies.

I've tried a number of variants and couldn't get any performance boost without breaking some of the test cases.  This patch is the best of a dozen attempts.

----------
Added file: https://bugs.python.org/file47744/math_hypot.s

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


More information about the Python-bugs-list mailing list