You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ReduceSignificance(0) returns 10 and ReduceSignificance(-1) returns 0 instead of rejecting the argument #126
The public ReduceSignificance(int significantDigits) (PreciseNumber/PreciseNumber.cs:860-876) doesn't validate its argument. Every other precision parameter in the library throws ArgumentOutOfRangeException for values below 1: Divide, RootN, Sqrt, Sin, and ConstantTo for PiTo and friends. ReduceSignificance instead silently returns a meaningless value:
The method also computes Exponent + significantDifference without checked, whereas the rest of the file guards exponent arithmetic with checked (see #120's exponent-overflow fix).
Why it matters
When a caller computes the precision, for example as digits - lost and it reaches 0 or goes negative, they get a wrong number (5 → 10) and no error. That is the worst outcome for a library whose purpose is precision.
Suggested fix
Throw ArgumentOutOfRangeException when significantDigits < 1, the same way the other precision parameters do.
Priority: Medium. It returns a silently wrong value (5 → 10) instead of an error, which is serious in a precision library. It only happens on invalid input (a precision below 1), though, and the fix is a small guard.
Area / suggested assignee:ReduceSignificance in PreciseNumber/PreciseNumber.cs. Owner: @matt-edmondson
Next step: throw ArgumentOutOfRangeException for significantDigits < 1, make the exponent addition checked, and add tests for 0 and for a negative value.
Activity
matt-edmondson commentedon Sep 27, 2026
Triage
ReduceSignificanceinPreciseNumber/PreciseNumber.cs. Owner: @matt-edmondsoncheckedexponent pattern from Throw OverflowException when Multiply or Divide leaves the int exponent range #120. No open PR covers it.ArgumentOutOfRangeExceptionforsignificantDigits < 1, make the exponent additionchecked, and add tests for 0 and for a negative value.Generated by Claude Code