[pypy-svn] r76100 - pypy/branch/fast-forward/pypy/module/math

benjamin at codespeak.net benjamin at codespeak.net
Sat Jul 10 20:33:11 CEST 2010


Author: benjamin
Date: Sat Jul 10 20:33:09 2010
New Revision: 76100

Modified:
   pypy/branch/fast-forward/pypy/module/math/interp_math.py
Log:
rewrite so the annotator doesn't think we're dividing by zero

Modified: pypy/branch/fast-forward/pypy/module/math/interp_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/interp_math.py	(original)
+++ pypy/branch/fast-forward/pypy/module/math/interp_math.py	Sat Jul 10 20:33:09 2010
@@ -1,7 +1,7 @@
 import math
 import sys
 
-from pypy.rlib import rarithmetic
+from pypy.rlib import rarithmetic, unroll
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped
 
@@ -557,6 +557,8 @@
 _lanczos_den_coeffs = [
     0.0, 39916800.0, 120543840.0, 150917976.0, 105258076.0, 45995730.0,
     13339535.0, 2637558.0, 357423.0, 32670.0, 1925.0, 66.0, 1.0]
+LANCZOS_N = len(_lanczos_den_coeffs)
+_lanczos_n_iter = unroll.unrolling_iterable(range(LANCZOS_N))
 _gamma_integrals = [
     1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0, 5040.0, 40320.0, 362880.0,
     3628800.0, 39916800.0, 479001600.0, 6227020800.0, 87178291200.0,
@@ -569,11 +571,11 @@
     den = 0.
     assert x > 0.
     if x < 5.:
-        for i in range(len(_lanczos_den_coeffs) - 1, -1, -1):
+        for i in _lanczos_n_iter:
             num = num * x + _lanczos_num_coeffs[i]
             den = den * x + _lanczos_den_coeffs[i]
     else:
-        for i in range(len(_lanczos_den_coeffs)):
+        for i in _lanczos_n_iter:
             num = num / x + _lanczos_num_coeffs[i]
             den = den / x + _lanczos_den_coeffs[i]
     return num / den



More information about the Pypy-commit mailing list