summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/npymath/npy_math_internal.h.src14
-rw-r--r--numpy/core/tests/test_umath.py4
2 files changed, 17 insertions, 1 deletions
diff --git a/numpy/core/src/npymath/npy_math_internal.h.src b/numpy/core/src/npymath/npy_math_internal.h.src
index c22ac5186..14892562c 100644
--- a/numpy/core/src/npymath/npy_math_internal.h.src
+++ b/numpy/core/src/npymath/npy_math_internal.h.src
@@ -423,6 +423,13 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
NPY_INPLACE @type@
npy_@kind@@c@(@type@ x, @type@ y)
{
+ int are_inputs_inf = (npy_isinf(x) && npy_isinf(y));
+
+ if (are_inputs_inf || !y) {
+ if (!npy_isnan(x)) {
+ npy_set_floatstatus_invalid();
+ }
+ }
return (@type@) npy_@kind@((double)x, (double) y);
}
#endif
@@ -508,6 +515,13 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
NPY_INPLACE @type@
npy_@kind@@c@(@type@ x, @type@ y)
{
+ int are_inputs_inf = (npy_isinf(x) && npy_isinf(y));
+
+ if (are_inputs_inf || !y) {
+ if (!npy_isnan(x)) {
+ npy_set_floatstatus_invalid();
+ }
+ }
return @kind@@c@(x, y);
}
#endif
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 6d97c640f..64357974b 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -461,7 +461,8 @@ class TestDivision:
with np.errstate(invalid='raise'):
assert_no_warnings(FloatingPointError, np.floor_divide, fnan, fone)
assert_no_warnings(FloatingPointError, np.floor_divide, fone, fnan)
- assert_raises(FloatingPointError, np.floor_divide, fnan, fzer)
+ assert_no_warnings(FloatingPointError, np.floor_divide, fnan, fzer)
+ assert_no_warnings(FloatingPointError, np.floor_divide, fzer, fnan)
@pytest.mark.parametrize('dtype', np.typecodes['Float'])
def test_floor_division_corner_cases(self, dtype):
@@ -590,6 +591,7 @@ class TestRemainder:
with np.errstate(invalid='raise'):
assert_raises(FloatingPointError, fn, fone, fzero)
assert_no_warnings(FloatingPointError, fn, fnan, fzero)
+ assert_no_warnings(FloatingPointError, fn, fzero, fnan)
assert_no_warnings(FloatingPointError, fn, fone, fnan)
assert_no_warnings(FloatingPointError, fn, fnan, fone)