[Python-checkins] r65127 - python/trunk/Lib/test/test_random.py

raymond.hettinger python-checkins at python.org
Sat Jul 19 02:42:03 CEST 2008


Author: raymond.hettinger
Date: Sat Jul 19 02:42:03 2008
New Revision: 65127
Log:
Improve accuracy of gamma test function
Modified:
 python/trunk/Lib/test/test_random.py
Modified: python/trunk/Lib/test/test_random.py
==============================================================================
--- python/trunk/Lib/test/test_random.py	(original)
+++ python/trunk/Lib/test/test_random.py	Sat Jul 19 02:42:03 2008
@@ -5,7 +5,7 @@
 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 @@
 
 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):


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /