From 2fb484e62518d15fc9a19565c2ab096bd741219a Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 9 Aug 2023 08:44:43 +0100 Subject: [PATCH] Future-proof helper function with zero handling. (GH-107798) --- Lib/statistics.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/statistics.py b/Lib/statistics.py index 066669d25dd..93c44f1f13f 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)