[pypy-commit] pypy numpypy-complex2: flesh out rcomplex

mattip noreply at buildbot.pypy.org
Mon Aug 27 23:13:48 CEST 2012


Author: mattip <matti.picus at gmail.com>
Branch: numpypy-complex2
Changeset: r56894:407a51b72c9d
Date: 2012-08-27 20:23 +0300
http://bitbucket.org/pypy/pypy/changeset/407a51b72c9d/

Log:	flesh out rcomplex

diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -855,8 +855,8 @@
 
 
     def test_complex(self):
-        from _numpypy import (array, complex128, complex64, add,
-            subtract as sub, multiply, divide, negative, conjugate,  abs, fmod)
+        from _numpypy import (complex128, complex64, add,
+            subtract as sub, multiply, divide, negative, abs, fmod)
         from _numpypy import (equal, not_equal, greater, greater_equal, less,
                 less_equal)
 
@@ -912,6 +912,9 @@
             assert abs(c2) == 5
             
             raises (TypeError, fmod, c0, 3) 
+            inf_c = complex_(complex(float('inf'), 0.))
+            assert repr(abs(inf_c)) == 'inf'
+            assert repr(abs(n)) == 'nan'
 
 
     def test_complex_math(self):
diff --git a/pypy/rlib/rcomplex.py b/pypy/rlib/rcomplex.py
--- a/pypy/rlib/rcomplex.py
+++ b/pypy/rlib/rcomplex.py
@@ -1,6 +1,9 @@
 import math
-from math import copysign
-from pypy.module.cmath.special_value import isfinite
+from math import copysign, fabs
+from pypy.module.cmath.special_value import (isfinite, sqrt_special_values,
+        cosh_special_values, sinh_special_values, exp_special_values,
+        special_type, )
+from pypy.rlib.rfloat import INFINITE as INF, NAN, isinf, DBL_MIN
 
 #binary
 
@@ -74,7 +77,7 @@
     return (-r, -i)
 
 
-def c_sqrt(r, i):
+def c_sqrt(x, y):
     '''
     Method: use symmetries to reduce to the case when x = z.real and y
     = z.imag are nonnegative.  Then the real part of the result is
@@ -101,14 +104,14 @@
     are normal.
     '''
 
-    if not isfinite(r) or not isfinite(i):
-        return sqrt_special_values[special_type(r)][special_type(i)]
+    if not isfinite(x) or not isfinite(y):
+        return sqrt_special_values[special_type(x)][special_type(y)]
 
-    if r == 0. and i == 0.:
+    if x == 0. and y == 0.:
         return (0., y)
 
-    ar = fabs(r)
-    ai = fabs(i)
+    ar = fabs(x)
+    ai = fabs(y)
 
     if ar < DBL_MIN and ai < DBL_MIN and (ar > 0. or ai > 0.):
         # here we catch cases where hypot(ar, ai) is subnormal
@@ -509,9 +512,9 @@
     if not isfinite(r) or not isfinite(i):
         # C99 rules: if either the real or the imaginary part is an
         # infinity, return infinity, even if the other part is a NaN.
-        if isinf(r):
+        if not isfinite(r):
             return INF
-        if isinf(i):
+        if not isfinite(i):
             return INF
 
         # either the real or imaginary part is a NaN,


More information about the pypy-commit mailing list