Stop multiplying by zero from throwing when the zero is on the right [patch] - #110
Merged
Merged
Conversation
…[patch] LowestSignificantDigits read the left count after overwriting it, so when both operands were -1, 0 or 1 the result depended on operand order and a zero on the right produced a count of 0, which ToSignificantNumber rejects. Capture both unlimited-precision flags first, and return 1 when both operands are exact, since any product, quotient or remainder of -1, 0 and 1 is exact at one digit. This also makes CompareTo antisymmetric for those values (1.CompareTo(0) was 0). Fixes #108 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QBrEwaLGeo2SvjVK3AnLrp
This was referenced Sep 28, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QBrEwaLGeo2SvjVK3AnLrp
|
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.



Fixes #108
What was wrong
LowestSignificantDigits, used byMultiply,Divide,ModandCompareTo, read the left count after it had already overwritten it. When both operands were -1, 0 or 1, the result depended on operand order. A zero on the right gave a count of 0, andToSignificantNumber(0)throws. So1 * 0,0 * 0anddefault * defaultthrew, while0 * 1returned 0.Fix
The same change makes
CompareToantisymmetric for these values. Before,1.CompareTo(0)returned 0 while0.CompareTo(1)returned -1.Tests
The new
SignificantNumberExactOperandTestscovers:Square(SignificantNumber.Zero)through generic matha * b == b * a == exactfor every pair drawn from {-1, 0, 1}Divide/ModresultsCompareTosign for every pairWith the fix reverted, 7 of these fail. With it, all 120 tests pass.
🤖 Generated with Claude Code
https://claude.ai/code/session_01QBrEwaLGeo2SvjVK3AnLrp
Generated by Claude Code