# Commits

committed 1ebae68 Merge

merged upstream

• Participants
• Parent commits fe8a844, 76e23aa
• Branches default

# File pypy/objspace/std/complexobject.py

` 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`
` `
`             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))`
` 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:`

# File pypy/objspace/std/test/test_complexobject.py

`         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)`
`         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`
` `