Round sums and differences to tens and hundreds when an operand is that coarse - #119
Merged
Merged
Conversation
…at coarse [patch] CountDecimalDigits clamped a positive exponent to 0, so an operand whose least significant digit is left of the decimal point was treated as exact to the units, and 1.2E3 + 34 gave 1234. Report that place as a negative decimal count instead, so Add, Subtract and Mod round to it: 1.2E3 + 34 is now 1.2E3, matching the two significant figures Multiply already honours. Fixes #107 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VeSBKr7Q99CTQ5BUJMKEct
|
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 #107
What
CountDecimalDigitsclamped a positive exponent to 0, so an operand whose least significant digit sits left of the decimal point was treated as exact to the units. It now returns-Exponent, so tens are -1, hundreds -2, and so on.Add,SubtractandModthen round to that place. The installed ktsu.PreciseNumber 2.6.4 already rounds to negative digit counts, so no package bump was needed. Operands of exactly -1, 0 or 1 are still ignored as exact.1.2E3 + 341.2E3 - 341200 + 341234 + 5.6Tests
SignificantNumberAdditionPlaceTestscovers the three cases in the issue, the reversed operand order, a round-up case (1.2E3 + 56 = 1.3E3),1.2E3 + 1(an exact operand is ignored), and the units-preserving1234 + 5.6/1234 - 5.6.250 % 70 = 40, are unaffected.🤖 Generated with Claude Code
https://claude.ai/code/session_01VeSBKr7Q99CTQ5BUJMKEct
Generated by Claude Code