What's wrong
PreciseNumber/PreciseNumber.cs:437-440:
private const int BinaryRadix = 2;
/// <inheritdoc/>
public static int Radix => BinaryRadix;
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.
Acceptance criteria
PreciseNumber.Radix == 10 == decimal.Radix.
What's wrong
PreciseNumber/PreciseNumber.cs:437-440:INumberBase<T>.Radixis defined as "the radix, or base, for the type".PreciseNumberstoresSignificand × 10^Exponentand does all its digit work (significant digits, rounding,Round(decimalDigits), the rendered form) in base 10. The BCL's other decimal type,decimal, reportsRadix == 10.PreciseNumber.Test/PreciseNumberTests.cs:906-908(TestRadix) asserts2, so the test pins the wrong value. It does not document a design decision.Why it matters
Generic math code uses
T.Radixto 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. WithRadix == 2, such code treatsPreciseNumberas binary. For example, it would conclude thatx * 10is not an exact scale, whilex * 2is.Suggested fix
10, and rename the constant (e.g.DecimalRadix).TestRadixto expect 10.Acceptance criteria
PreciseNumber.Radix == 10 == decimal.Radix.