Add General Decimal Arithmetic ordering, adjacency, and exponent operations#150
Open
Btocode wants to merge 1 commit into
Open
Add General Decimal Arithmetic ordering, adjacency, and exponent operations#150Btocode wants to merge 1 commit into
Btocode wants to merge 1 commit into
Conversation
…ations
Implement the following GDA / IEEE 754 decimal operations that were
missing from apd:
- Context.Max, Min, MaxAbs, MinAbs: numeric and by-magnitude minimum
and maximum, with the specification's NaN and total-order tie-break
rules.
- Context.NextPlus, NextMinus, NextToward: the representable value
adjacent to an operand in a given direction.
- Context.LogB, ScaleB: the adjusted exponent, and scaling by a power
of ten.
- Context.CopySign: the magnitude of one operand with the sign of
another.
- Decimal.SameQuantum and Decimal.CmpTotalMag: companions to the
existing CmpTotal.
The operations follow the General Decimal Arithmetic specification,
including the condition flags they raise. New table-driven tests cover
signed zeros, subnormals near Etiny, values near Nmax, infinities, and
quiet and signaling NaNs; the expected values were cross-checked against
the Python standard library's decimal module.
Signed-off-by: S Afsan Rahmatullah <afsan.scorp@gmail.com>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds the following General Decimal Arithmetic (GDA) / IEEE 754 decimal operations that apd was missing:
Context.Max,Min,MaxAbs,MinAbs— numeric and by-magnitude minimum and maximum, with the specification's NaN and total-order tie-break rules.Context.NextPlus,NextMinus,NextToward— the representable value adjacent to an operand in a given direction.Context.LogB,ScaleB— the adjusted exponent, and scaling by a power of ten.Context.CopySign— the magnitude of one operand with the sign of another.Decimal.SameQuantumandDecimal.CmpTotalMag— companions to the existingCmpTotal.The operations follow the GDA specification, including the condition flags they raise (
InvalidOperation,DivisionByZero,Overflow,Underflow,Subnormal,Inexact,Rounded,Clamped). Implementation notes worth a reviewer's attention:Max/Mintreat a quiet NaN operand as absent (return the other operand); only a signaling NaN raisesInvalidOperation. Ties (numerically equal operands) are broken by total order, so e.g.Max(1.0, 1.00)returns1.0.next-*operations compute increments on non-negative magnitudes (vianextPlus(x) == -nextMinus(-x)) to avoid relying on directed rounding of negative subnormals, and clamp directed-rounding overflow to Nmax rather than infinity.New table-driven tests cover signed zeros, subnormals near Etiny, values near Nmax, infinities, and quiet/signaling NaNs. The expected values were additionally cross-checked against the Python standard library's
decimalmodule (which implements the same specification) over tens of thousands of randomized inputs.