Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 852cd10

Browse files
committed
BUG: Fix up some corner cases in npy_cexp
The failing c99 annex G values for cexp were: cexp(Inf, -0) == (NAN, -0) cexp(Inf, Inf) == (+-Inf, NAN) + raises FE_INVALID The first returned (NAN, 0) and the second was correct but failed to raise the invalid floating-point exception.
1 parent e61e74f commit 852cd10

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

numpy/core/src/npymath/npy_math_complex.c.src

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static NPY_INLINE @ctype@ cmuli@c@(@ctype@ a)
172172
} else if (npy_isnan(r)) {
173173
/* r is nan */
174174
if (i == 0) {
175-
ret = npy_cpack@c@(r, 0);
175+
ret = z;
176176
} else {
177177
ret = npy_cpack@c@(r, npy_copysign@c@(NPY_NAN, i));
178178
}
@@ -188,6 +188,7 @@ static NPY_INLINE @ctype@ cmuli@c@(@ctype@ a)
188188
ret = npy_cpack@c@(r * c, r * s);
189189
} else {
190190
/* x = +inf, y = +-inf | nan */
191+
npy_set_floatstatus_invalid();
191192
ret = npy_cpack@c@(r, NPY_NAN);
192193
}
193194
} else {

numpy/core/tests/test_umath_complex.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ def _check_inf_nan(dummy):
123123
# cexp(nan + nani) is nan + nani
124124
yield check, f, np.nan, np.nan, np.nan, np.nan
125125

126+
# cexp(nan +-0) is nan +-0
127+
yield check, f, np.nan, np.PZERO, np.nan, np.PZERO, True
128+
yield check, f, np.nan, np.NZERO, np.nan, np.NZERO, True
129+
130+
126131
@dec.knownfailureif(True, "cexp(nan + 0I) is wrong on most implementations")
127132
def test_special_values2(self):
128133
# XXX: most implementations get it wrong here (including glibc <= 2.10)

0 commit comments

Comments
 (0)