Repository navigation
Align Decimal32/64/128 surface with the approved API - #131098
Conversation
The IEEE 754 spec operations lack a verb, so the public API surface uses GetQuantum and HaveSameQuantum per the API review naming guidance. Co-authored-by: Copilot App <[email protected]>
Surfaces the IFloatingPointIeee754 Lerp method as a public static on each decimal type, matching the approved API surface and the binary IEEE types. Co-authored-by: Copilot App <[email protected]>
…ypes Surfaces the IFloatingPointIeee754 reciprocal estimate methods as public statics on each decimal type, matching the approved API surface. The decimal formats have no hardware estimate, so these compute the exact reciprocal. Co-authored-by: Copilot App <[email protected]>
Implements the IEEE 754-2019 5.5.2 binary encoding conversions. The decimal types already store the BID interchange representation, so these round-trip the raw bit pattern. The decimal (DPD) encoding is deferred. Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/area-system-numerics |
Co-authored-by: Copilot App <[email protected]>
08fa251 to
aea6b83
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the System.Numerics.Decimal32 / Decimal64 / Decimal128 public API surface to match the approved shape, and fills in previously-approved-but-missing members (notably BID/DPD encode/decode helpers and several IEEE 754-2019 operations).
Changes:
- Renames
Quantum/SameQuantumtoGetQuantum/HaveSameQuantumacross interface, implementations, ref surface, and tests. - Adds public BID/DPD conversion APIs (
EncodeBinary/DecodeBinary,EncodeDecimal/DecodeDecimal) for all three decimal IEEE types, backed by shared generic codec logic inNumber.DecimalIeee754.cs. - Adds
Lerp,ReciprocalEstimate, andReciprocalSqrtEstimatefor all three types, plus corresponding test coverage.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DecimalIeee754GenericSurface.cs | Extends generic-surface verification to include Lerp/reciprocal and the renamed quantum APIs. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Decimal64Tests.cs | Updates quantum naming; adds BID/DPD encode/decode tests and known vectors for Decimal64. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Decimal32Tests.cs | Updates quantum naming; adds BID/DPD encode/decode tests and known vectors for Decimal32 (includes a leading-digit-9 case). |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Decimal128Tests.cs | Updates quantum naming; adds BID/DPD encode/decode tests and known vectors for Decimal128. |
| src/libraries/System.Runtime/ref/System.Runtime.cs | Updates reference surface for renamed quantum APIs; adds Lerp/reciprocal and BID/DPD encode/decode members. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/IDecimalFloatingPointIeee754.cs | Updates the interface to the approved GetQuantum / HaveSameQuantum naming. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Decimal64.cs | Implements new public members: BID/DPD encode/decode, Lerp, reciprocal estimates, and renamed quantum APIs. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Decimal32.cs | Implements new public members: BID/DPD encode/decode, Lerp, reciprocal estimates, and renamed quantum APIs. |
| src/libraries/System.Private.CoreLib/src/System/Numerics/Decimal128.cs | Implements new public members: BID/DPD encode/decode, Lerp, reciprocal estimates, and renamed quantum APIs. |
| src/libraries/System.Private.CoreLib/src/System/Number.DecimalIeee754.cs | Adds shared generic BID⇄DPD conversion implementation (declet packing/unpacking and combination-field handling). |
Copilot's findings
- Files reviewed: 10/10 changed files
- Comments generated: 2
…64/Decimal128 Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (2)
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Decimal64Tests.cs:3010
- The new BID<->DPD codec has a distinct combination-field branch for leading digits 8/9 (see Number.EncodeDecimalIeee754 / DecodeDecimalIeee754). The Decimal64 tests added here only exercise msd<=7 inputs (+0/+1/123.45/NaN/etc), so the msd>=8 branch remains untested for Decimal64.
[Theory]
[InlineData(0x31C0000000000000UL)] // +0
[InlineData(0xB1C0000000000000UL)] // -0
[InlineData(0x31C0000000000001UL)] // +1
[InlineData(0x3180000000003039UL)] // 123.45
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Decimal128Tests.cs:3096
- The new BID<->DPD codec has a distinct combination-field branch for leading digits 8/9. The added Decimal128 Encode/DecodeDecimal tests cover specials and small finite values, but don't currently include an msd>=8 finite value, so that branch isn't exercised for Decimal128.
[Theory]
[InlineData(0x3040000000000000UL, 0x0000000000000000UL)] // +0
[InlineData(0xB040000000000000UL, 0x0000000000000000UL)] // -0
[InlineData(0x3040000000000000UL, 0x0000000000000001UL)] // +1
[InlineData(0x3041ED09BEAD87C0UL, 0x378D8E63FFFFFFFFUL)] // 34 nines (leading digit 9)
[InlineData(0x7800000000000000UL, 0x0000000000000000UL)] // +Infinity
[InlineData(0xF800000000000000UL, 0x0000000000000000UL)] // -Infinity
[InlineData(0x7C00000000000000UL, 0x0000000000000000UL)] // NaN
- Files reviewed: 10/10 changed files
- Comments generated: 0 new
|
Workflow state for the Holistic Review Orchestrator. {
"version": 5,
"last_dispatched_commit": "feb01377cdf3c03521b6e22c716799dac47bb05d",
"last_dispatched_base_ref": "main",
"last_dispatched_base_sha": "c39c3f371a1542dc1442a244bba117fb4e762299",
"last_reviewed_commit": "feb01377cdf3c03521b6e22c716799dac47bb05d",
"last_reviewed_base_ref": "main",
"last_reviewed_base_sha": "c39c3f371a1542dc1442a244bba117fb4e762299",
"last_recorded_worker_run_id": "29770130764",
"review_attempt_commit": "",
"review_attempt_base_ref": "",
"review_attempt_count": 0,
"max_review_attempts": 5,
"review_history_format": "holistic-review-disclosure-v1",
"review_history": [
{
"commit": "feb01377cdf3c03521b6e22c716799dac47bb05d",
"review_id": 4738173834
}
]
} |
There was a problem hiding this comment.
Holistic Review
Motivation: Justified. This aligns the Decimal32/Decimal64/Decimal128 surface with the API approved in #81376 (label api-approved), renaming Quantum/SameQuantum to GetQuantum/HaveSameQuantum and filling in approved-but-missing members (Lerp, ReciprocalEstimate, ReciprocalSqrtEstimate, EncodeBinary/DecodeBinary, EncodeDecimal/DecodeDecimal).
Approach: Sound. The BID/DPD codec is factored into shared generic helpers in Number.DecimalIeee754.cs keyed off the existing NumberBitsSignificand, so per-type members only vary by width. Lerp/ReciprocalEstimate/ReciprocalSqrtEstimate reuse existing primitives and match the binary IEEE types' definitions (e.g. Lerp == MultiplyAddEstimate(value1, One - amount, value2 * amount), identical to Double.Lerp). Compound is reasonably deferred, consistent with IFloatingPointIeee754.
Summary: [CLSCompliant(false)] on the unsigned-integer overloads, and the interface rename). The renames are also propagated consistently to all callers and tests. My only reservation is test depth for the new DPD codec (details below) — a human familiar with the encoding should confirm the canonical-vector coverage is sufficient. No blocking correctness issues found.
Detailed Findings
✅ API approval — Matches the approved proposal
Issue #81376 carries the api-approved label, and the approval comment (#81376 comment 1433633909) explicitly calls for GetQuantum/HaveSameQuantum and lists Lerp, ReciprocalEstimate, ReciprocalSqrtEstimate, and the EncodeBinary/DecodeBinary/EncodeDecimal/DecodeDecimal overloads with the exact per-width return types used here. The ref/System.Runtime.cs changes and the IDecimalFloatingPointIeee754<TSelf> interface rename line up with that shape. No extra unapproved public surface was introduced.
✅ Consistency — Renames fully propagated
Quantum/SameQuantum → GetQuantum/HaveSameQuantum is applied across all three concrete types, the interface, the ref assembly, and every test call site (QuantumTest, SameQuantumTest, Quantum_IntelReferenceVectors, and the generic DecimalIeee754GenericSurface). No stale references remain.
⚠️ Test quality — DPD canonical coverage is thin
The new DPD tests are strong on round-trips (EncodeDecodeDecimalRoundTrips covers ±0, ±Infinity, NaN, NaN-with-payload, the leading-digit-8/9 path, and a representative finite value across all three widths). However, round-trip tests only prove Decode∘Encode is an involution; they cannot detect a systematic bit-orientation error in the declet packing (DigitsToDeclet/DecletToDigits) that is symmetric in encode and decode. The only tests that pin the encoding to the published canonical bit pattern (EncodeDecimalKnownVectors) cover just the values 0 and 1 per width. Consider adding a few more canonical DPD vectors from IEEE 754-2019 Table 3.6 / the standard's examples that exercise multi-digit declets and the 8/9 selector combinations (e.g. values containing digits 2–9 in several positions), so the declet tables are locked to the standard rather than only to their own inverse. This is advisory, not merge-blocking.
Note
This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.
Generated by Holistic Review · 125 AIC · ⌖ 15 AIC · ⊞ 10K
EncodeDecimal/DecodeDecimal are cross-encoding conversions per IEEE 754-2019 5.5.2 and must produce canonical results, so drop the reserved G_i bits while preserving the sign, NaN marker, signaling bit, and payload. EncodeBinary and DecodeBinary stay pure copies that propagate non-canonical bits. Co-authored-by: Copilot App <[email protected]>
This aligns the
Decimal32/Decimal64/Decimal128public surface with the API approved in #81376 (comment), and fills in the members that were approved but not yet implemented.Naming
Quantum/SameQuantumtoGetQuantum/HaveSameQuantumto match the approved shape.Approved-but-missing members
Lerpon all three types.ReciprocalEstimateandReciprocalSqrtEstimateon all three types.EncodeBinary/DecodeBinary(IEEE 754-2019 §5.5.2 binary integer decimal, BID) on all three types.EncodeDecimal/DecodeDecimal(IEEE 754-2019 §5.5.2 densely packed decimal, DPD) on all three types.The BID/DPD conversions are implemented as a shared generic codec in
Number.DecimalIeee754.csthat reuses the existing significand unpack/encode infrastructure, so the per-type members only vary by width. The declet tables come directly from IEEE 754-2019 Table 3.6, and the format-field widths derive from the existingNumberBitsSignificandconstant rather than introducing new per-type state.Compoundis intentionally skipped -- it isn't exposed onIFloatingPointIeee754either, so exposing it here would be inconsistent.Tests
Round-trip coverage for BID and DPD across
±0,±Infinity,NaN,NaN-with-payload, the leading-digit 8/9 combination path, and representative finite values. The DPD tests additionally assert against the published canonical encodings (e.g.decimal32(1)==0x22500001,decimal64(1)==0x2238000000000001,decimal128(1)==0x22080000000000000000000000000001) to lock the bit orientation to the standard.Full
System.Runtime.Testsrun passes (0 failed).Note
This PR description and portions of the change were drafted with GitHub Copilot.