summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/umath/scalarmath.c.src5
-rw-r--r--numpy/core/tests/test_scalarmath.py2
2 files changed, 6 insertions, 1 deletions
diff --git a/numpy/core/src/umath/scalarmath.c.src b/numpy/core/src/umath/scalarmath.c.src
index 3936efbdf..a425faf3c 100644
--- a/numpy/core/src/umath/scalarmath.c.src
+++ b/numpy/core/src/umath/scalarmath.c.src
@@ -523,9 +523,12 @@ static NPY_INLINE int
{
#if @uns@
*out = -a;
+ if (a == 0) {
+ return 0;
+ }
return NPY_FPE_OVERFLOW;
#elif @int@
- if(a == NPY_MIN_@NAME@){
+ if (a == NPY_MIN_@NAME@){
*out = a;
return NPY_FPE_OVERFLOW;
}
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
index a358d4f5f..e3dc52c48 100644
--- a/numpy/core/tests/test_scalarmath.py
+++ b/numpy/core/tests/test_scalarmath.py
@@ -923,6 +923,8 @@ def test_scalar_unsigned_integer_overflow(dtype):
with pytest.warns(RuntimeWarning, match="overflow encountered"):
-val
+ zero = np.dtype(dtype).type(0)
+ -zero # does not warn
@pytest.mark.parametrize("dtype", np.typecodes["AllInteger"])
@pytest.mark.parametrize("operation", [