Skip to content

Conversation

@charris
Copy link
Member

@charris charris commented Oct 10, 2025

Backport of #29893.

Summary of changes

  • Explicitly handle the case INT_MIN % -1 in scalar tail loops for fmod and remainder kernels.

  • Set the result to 0 to avoid undefined behavior and align with NumPy/Python expected semantics.

  • Ensures portable, correct behavior across all architectures, including POWER10 (ppc64le).

Background / Motivation
On POWER10 systems, several SIMD tests were failing due to integer overflow when evaluating INT_MIN % -1, an undefined operation in C.
Python defines this operation to return 0, and this change updates NumPy’s low-level implementation to match that behavior.

Issue Reference
Fixes: #29731 — [POWER10] SIMD tests failing with integer overflow (previously skipped)

cc: @seiko2plus @rgommers @ghatwala

@charris charris added this to the 2.3.4 release milestone Oct 10, 2025
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Oct 10, 2025
…#29893)

* BUG: Fix INT_MIN % -1 to return 0 for all signed integer types

- Explicitly check for INT_MIN % -1 in scalar tail loops for fmod and remainder kernels.
- Set result to 0 to avoid undefined behavior and match NumPy/Python expectations.
- Ensures correct, portable behavior on all platforms (e.g., PPC64LE).

* Apply suggestion from @seberg

---------

Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
@charris charris merged commit fbe8f1b into numpy:maintenance/2.3.x Oct 10, 2025
74 checks passed
@charris charris deleted the backport-29893 branch October 10, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants