[issue41513] Scale by power of two in math.hypot()
Raymond Hettinger
report at bugs.python.org
Sat Aug 15 00:54:40 EDT 2020
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
Update:
def hypot(*coords):
# Corrected, unfused: https://arxiv.org/pdf/1904.09481.pdf
# Simplified version omits scaling and handling of wide ranges
# Has 1 ulp error 0.44% of the time (0.54% per the paper).
# Can be reduced to 0% with a fused multiply-add.
a, b = map(fabs, coords)
if a < b:
a, b = b, a
h = sqrt(a*a + b*b)
if h <= 2*b:
delta = h - b
x = a*(2*delta - a) + (delta - 2*(a - b))*delta
else:
delta = h - a
x = 2*delta*(a - 2*b) + (4*delta - b)*b + delta*delta
return h - x/(2*h)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41513>
_______________________________________
More information about the Python-bugs-list
mailing list