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
Parse("10", NumberStyles.HexNumber) silently returns 10 instead of 16 (or rejecting the style): AllowHexSpecifier and AllowBinarySpecifier are ignored #177
Parse(ReadOnlySpan<char>, NumberStyles, IFormatProvider?) (PreciseNumber/PreciseNumber.cs:1200-1307) and TryParse (~1369) never look at NumberStyles.AllowHexSpecifier or NumberStyles.AllowBinarySpecifier (neither name appears in the file). Input that happens to be all decimal digits is parsed as decimal, so a wrong value comes back with no error.
staticTParseG<T>(strings,NumberStylesst)whereT:INumberBase<T>=>T.Parse(s,st,CultureInfo.InvariantCulture);ParseG<PreciseNumber>("10",NumberStyles.HexNumber);// 10 — BigInteger/int give 16; decimal/double throw ArgumentExceptionParseG<PreciseNumber>("1010",NumberStyles.BinaryNumber);// 1010 — int gives 10PreciseNumber.TryParse("10",NumberStyles.HexNumber,CultureInfo.InvariantCulture,outvarr);// true, r = 10ParseG<PreciseNumber>("A",NumberStyles.HexNumber);// FormatException
Generic-math code (T.Parse(s, NumberStyles.HexNumber, ...) over INumberBase<T>) gets a silently wrong number for PreciseNumber where every BCL type either gives the right answer or refuses the style. This is a gap left by the #132 fix (styles are now validated, but these two flags fall through). It's distinct from #152, which is about valid inputs being rejected.
Suggested fix
Either:
throw ArgumentException when either flag is set, matching decimal and double, or
support them for integer input, matching BigInteger.
Acceptance: the calls above either return 16 / 10 or throw ArgumentException (for both Parse and TryParse); add tests alongside the existing NumberStyles tests.
Priority: Medium. It returns a wrong value silently instead of throwing, but only for callers that pass hex or binary NumberStyles, which mostly means generic-math code.
Area / suggested assignment:NumberStyles validation in Parse/TryParse (PreciseNumber/PreciseNumber.cs ~1200–1370)
Next step: the easier fix is to throw ArgumentException when AllowHexSpecifier or AllowBinarySpecifier is set, which matches decimal and double. Cover both Parse and TryParse in tests.
Activity
matt-edmondson commentedon Oct 29, 2026
Triage
NumberStyles, which mostly means generic-math code.NumberStylesvalidation inParse/TryParse(PreciseNumber/PreciseNumber.cs~1200–1370)Parsefor Parse("1 234,5", fr-FR) throws where decimal returns 1234.5: a typed space doesn't match a no-break-space group separator #174 only.ArgumentExceptionwhenAllowHexSpecifierorAllowBinarySpecifieris set, which matchesdecimalanddouble. Cover bothParseandTryParsein tests.Generated by Claude Code