[pypy-commit] pypy numpypy-complex2: shortcut c_pow for complex if both imag are 0. (still need more tests)

mattip noreply at buildbot.pypy.org
Fri Sep 21 14:55:38 CEST 2012


Author: mattip <matti.picus at gmail.com>
Branch: numpypy-complex2
Changeset: r57450:4755aecbc271
Date: 2012-09-21 15:03 +0300
http://bitbucket.org/pypy/pypy/changeset/4755aecbc271/

Log:	shortcut c_pow for complex if both imag are 0. (still need more
	tests)

diff --git a/pypy/rlib/rcomplex.py b/pypy/rlib/rcomplex.py
--- a/pypy/rlib/rcomplex.py
+++ b/pypy/rlib/rcomplex.py
@@ -67,8 +67,13 @@
 
 def c_pow(x, y):
     (r1, i1), (r2, i2) = x, y
-    if r2 == 0.0 and i2 == 0.0:
+    if i1 == 0 and i2 == 0:
+        rr = pow(r1, r2)
+        ir = 0.
+    elif r2 == 0.0 and i2 == 0.0:
         rr, ir = 1, 0
+    elif r1 == 1.0 and i1 == 0.0:
+        rr, ir = (1.0, 0.0)
     elif r1 == 0.0 and i1 == 0.0:
         if i2 != 0.0 or r2 < 0.0:
             raise ZeroDivisionError
diff --git a/pypy/rlib/test/rcomplex_testcases2.txt b/pypy/rlib/test/rcomplex_testcases2.txt
--- a/pypy/rlib/test/rcomplex_testcases2.txt
+++ b/pypy/rlib/test/rcomplex_testcases2.txt
@@ -71,17 +71,18 @@
 pow0010 pow 1.0 0.0 nan 0.0 -> 1.0 0.0
 pow0011 pow 1.0 0.0 0.0 nan -> 1.0 0.0
 pow0012 pow 1.0 0.0 nan nan -> 1.0 0.0
+-- if x is 0.0, result is +0 or -0
+pow0020 pow 0.0 0.0  1.0 0.0 -> 0.0 0.0
 -- if y is 0.0, result is 1.0
-pow0020 pow 0.0 0.0  1.0 0.0 -> 1.0 0.0
-pow0021 pow 2.0 0.0  1.0 0.0 -> 1.0 0.0
-pow0022 pow 0.0 2.0  1.0 0.0 -> 1.0 0.0
-pow0023 pow 2.0 2.0  1.0 0.0 -> 1.0 0.0
-pow0024 pow inf 0.0  1.0 0.0 -> 1.0 0.0
-pow0025 pow 0.0 inf  1.0 0.0 -> 1.0 0.0
-pow0026 pow inf inf  1.0 0.0 -> 1.0 0.0
-pow0027 pow -inf 0.0 1.0 0.0 -> 1.0 0.0
-pow0028 pow 0.0 -inf 1.0 0.0 -> 1.0 0.0
-pow0029 pow -inf -inf 1.0 0.0 -> 1.0 0.0
-pow0030 pow nan 0.0  1.0 0.0 -> 1.0 0.0
-pow0031 pow 0.0 nan  1.0 0.0 -> 1.0 0.0
-pow0032 pow nan nan  1.0 0.0 -> 1.0 0.0
+pow0021 pow 2.0 0.0  0.0 0.0 -> 1.0 0.0
+pow0022 pow 0.0 2.0  0.0 0.0 -> 1.0 0.0
+pow0023 pow 2.0 2.0  0.0 0.0 -> 1.0 0.0
+pow0024 pow inf 0.0  0.0 0.0 -> 1.0 0.0
+pow0025 pow 0.0 inf  0.0 0.0 -> 1.0 0.0
+pow0026 pow inf inf  0.0 0.0 -> 1.0 0.0
+pow0027 pow -inf 0.0 0.0 0.0 -> 1.0 0.0
+pow0028 pow 0.0 -inf 0.0 0.0 -> 1.0 0.0
+pow0029 pow -inf -inf 0.0 0.0 -> 1.0 0.0
+pow0030 pow nan 0.0  0.0 0.0 -> 1.0 0.0
+pow0031 pow 0.0 nan  0.0 0.0 -> 1.0 0.0
+pow0032 pow nan nan  0.0 0.0 -> 1.0 0.0


More information about the pypy-commit mailing list