🌐 AI搜索 & 代理 主页
Skip to content

Commit fbe8f1b

Browse files
authored
Merge pull request #29921 from charris/backport-29893
BUG: Fix INT_MIN % -1 to return 0 for all signed integer types (#29893)
2 parents 126d15c + 8a12fbc commit fbe8f1b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

numpy/_core/src/umath/loops_modulo.dispatch.c.src

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,16 @@ vsx4_simd_@func@_by_scalar_contig_@sfx@(char **args, npy_intp len)
490490
#else /* fmod and remainder */
491491
for (; len > 0; --len, ++src1, ++dst1) {
492492
const npyv_lanetype_@sfx@ a = *src1;
493-
*dst1 = a % scalar;
493+
if (NPY_UNLIKELY(a == NPY_MIN_INT@len@ && scalar == -1)) {
494+
*dst1 = 0;
495+
} else {
496+
*dst1 = a % scalar;
494497
#if @id@ == 1 /* remainder */
495-
if (!((a > 0) == (scalar > 0) || *dst1 == 0)) {
496-
*dst1 += scalar;
497-
}
498+
if (!((a > 0) == (scalar > 0) || *dst1 == 0)) {
499+
*dst1 += scalar;
500+
}
498501
#endif
502+
}
499503
}
500504
#endif
501505
npyv_cleanup();

0 commit comments

Comments
 (0)