Registry Mirror
Skip to content

Conversation

@LemonCondor

Copy link
Copy Markdown
Contributor

Rationale for this change

compute.Divide with overflow checking on (the default, ArithmeticOptions{}) returns the minimum value for min / -1 on signed integers. For example, int32 -2147483648 / -1 returns -2147483648 with 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_checked returns "overflow" for this case.

What changes are included in this PR?

The checked integer division kernel now returns the existing overflow error 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. TestDivideOverflow in BinaryIntegralArithmeticSuite covers 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/compute passes on linux/arm64.

Are there any user-facing changes?

Yes. Checked divide now returns an error for signed min / -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.

Checked integer division returned the minimum value for min / -1
instead of an overflow error, unlike the other checked kernels and
Arrow C++.

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zeroshade
zeroshade merged commit 7addfc7 into apache:main Nov 25, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants