Skip to content

Commit

Permalink
Future-proof helper function with zero handling.
Browse files Browse the repository at this point in the history
The ZeroDivisionError was already being caught in correlation(),
but it is nicer to handle the zero case inside the helper function.
  • Loading branch information
rhettinger committed Aug 9, 2023
1 parent 925bbc2 commit c27f174
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c27f174

Please sign in to comment.