Skip to content

Commit c4a0eea

Browse files
committed
Use more accurate sqrt(2*pi)
1 parent 60ab407 commit c4a0eea

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎Lib/statistics.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
from collections import Counter, namedtuple, defaultdict
147147

148148
_SQRT2 = sqrt(2.0)
149-
_SQRT2PI = sqrt(2.0 * pi)
149+
_SQRT2PI = float.fromhex('0x1.40d931ff62706p+1') # Correctly rounded sqrt(2*pi)
150150
_random = random
151151

152152
## Exceptions ##############################################################
@@ -821,8 +821,8 @@ def deco(builder):
821821

822822
@register('normal', 'gauss')
823823
def normal_kernel():
824-
sqrt2pi = sqrt(2 * pi)
825-
neg_sqrt2 = -sqrt(2)
824+
sqrt2pi = _SQRT2PI
825+
neg_sqrt2 = -_SQRT2
826826
pdf = lambda t: exp(-1/2 * t * t) / sqrt2pi
827827
cdf = lambda t: 1/2 * erfc(t / neg_sqrt2)
828828
invcdf = lambda t: _normal_dist_inv_cdf(t, 0.0, 1.0)

0 commit comments

Comments
 (0)