Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8afe118

Browse files
authored
BUG: avoid negating INT_MIN in PyArray_Round implementation (numpy#30071)
1 parent 9e42499 commit 8afe118

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

numpy/_core/src/multiarray/calculation.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,15 @@ PyArray_Round(PyArrayObject *a, int decimals, PyArrayObject *out)
652652
else {
653653
op1 = n_ops.true_divide;
654654
op2 = n_ops.multiply;
655-
decimals = -decimals;
655+
if (decimals == INT_MIN) {
656+
// not technically correct but it doesn't matter because no one in
657+
// this millenium is using floating point numbers with enough
658+
// accuracy for this to matter
659+
decimals = INT_MAX;
660+
}
661+
else {
662+
decimals = -decimals;
663+
}
656664
}
657665
if (!out) {
658666
if (PyArray_ISINTEGER(a)) {

0 commit comments

Comments
 (0)