diff options
| author | Matti Picus <matti.picus@gmail.com> | 2022-10-31 14:08:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-31 14:08:04 +0100 |
| commit | 53beb7b0244425111196085a1342c0787b451e76 (patch) | |
| tree | 3334e8786c15c582e9c890feb38da7c8a108afad /numpy | |
| parent | 04ddeb3e159a0f075f4d5e9d113b6cfa61d55fdb (diff) | |
| parent | 27d876ffaa179cf38b7d20b8f245a9e637bd0de8 (diff) | |
| download | numpy-53beb7b0244425111196085a1342c0787b451e76.tar.gz | |
Merge pull request #22478 from seberg/integer-scalar-warnings
BUG: -unsigned_int(0) no overflow warning
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/src/umath/scalarmath.c.src | 10 | ||||
| -rw-r--r-- | numpy/core/tests/test_scalarmath.py | 2 |
2 files changed, 10 insertions, 2 deletions
diff --git a/numpy/core/src/umath/scalarmath.c.src b/numpy/core/src/umath/scalarmath.c.src index 3936efbdf..7c63ac0f1 100644 --- a/numpy/core/src/umath/scalarmath.c.src +++ b/numpy/core/src/umath/scalarmath.c.src @@ -523,15 +523,21 @@ 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; } -#endif *out = -a; return 0; +#else /* floats */ + *out = -a; + return 0; +#endif } /**end repeat**/ 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", [ |
