Author: Brian Kearns <bdkea...@gmail.com>
Branch: 
Changeset: r67939:9ed2dd8cdfe8
Date: 2013-11-10 20:44 -0500
http://bitbucket.org/pypy/pypy/changeset/9ed2dd8cdfe8/

Log:    fix a complex scalar str_format case

diff --git a/pypy/module/micronumpy/test/test_scalar.py 
b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -92,10 +92,15 @@
 
     def test_complex_str_format(self):
         import numpy as np
-        assert str(np.complex128(complex(1, float('nan')))) == '(1+nan*j)'
-        assert str(np.complex128(complex(1, float('-nan')))) == '(1+nan*j)'
-        assert str(np.complex128(complex(1, float('inf')))) == '(1+inf*j)'
-        assert str(np.complex128(complex(1, float('-inf')))) == '(1-inf*j)'
+        for t in [np.complex64, np.complex128]:
+            assert str(t(complex(1, float('nan')))) == '(1+nan*j)'
+            assert str(t(complex(1, float('-nan')))) == '(1+nan*j)'
+            assert str(t(complex(1, float('inf')))) == '(1+inf*j)'
+            assert str(t(complex(1, float('-inf')))) == '(1-inf*j)'
+            for x in [0, 1, -1]:
+                assert str(t(complex(x))) == str(complex(x))
+                assert str(t(x*1j)) == str(complex(x*1j))
+                assert str(t(x + x*1j)) == str(complex(x + x*1j))
 
     def test_complex_zero_division(self):
         import numpy as np
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1030,7 +1030,7 @@
         imag_str += 'j'
 
         # (0+2j) => 2j
-        if real == 0:
+        if real == 0 and math.copysign(1, real) == 1:
             return imag_str
 
         real_str = str_format(real)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to