-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Closed
Description
Describe the issue:
Currently, there are various cases where division leads to overflow/arithmetic exceptions. This happens when the dividend is the smallest possible value of the dtype and the divisor is -1
.
Example:
np.iinfo(np.int32).min % np.int32(-1)
Reproduce the code example:
https://gist.github.com/ganesh-k13/6faaf65d418db13012bd403250cca70a
~ » python3 overflow.py ganesh@ganesh-MS-7B86
1.22.3
Scalars: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 48/48 [00:04<00:00, 10.65it/s]
Arrays: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 48/48 [00:04<00:00, 10.26it/s]
Scalar Failures Observed:
+--------------+------------------+-----------------+
| operation | dividend_dtype | divisor_dtype |
+==============+==================+=================+
| np.remainder | np.int32 | np.int8 |
+--------------+------------------+-----------------+
| np.fmod | np.int32 | np.int8 |
+--------------+------------------+-----------------+
| np.remainder | np.int32 | np.int16 |
+--------------+------------------+-----------------+
| np.fmod | np.int32 | np.int16 |
+--------------+------------------+-----------------+
| np.remainder | np.int32 | np.int32 |
+--------------+------------------+-----------------+
| np.fmod | np.int32 | np.int32 |
+--------------+------------------+-----------------+
| np.remainder | np.int64 | np.int8 |
+--------------+------------------+-----------------+
| np.fmod | np.int64 | np.int8 |
+--------------+------------------+-----------------+
| np.remainder | np.int64 | np.int16 |
+--------------+------------------+-----------------+
| np.fmod | np.int64 | np.int16 |
+--------------+------------------+-----------------+
| np.remainder | np.int64 | np.int32 |
+--------------+------------------+-----------------+
| np.fmod | np.int64 | np.int32 |
+--------------+------------------+-----------------+
| np.remainder | np.int64 | np.int64 |
+--------------+------------------+-----------------+
| np.fmod | np.int64 | np.int64 |
+--------------+------------------+-----------------+
Array Failures Observed:
+--------------+------------------+-----------------+
| operation | dividend_dtype | divisor_dtype |
+==============+==================+=================+
| np.remainder | np.int32 | np.int8 |
+--------------+------------------+-----------------+
| np.fmod | np.int32 | np.int8 |
+--------------+------------------+-----------------+
| np.remainder | np.int32 | np.int16 |
+--------------+------------------+-----------------+
| np.fmod | np.int32 | np.int16 |
+--------------+------------------+-----------------+
| np.remainder | np.int32 | np.int32 |
+--------------+------------------+-----------------+
| np.fmod | np.int32 | np.int32 |
+--------------+------------------+-----------------+
| np.remainder | np.int32 | np.int64 |
+--------------+------------------+-----------------+
| np.fmod | np.int32 | np.int64 |
+--------------+------------------+-----------------+
| np.remainder | np.int64 | np.int8 |
+--------------+------------------+-----------------+
| np.fmod | np.int64 | np.int8 |
+--------------+------------------+-----------------+
| np.remainder | np.int64 | np.int16 |
+--------------+------------------+-----------------+
| np.fmod | np.int64 | np.int16 |
+--------------+------------------+-----------------+
| np.remainder | np.int64 | np.int32 |
+--------------+------------------+-----------------+
| np.fmod | np.int64 | np.int32 |
+--------------+------------------+-----------------+
| np.remainder | np.int64 | np.int64 |
+--------------+------------------+-----------------+
| np.fmod | np.int64 | np.int64 |
+--------------+------------------+-----------------+
Error message:
>>> np.iinfo(np.int64).min % np.int64(-1)
[1] 61277 floating point exception (core dumped) python3
NumPy/Python version information:
1.22.3 3.10.4 (main, Apr 2 2022, 09:04:19) [GCC 11.2.0]
Relate Issues and PRs:
- Int32 (and Int64) Min Value modulo -1 Causes Python to Crash #19246
- BUG: Integer overflow in remainder for Windows #19260
ToDo
- Fix scalar overflow,
- Raise the right warning, xref: f253ac2, related: MAINT,ENH: Rewrite scalar math logic #21188
- Handle SIMD oveflow