Future-proof helper function with zero handling. (GH-107798)

This commit is contained in:
Raymond Hettinger 2023-08-09 08:44:43 +01:00 committed by GitHub
parent 34cafd35e3
commit 2fb484e625
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -1009,6 +1009,8 @@ def _sqrtprod(x: float, y: float) -> float:
# Square root differential correction:
# https://www.wolframalpha.com/input/?i=Maclaurin+series+sqrt%28h**2+%2B+x%29+at+x%3D0
h = sqrt(x * y)
if not h:
return 0.0
x = sumprod((x, h), (y, -h))
return h + x / (2.0 * h)