Author: Benjamin Peterson <benja...@python.org> Branch: Changeset: r45093:0ce179451a54 Date: 2011-06-23 14:21 -0500 http://bitbucket.org/pypy/pypy/changeset/0ce179451a54/
Log: move factorial to app level diff --git a/pypy/module/math/__init__.py b/pypy/module/math/__init__.py --- a/pypy/module/math/__init__.py +++ b/pypy/module/math/__init__.py @@ -4,6 +4,7 @@ class Module(MixedModule): appleveldefs = { + 'factorial' : 'app_math.factorial' } interpleveldefs = { @@ -40,7 +41,6 @@ 'isnan' : 'interp_math.isnan', 'trunc' : 'interp_math.trunc', 'fsum' : 'interp_math.fsum', - 'factorial' : 'interp_math.factorial', 'asinh' : 'interp_math.asinh', 'acosh' : 'interp_math.acosh', 'atanh' : 'interp_math.atanh', diff --git a/pypy/module/math/app_math.py b/pypy/module/math/app_math.py new file mode 100644 --- /dev/null +++ b/pypy/module/math/app_math.py @@ -0,0 +1,13 @@ +def factorial(x): + """Find x!.""" + if isinstance(x, float): + fl = int(x) + if fl != x: + raise ValueError("float arguments must be integral") + x = fl + if x < 0: + raise ValueError("x must be >= 0") + res = 1 + for i in range(1, x + 1): + res *= i + return res diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py --- a/pypy/module/math/interp_math.py +++ b/pypy/module/math/interp_math.py @@ -373,22 +373,6 @@ hi = v return space.wrap(hi) -def factorial(space, w_x): - """Find x!.""" - if space.isinstance_w(w_x, space.w_float): - fl = space.float_w(w_x) - if math.floor(fl) != fl: - raise OperationError(space.w_ValueError, - space.wrap("float arguments must be integral")) - w_x = space.long(w_x) - x = space.int_w(w_x) - if x < 0: - raise OperationError(space.w_ValueError, space.wrap("x must be >= 0")) - w_res = space.wrap(1) - for i in range(1, x + 1): - w_res = space.mul(w_res, space.wrap(i)) - return w_res - def log1p(space, w_x): """Find log(x + 1).""" return math1(space, rfloat.log1p, w_x) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit