summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/umathmodule.c.src10
-rw-r--r--numpy/core/tests/test_regression.py9
2 files changed, 16 insertions, 3 deletions
diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src
index 9096cdbf1..760d6d57e 100644
--- a/numpy/core/src/umathmodule.c.src
+++ b/numpy/core/src/umathmodule.c.src
@@ -1683,9 +1683,15 @@ static void
#define BOOL_negative BOOL_logical_not
-#define _SIGN1(x) ((x) > 0 ? 1 : ((x) < 0 ? -1 : 0))
+#define _SIGN1(x) (isnan((x)) ? NAN : ((x) > 0 ? 1 : ((x) < 0 ? -1 : 0)) )
#define _SIGN2(x) ((x) == 0 ? 0 : 1)
-#define _SIGNC(x) (((x).real > 0) ? 1 : ((x).real < 0 ? -1 : ((x).imag > 0 ? 1 : ((x).imag < 0) ? -1 : 0)))
+#define _SIGNC(x) (isnan((x.real)) ? NAN : \
+ isnan((x.imag)) ? NAN : \
+ ((x).real > 0) ? 1 : \
+ ((x).real < 0 ? -1 : \
+ ((x).imag > 0 ? 1 : \
+ ((x).imag < 0) ? -1 : 0)))
+
/**begin repeat
#TYPE=BYTE,SHORT,INT,LONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE,UBYTE,USHORT,UINT,ULONG,ULONGLONG#
#typ=byte,short,int,long,longlong,float,double,longdouble,ubyte,ushort,uint,ulong,ulonglong#
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 084307b43..6abb28c3e 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1124,7 +1124,7 @@ class TestRegression(TestCase):
assert dat.T.info == 'jubba'
assert dat.var(1).info == 'jubba'
assert dat.view(TestArray).info == 'jubba'
-
+
def test_recarray_tolist(self, level=rlevel):
"""Ticket #793, changeset r5215
"""
@@ -1163,6 +1163,13 @@ class TestRegression(TestCase):
x = np.array([('a',u'b')], dtype=t)
assert_equal(str(x), "[('a', u'b')]", err_msg=msg)
+ def check_sign_for_complex_nan(self, level=rlevel):
+ """Ticket 794."""
+ C = np.array([-np.inf, -2+1j, 0, 2-1j, np.inf, np.nan])
+ have = np.sign(C)
+ want = np.array([-1+0j, -1+0j, 0+0j, 1+0j, 1+0j, np.nan+0j])
+ assert_equal(have, want)
+
if __name__ == "__main__":
run_module_suite()