1. Gil Shwartz
  2. pypy

Commits

mattip  committed 407a51b

flesh out rcomplex

  • Participants
  • Parent commits 4ff04cf
  • Branches numpypy-complex2

Comments (0)

Files changed (2)

File pypy/module/micronumpy/test/test_ufuncs.py

View file
 
 
     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)
 
             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):

File pypy/rlib/rcomplex.py

View file
 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
 
     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
     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
     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,