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
PreciseNumber.Radix returns 2, but the type is base 10 (significand × 10^exponent) #116
INumberBase<T>.Radix is defined as "the radix, or base, for the type". PreciseNumber stores Significand × 10^Exponent and does all its digit work (significant digits, rounding, Round(decimalDigits), the rendered form) in base 10. The BCL's other decimal type, decimal, reports Radix == 10.
PreciseNumber.Test/PreciseNumberTests.cs:906-908 (TestRadix) asserts 2, so the test pins the wrong value. It does not document a design decision.
Why it matters
Generic math code uses T.Radix to reason about representation. Examples include computing ulps, deciding how many digits a value can hold exactly, choosing a digit-by-digit algorithm, or checking whether scaling by the radix is exact. With Radix == 2, such code treats PreciseNumber as binary. For example, it would conclude that x * 10 is not an exact scale, while x * 2 is.
Suggested fix
Return 10, and rename the constant (e.g. DecimalRadix).
Update TestRadix to expect 10.
This is a behaviour change to a public static, so note it in the changelog.
Activity