Skip to content

Round sums and differences to tens and hundreds when an operand is that coarse - #119

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/round-sums-to-tens
Sep 29, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/round-sums-to-tens

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #107

What

CountDecimalDigits clamped 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, Subtract and Mod then 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.

Expression Before After
1.2E3 + 34 1234 1.2E3
1.2E3 - 34 1166 1.2E3
1200 + 34 1234 1.2E3
1234 + 5.6 1240 1240 (units kept)

Tests

  • New SignificantNumberAdditionPlaceTests covers 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-preserving 1234 + 5.6 / 1234 - 5.6.
  • Without the fix, 8 of those rows fail. With it, the full suite passes: 167/167. The existing Mod tests, such as 250 % 70 = 40, are unaffected.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VeSBKr7Q99CTQ5BUJMKEct


Generated by Claude Code

…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
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 2896634 into main Sep 29, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the claude/round-sums-to-tens branch September 29, 2026 21:51
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.

Add/Subtract never round to tens or hundreds: 1.2E3 + 34 = 1234 instead of 1.2E3

2 participants