Count trailing zeros in IsEvenInteger and IsOddInteger - #107
Merged
Merged
Conversation
Trailing zeros are stored in the exponent, so 10 is significand 1 at exponent 1. The parity checks read only the significand, so every multiple of 10 whose significand was odd (10, 30, 100, ...) reported as odd. Any positive exponent makes the value a multiple of 10 and therefore even; only a value at exponent 0 takes its parity from the significand. Fixes #104 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018AEYBNCRr6chFLiZDv1MVj
|
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 #104
What was wrong
The sanitizing constructor moves trailing zeros into
Exponent, so10is stored as significand1at exponent1.IsEvenIntegerandIsOddIntegerlooked only atSignificand.IsEven. As a result, 10, 30, 100,7 + 3and every other multiple of 10 with an odd significand reported as odd and not even.Change
This is the fix suggested in the issue:
Both methods now have a remark explaining why the exponent matters.
As the triage note asked, I checked the other
Significand-only predicates.IsPositive,IsNegativeandIsZerodepend only on sign or zero-ness, so trailing zeros don't affect them.IsUnitalready checksExponent == 0.Tests
TestIsEvenIntegerForMultiplesOfTen: 10, 100, 30, -20 and 1,000,000 must be even and not odd.TestParityOfASumWithTrailingZero:7 + 3from the issue.TestIsOddIntegerForOddValues: 1, -3, 21 and 1001 stay odd and not even. This guards against over-correcting.Verification
dotnet test: 395/395 pass.7 + 3test fail.-20passes either way, because its significand (-2) is already even. It stays in as the case the issue asked for.dotnet build PreciseNumber/PreciseNumber.csprojsucceeds with no warnings.🤖 Generated with Claude Code
https://claude.ai/code/session_018AEYBNCRr6chFLiZDv1MVj
Generated by Claude Code