Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22259 from ganesh-k13/doc_21506_div_overflow
DOC: Better report integer division overflow (#21506)
- Loading branch information
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Better reporting of integer division overflow | ||
--------------------------------------------- | ||
|
||
Integer division overflow of scalars and arrays used to provide a ``RuntimeWarning`` | ||
and the return value was undefined leading to crashes at rare occasions:: | ||
|
||
>>> np.array([np.iinfo(np.int32).min]*10, dtype=np.int32) // np.int32(-1) | ||
<stdin>:1: RuntimeWarning: divide by zero encountered in floor_divide | ||
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int32) | ||
|
||
Integer division overflow now returns the input dtype's minimum value and raise the | ||
following ``RuntimeWarning``:: | ||
|
||
>>> np.array([np.iinfo(np.int32).min]*10, dtype=np.int32) // np.int32(-1) | ||
<stdin>:1: RuntimeWarning: overflow encountered in floor_divide | ||
array([-2147483648, -2147483648, -2147483648, -2147483648, -2147483648, | ||
-2147483648, -2147483648, -2147483648, -2147483648, -2147483648], | ||
dtype=int32) |