Repository navigation
Implement INumberBase and conversions for the IEEE 754 decimal types - #130807
Merged
tannergooding merged 7 commits intoJul 16, 2026
Merged
tannergooding merged 7 commits into
tannergooding merged 7 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-numerics |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands the IEEE 754 decimal floating-point types (Decimal32, Decimal64, Decimal128) with conversion support (including generic-math conversion dispatch), adds UTF-8 parse/format interface support, and extends the Intel BID reference-vector test infrastructure to validate the new conversion behavior.
Changes:
- Add conversion operator matrices and
INumberBase<TSelf>conversion dispatch (Create*,TryConvertFrom*,TryConvertTo*) for the IEEE 754 decimal types. - Add UTF-8 parsing/formatting interface implementations and shared formatting helpers.
- Extend Intel
readtest.in-driven test data and add new theory coverage for integer/binary-float/cross-decimal conversions.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Numerics/Decimal32.cs | Adds interface implementations and conversion surfaces for Decimal32. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Decimal64.cs | Adds interface implementations and conversion surfaces for Decimal64. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Decimal128.cs | Adds interface implementations and conversion surfaces for Decimal128. |
| src/libraries/System.Private.CoreLib/src/System/Number.DecimalIeee754.cs | Implements shared conversion logic used by the decimal IEEE 754 types. |
| src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs | Adds/extends shared formatting helpers for the decimal IEEE 754 types. |
| src/libraries/System.Runtime/ref/System.Runtime.cs | Updates public ref surface for new interfaces/members/operators. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DecimalIeee754IntelTestData.cs | Extends Intel vector parsing/enumeration for conversion-related operations. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Decimal32Tests.cs | Adds Intel-vector and focused behavioral tests for Decimal32 conversions. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Decimal64Tests.cs | Adds Intel-vector and focused behavioral tests for Decimal64 conversions. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Decimal128Tests.cs | Adds Intel-vector and focused behavioral tests for Decimal128 conversions. |
Copilot's findings
- Files reviewed: 10/10 changed files
- Comments generated: 1
Add the full explicit/implicit conversion matrix (to and from every built-in numeric type, `System.Decimal`, and the other decimal types), `INumberBase<TSelf>`, `ISpanFormattable`, `IUtf8SpanFormattable`, and `IUtf8SpanParsable<TSelf>` to `Decimal32`, `Decimal64`, and `Decimal128`. Each type owns its own conversion dispatch because `System.Decimal` and the built-in numeric types predate the IEEE 754 decimal types and never convert to them. Co-authored-by: Copilot App <[email protected]>
Cover the conversion operators with Intel BID reference vectors and add focused `Create*`/`TryConvert*` round-trip, checked-overflow, and saturation tests, including the near-`decimal` boundary where the nearest `Decimal64` rounds just outside `System.Decimal`'s range. Co-authored-by: Copilot App <[email protected]>
…eration Extract the single underscore-delimited token via spans instead of allocating a string array plus per-token substrings for every readtest.in row. Co-authored-by: Copilot App <[email protected]>
The byte-based Parse(ReadOnlySpan<byte>, NumberStyles, IFormatProvider?) overload carries an extra NumberStyles parameter, so it inherits from the INumberBase member rather than IUtf8SpanParsable, matching Half. Also drop an accidental duplicate of the decimal-saturation comment on Decimal64. Co-authored-by: Copilot App <[email protected]>
A negative value in (-1, 0) truncates toward zero into range, so a checked conversion to an unsigned target returns zero rather than throwing, matching the binary floating-point to integer conversions the decimal path mirrors. Co-authored-by: Copilot App <[email protected]>
tannergooding
force-pushed
the
tannergooding-decimal-ieee754-operators
branch
from
July 15, 2026 23:58
1c92dd6 to
7d476eb
Compare
tannergooding
marked this pull request as ready for review
July 16, 2026 00:21
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
These are lossy on 64-bit platforms where nint/nuint carry up to ~20 significant digits, exceeding Decimal64's 16-digit precision, so the approved API shape provides them as explicit rather than implicit. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
tannergooding
force-pushed
the
tannergooding-decimal-ieee754-operators
branch
from
July 16, 2026 00:36
c5e490b to
6205959
Compare
eiriktsarpalis
approved these changes
Jul 16, 2026
tannergooding
enabled auto-merge (squash)
July 16, 2026 07:31
Open
3 tasks
tannergooding
added a commit
that referenced
this pull request
Jul 17, 2026
…EEE 754 decimal types (#130890) Continues the incremental buildout of the IEEE 754 decimal types (part of #81376). #130807 added the conversion surface and `INumberBase<TSelf>`; this one adds the next set of interfaces and the modulus operator. Adds to `Decimal32`, `Decimal64`, and `Decimal128`: * `IFloatingPointConstants<TSelf>` -- `E`, `Pi`, and `Tau`, correctly rounded to each format's precision. * `ISignedNumber<TSelf>` -- `NegativeOne`. * `INumber<TSelf>` -- `Max`/`Min`/`MaxNumber`/`MinNumber`/`Clamp`/`Sign`/`CopySign` and friends, mirroring `System.Half`'s semantics (IEEE 2019 `minimum`/`maximum` cohort/signed-zero/NaN handling). * `IFloatingPoint<TSelf>` -- `Round` (all overloads), the `GetExponentByteCount`/`GetSignificandByteCount`/`TryWrite*` bit APIs, and the remaining classification members. * The modulus operator (`%`, `IModulusOperators<TSelf, TSelf, TSelf>`). The `%` operator follows the same truncated-remainder (`fmod`) semantics as `float`/`double`/`Half` -- `x - Truncate(x / y) * y` -- which is distinct from `IEEE754Remainder` (round-to-nearest quotient); the latter arrives with `IFloatingPointIeee754`. ---------- Non-trivial members are ported from the Intel BID reference and validated bit-exact against its reference vectors (modulus and round), plus the existing Python-oracle-generated coverage. The multi-argument `Round(value, digits, mode)` overloads are the one bespoke piece -- Intel has no direct baseline for them, so they are built on the faithful single-argument rounding primitive. `IFloatingPointIeee754<TSelf>`/`IDecimalFloatingPointIeee754<TSelf>` (and the transcendental sub-interfaces) are deferred to a follow-up that stacks on this. > [!NOTE] > This PR description was drafted by GitHub Copilot. --------- Co-authored-by: Copilot App <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continues the incremental buildout of the IEEE 754 decimal types (part of #81376). Prior PRs added the layout, parsing/formatting, arithmetic/comparison operators, and the simple statics. This one adds the conversion surface and the first interface implementation.
Adds to
Decimal32,Decimal64, andDecimal128:System.Decimal, and the other two decimal types.INumberBase<TSelf>, includingCreateChecked/CreateSaturating/CreateTruncatingand theTryConvertFrom*/TryConvertTo*dispatch.ISpanFormattable,IUtf8SpanFormattable, andIUtf8SpanParsable<TSelf>.Each type owns its own conversion dispatch because
System.Decimaland the built-in numeric types predate the IEEE 754 decimal types and therefore never convert to them. This mirrors theSystem.Halfdesign.Non-trivial conversions are validated against Intel's BID reference vectors.
Create*/TryConvert*add focused round-trip, checked-overflow, and saturation coverage -- including the near-decimalboundary where the nearestDecimal64rounds just outsideSystem.Decimal's range, which the saturating/truncating path handles by range-checking in exactDecimal128space.The larger remaining interfaces (
INumber,ISignedNumber,IFloatingPoint,IFloatingPointIeee754/IDecimalFloatingPointIeee754, and theIBinaryInteger-style bit APIs) are deferred to follow-up PRs.Note
This PR description was drafted by GitHub Copilot.