Conversation
Checked integer division returned the minimum value for min / -1 instead of an overflow error, unlike the other checked kernels and Arrow C++.
zeroshade
approved these changes
Nov 25, 2026
zeroshade
left a comment
Member
There was a problem hiding this comment.
Thanks! Checked divide now reports overflow for signed min / -1 like the other checked kernels and Arrow C++, and unchecked division still wraps. Verified locally with array and scalar inputs. Optional nit: the local min shadows the builtin; minVal would avoid lint noise.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
compute.Dividewith overflow checking on (the default,ArithmeticOptions{}) returns the minimum value formin / -1on signed integers. For example, int32-2147483648 / -1returns-2147483648with no error. The true result does not fit in the type, so the checked kernel should report an overflow. The other checked kernels (add,subtract,multiply,negate,abs) already do, and Arrow C++divide_checkedreturns "overflow" for this case.What changes are included in this PR?
The checked integer division kernel now returns the existing
overflowerror when a signed dividend is the type's minimum and the divisor is -1. Unchecked division keeps Go's wrapping result.Are these changes tested?
Yes.
TestDivideOverflowinBinaryIntegralArithmeticSuitecovers int8, int16, int32 and int64 with overflow checks on (error expected) and off (wrapped value expected). It fails on main: "An error is expected but got nil". With the change,go test -run 'TestBinaryArithmetic$' ./arrow/computepasses on linux/arm64.Are there any user-facing changes?
Yes. Checked
dividenow returns an error for signedmin / -1, where it used to return a wrong value silently.An AI assistant was used to find and write this change. The added test fails without the fix and passes with it.