[Python-checkins] Future-proof helper function with zero handling. (GH-107798)
rhettinger
webhook-mailer at python.org
Wed Aug 9 03:44:47 EDT 2023
https://github.com/python/cpython/commit/2fb484e62518d15fc9a19565c2ab096bd741219a
commit: 2fb484e62518d15fc9a19565c2ab096bd741219a
branch: main
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2023-08-09T08:44:43+01:00
summary:
Future-proof helper function with zero handling. (GH-107798)
files:
M Lib/statistics.py
diff --git a/Lib/statistics.py b/Lib/statistics.py
index 066669d25ddb1..93c44f1f13fab 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -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)
More information about the Python-checkins
mailing list