Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r51596:1ebae6842fb2
Date: 2012-01-21 11:33 -0600
http://bitbucket.org/pypy/pypy/changeset/1ebae6842fb2/
Log: merged upstream
diff --git a/pypy/objspace/std/complexobject.py
b/pypy/objspace/std/complexobject.py
--- a/pypy/objspace/std/complexobject.py
+++ b/pypy/objspace/std/complexobject.py
@@ -8,6 +8,7 @@
from pypy.rlib.rbigint import rbigint
from pypy.rlib.rfloat import (
formatd, DTSF_STR_PRECISION, isinf, isnan, copysign)
+from pypy.rlib import jit
import math
@@ -129,10 +130,10 @@
ir = len * math.sin(phase)
return W_ComplexObject(rr, ir)
- def pow_int(self, n):
- if n > 100 or n < -100:
- return self.pow(W_ComplexObject(1.0 * n, 0.0))
- elif n > 0:
+ def pow_small_int(self, n):
+ if n >= 0:
+ if jit.isconstant(n) and n == 2:
+ return self.mul(self)
return self.pow_positive_int(n)
else:
return w_one.div(self.pow_positive_int(-n))
@@ -217,10 +218,10 @@
def pow__Complex_Complex_ANY(space, w_complex, w_exponent, thirdArg):
if not space.is_w(thirdArg, space.w_None):
raise OperationError(space.w_ValueError, space.wrap('complex modulo'))
- int_exponent = int(w_exponent.realval)
try:
- if w_exponent.imagval == 0.0 and w_exponent.realval == int_exponent:
- w_p = w_complex.pow_int(int_exponent)
+ r = w_exponent.realval
+ if w_exponent.imagval == 0.0 and -100.0 <= r <= 100.0 and r == int(r):
+ w_p = w_complex.pow_small_int(int(r))
else:
w_p = w_complex.pow(w_exponent)
except ZeroDivisionError:
diff --git a/pypy/objspace/std/test/test_complexobject.py
b/pypy/objspace/std/test/test_complexobject.py
--- a/pypy/objspace/std/test/test_complexobject.py
+++ b/pypy/objspace/std/test/test_complexobject.py
@@ -71,7 +71,7 @@
assert _powu((0.0,1.0),2) == (-1.0,0.0)
def _powi((r1, i1), n):
- w_res = W_ComplexObject(r1, i1).pow_int(n)
+ w_res = W_ComplexObject(r1, i1).pow_small_int(n)
return w_res.realval, w_res.imagval
assert _powi((0.0,2.0),0) == (1.0,0.0)
assert _powi((0.0,0.0),2) == (0.0,0.0)
@@ -213,6 +213,7 @@
assert a ** 105 == a ** 105
assert a ** -105 == a ** -105
assert a ** -30 == a ** -30
+ assert a ** 2 == a * a
assert 0.0j ** 0 == 1
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit