Skip to content

Add UTF-8 Parse/TryParse/TryFormat polyfills for BigInteger and Complex - #609

Merged
SimonCropp merged 1 commit into
mainfrom
biginteger-complex-utf8-parsing
Sep 17, 2026
Merged

SimonCropp merged 1 commit into
mainfrom
biginteger-complex-utf8-parsing

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

Polyfills the UTF-8 members that .NET 11 adds to BigInteger and Complex (dotnet/runtime#117745, from the Performance Improvements in .NET 11 post). Signatures were checked against the 11.0 RC1 ref pack, and the 7.0/8.0/9.0/10.0 ref packs were checked for when each member first appeared.

BigInteger (all targets below net11, needs FeatureMemory)

  • Parse(ReadOnlySpan<byte>, NumberStyles = Integer, IFormatProvider? = null)
  • Parse(ReadOnlySpan<byte>, IFormatProvider?)
  • TryParse(ReadOnlySpan<byte>, out BigInteger)
  • TryParse(ReadOnlySpan<byte>, NumberStyles, IFormatProvider?, out BigInteger)
  • TryParse(ReadOnlySpan<byte>, IFormatProvider?, out BigInteger)
  • TryFormat(Span<byte>, out int, ReadOnlySpan<char> = default, IFormatProvider? = null)

Complex (net7.0–net10.0)

  • TryParse(ReadOnlySpan<byte>, NumberStyles, IFormatProvider?, out Complex)
  • TryParse(ReadOnlySpan<byte>, IFormatProvider?, out Complex)

Below net7, Complex has no string Parse to delegate to. The UTF-8 TryFormat already exists from net8.

Complex.Parse(ReadOnlySpan<byte>, ...) is not polyfilled. Static extension members compile to plain static methods on Polyfill, so it would collide with BigInteger.Parse(ReadOnlySpan<byte>, ...) (CS0111). This matches how IPAddress.Parse is skipped next to Guid.Parse, and is documented with a //Note:.

All members decode the UTF-8 bytes to a string and delegate to the existing overloads. Results match the BCL, but they allocate a string.

New FeatureNumerics constant

On .NET Framework, BigInteger/Complex live in System.Numerics.dll. SDK-style projects reference it implicitly, but old-style projects may not. Polyfill.targets now sets FeatureNumerics when System.Numerics or System.Runtime.Numerics is in @(ReferencePath), and always sets it for netcoreapp, net5+ and netstandard. It is registered in Identifiers.sharedIdentifiers, BuildApiTest and SplitterTests, and listed in CLAUDE.md.

Verification

  • ApiBuilderTests (Debug) regenerated Split and the API list: 71/71 pass
  • Tests, Consume, ConsumeNoRefs and ConsumeClassicReferences build across all targets
  • New tests pass on net48, net8.0 and net11.0 (BCL). netcoreapp3.1 was not run locally because that runtime isn't installed

Adds the .NET 11 UTF-8 BigInteger Parse/TryParse/TryFormat and Complex TryParse overloads.
Complex UTF-8 Parse is skipped because it would collide with BigInteger.Parse as static extension members.
Introduces the FeatureNumerics constant, set when System.Numerics is referenced.
@SimonCropp SimonCropp added this to the 11.4.0 milestone Sep 17, 2026
@SimonCropp
SimonCropp merged commit bc1e0ac into main Sep 17, 2026
4 of 6 checks passed
@SimonCropp
SimonCropp deleted the biginteger-complex-utf8-parsing branch September 17, 2026 13:21
This was referenced Sep 19, 2026
This was referenced Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant