Skip to content

Regression since #119: integer sums stall at round numbers. 10 + 2 == 10, 100 + 25 == 100, 20 - 3 == 20, and a sum += 2 loop stops at 10 #124

Open

Description

@matt-edmondson

What's wrong

PreciseNumber normalizes integers by moving trailing zeros into the exponent: 10 becomes 1E1 and 100 becomes 1E2. Since fc66077 (#119, the fix for #107), CountDecimalDigits (SignificantNumber/SignificantNumber.cs:155) returns -value.Exponent without clamping it. As a result, any whole number ending in 0 is treated as known only to the tens or hundreds place, including one that came from int.ToSignificantNumber(). Add and Subtract then round the result to that place through LowestDecimalDigits (line 163 onward).

Failure scenarios

Measured at HEAD a15223e, then against fc66077^ in a worktree:

Expression HEAD Before #119 Expected
10.ToSignificantNumber() + 2.ToSignificantNumber() 10 12 12
100 + 25 100 125 125
20 - 3 20 17 17
default, then += 2 ten times 10 20 20

The last row shows what happens to an ordinary accumulator: once it reaches 10, every later + 2 rounds back to 10, so a running total of integer counts silently stops growing.

Relation to existing issues

Suggested fix

The full fix is the separate precision tracking proposed in #120. Until that lands, one of these:

  • Treat values from integer conversions (int/long/... ToSignificantNumber(), CreateChecked from integer types) as exact to the units place, i.e. clamp CountDecimalDigits to ≥ 0 for them. Only an explicit coarse input, such as Parse("1.2E3"), would then round to tens or hundreds.
  • Or revert the negative decimal places from Round sums and differences to tens and hundreds when an operand is that coarse #119 until precision can be tracked.

Acceptance criteria

Activity

  1. matt-edmondson commented on Oct 5, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions