Skip to content

BUG: Division overflow tracking issue #21506

@ganesh-k13

Description

@ganesh-k13

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:

ToDo

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions