THEpranavsomalraju opened a new pull request, #1719: URL: https://github.com/apache/arrow-go/pull/1719
### Rationale for this change Fixes #1718. The checked `add` and `subtract` kernels used the unsigned carry formula for signed types as well, shifted by one bit less. That catches a result above the maximum but not one below the minimum, so `add(MinInt32, -1)` returned `MaxInt32` with no error. ### What changes are included in this PR? For signed types, `OpAddChecked` and `OpSubChecked` now use the sign-based check: add overflows when both operands have the same sign and the result has the other one; subtract overflows when the operands have different signs and the result's sign differs from the left operand's. The unsigned path is unchanged. ### Are these changes tested? Yes. `TestAdd` and `TestSub` in the binary arithmetic suite now check `min + (-1)`, `min + min`, `max - (-1)` and `0 - min` for every signed type, plus the boundary cases that must not error (`min + max`, `min - min`, `-1 - max`). The new overflow cases fail on main for int8, int16, int32 and int64. I also checked every int8 pair for both operations against exact arithmetic. ### Are there any user-facing changes? Checked add and subtract now return an overflow error for results below the minimum of a signed type instead of a wrapped value. An AI assistant was used to help find this bug and write the change. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
