Skip to content

Fraction.add and subtract return the reduced form when an operand is zero - #1787

Merged
garydgregory merged 1 commit into
apache:masterfrom
lenamonj:fraction-zero-reduce
Sep 9, 2026
Merged

Fraction.add and subtract return the reduced form when an operand is zero#1787
garydgregory merged 1 commit into
apache:masterfrom
lenamonj:fraction-zero-reduce

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #1784. The zero shortcuts in addSub returned the other operand as constructed, so ZERO.add(2/4) was 2/4 against the Javadoc's reduced-form promise, and ZERO.subtract(Integer.MIN_VALUE/2) threw although the reduced result 1073741824/1 fits, both noted in the #1784 review. The shortcuts now reduce before returning or negating. The new test covers both operations with zero on either side and the Integer.MIN_VALUE boundary; it fails on master and passes with the change. Default mvn goal green with -Ddoclint=all.

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? Claude (Anthropic) wrote the fix and the test from the Fix Fraction.add and subtract for operands not in lowest terms #1784 review and ran the reproduction and the default Maven goal on a fresh clone; I directed and reviewed the work.
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.

@garydgregory
garydgregory merged commit 284be5d into apache:master Sep 9, 2026
23 of 24 checks passed
@garydgregory

Copy link
Copy Markdown
Member

@lenamonj Looks good, thank you, merged 🚀

@lenamonj
lenamonj deleted the fraction-zero-reduce branch September 9, 2026 06:41
garydgregory added a commit that referenced this pull request Sep 9, 2026
zero (#1787).

- Test both operands being unreduced zeros
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