diff options
author | Raymond Hettinger <python@rcn.com> | 2008-07-19 00:42:03 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-07-19 00:42:03 (GMT) |
commit | 3c212163ec5fadeabf4070c2b2e22bd85e2d2aa0 (patch) | |
tree | a0f0a8d66d8cb814e8b3c8eb81f3c8168c05f806 /Lib | |
parent | f032a002711083610bf732bdfc5034e3af739ebe (diff) | |
download | cpython-3c212163ec5fadeabf4070c2b2e22bd85e2d2aa0.zip cpython-3c212163ec5fadeabf4070c2b2e22bd85e2d2aa0.tar.gz cpython-3c212163ec5fadeabf4070c2b2e22bd85e2d2aa0.tar.bz2 |
Improve accuracy of gamma test function
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_random.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index 07e12d3..8ad701b 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -5,7 +5,7 @@ import random import time import pickle import warnings -from math import log, exp, sqrt, pi +from math import log, exp, sqrt, pi, sum as msum from test import test_support class TestBasicOps(unittest.TestCase): @@ -465,11 +465,9 @@ _gammacoeff = (0.9999999999995183, 676.5203681218835, -1259.139216722289, def gamma(z, cof=_gammacoeff, g=7): z -= 1.0 - sum = cof[0] - for i in xrange(1,len(cof)): - sum += cof[i] / (z+i) + s = msum([cof[0]] + [cof[i] / (z+i) for i in range(1,len(cof))]) z += 0.5 - return (z+g)**z / exp(z+g) * sqrt(2*pi) * sum + return (z+g)**z / exp(z+g) * sqrt(2.0*pi) * s class TestDistributions(unittest.TestCase): def test_zeroinputs(self): |