Skip to content

Commit c3bc0fe

Browse files
authored
Factor-out constant calculation. (GH-29491)
1 parent 5b7c7cb commit c3bc0fe

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Lib/statistics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
from operator import itemgetter, mul
140140
from collections import Counter, namedtuple
141141

142+
_SQRT2 = sqrt(2.0)
143+
142144
# === Exceptions ===
143145

144146
class StatisticsError(ValueError):
@@ -1102,7 +1104,7 @@ def cdf(self, x):
11021104
"Cumulative distribution function. P(X <= x)"
11031105
if not self._sigma:
11041106
raise StatisticsError('cdf() not defined when sigma is zero')
1105-
return 0.5 * (1.0 + erf((x - self._mu) / (self._sigma * sqrt(2.0))))
1107+
return 0.5 * (1.0 + erf((x - self._mu) / (self._sigma * _SQRT2)))
11061108

11071109
def inv_cdf(self, p):
11081110
"""Inverse cumulative distribution function. x : P(X <= x) = p
@@ -1158,7 +1160,7 @@ def overlap(self, other):
11581160
dv = Y_var - X_var
11591161
dm = fabs(Y._mu - X._mu)
11601162
if not dv:
1161-
return 1.0 - erf(dm / (2.0 * X._sigma * sqrt(2.0)))
1163+
return 1.0 - erf(dm / (2.0 * X._sigma * _SQRT2))
11621164
a = X._mu * Y_var - Y._mu * X_var
11631165
b = X._sigma * Y._sigma * sqrt(dm * dm + dv * log(Y_var / X_var))
11641166
x1 = (a + b) / dv

0 commit comments

Comments
 (0)