decimal API

Luna-Flow/floating/decimal is the IEEE 754-2019 decimal floating-point package of floating. A Decimal is an arbitrary-precision decimal value that keeps its quantum (exponent), its sign of zero and its NaN payload; a DecimalContext fixes precision, rounding, exponent range, clamping and tininess; every context operation returns the rounded value together with the DecimalFlags it raised. The package also encodes and decodes the decimal32/64/128 interchange formats in both DPD and BID, and evaluates elementary functions with certified rounding.

The decimal tutorial walks through typical tasks and the decimal design explains the arithmetic model, encodings, rounding and certification. The finite evidence for the IEEE claim is recorded in decimal conformance. Sticky General Decimal Arithmetic status and traps live in the separate decimal_gda package; decimal_checked accumulates the flags of a pipeline of Decimal operations.

Notation used below: a finite value is (−1)s⋅c⋅10q(-1)^s \cdot c \cdot 10^{q} with sign ss, non-negative integer coefficient cc and exponent (quantum) qq; pp is the context precision, emax⁡e_{\max} and emin⁡e_{\min} the context exponent limits for the adjusted exponent q+digits⁡(c)−1q + \operatorname{digits}(c) - 1, and Etiny=emin⁡−p+1E_{\text{tiny}} = e_{\min} - p + 1 the smallest exponent of a subnormal.

Values and representation

Decimal

Decimal is an immutable decimal floating-point value.

pub struct Decimal {
  // private fields
} derive(@debug.Debug)

A Decimal is one of: a finite value (−1)sc 10q(-1)^s c\,10^q (including ±0\pm 0), ±∞\pm\infty, or a quiet or signaling NaN with a sign and a non-negative integer payload. Every value also carries a working precision, used by the plain operators and by conversions that have no context argument. The fields are private; use the observers below. Two values with the same mathematical value but different exponents (for example 1.2 and 1.20) are different members of the same cohort: they compare equal numerically but are distinguished by quantum, same_quantum, compare_total, formatting and interchange encoding.

The derived Debug implementation is promoted as Decimal::to_repr; see Trait implementations.

Decimal::precision, coefficient, magnitude, exponent10, quantum

These observers return the stored representation of a value.

pub fn Decimal::precision(Self) -> Int
pub fn Decimal::coefficient(Self) -> @bigint.BigInt
pub fn Decimal::magnitude(Self) -> @bigint.BigInt
pub fn Decimal::exponent10(Self) -> Int
pub fn Decimal::quantum(Self) -> Int

precision is the working precision stored in the value (at least 1). coefficient and magnitude both return the non-negative coefficient cc; for a NaN they return the payload and for an infinity 0. The sign is never part of the coefficient: use is_negative. exponent10 and quantum both return the stored exponent qq; for special values it is 0.

///|
test "decimal representation observers" {
  let x = @decimal.Decimal::from_string("-12.300").unwrap()
  inspect(x.coefficient(), content="12300")
  inspect(x.quantum(), content="-3")
  inspect(x.is_negative(), content="true")
  inspect(x.precision(), content="34")
}

Decimal::sign, is_negative, is_signed

These observers report the sign of a value.

pub fn Decimal::sign(Self) -> @def.Sign
pub fn Decimal::is_negative(Self) -> Bool
pub fn Decimal::is_signed(Self) -> Bool

sign returns @def.Sign::Zero for both zeros and for every NaN, and Negative/Positive otherwise. is_negative and is_signed are the same predicate: they return the stored sign bit, so they are true for −0-0, for −∞-\infty and for a negative NaN.

Decimal::classify, class_name

classify returns the coarse class of a value; class_name returns the General Decimal Arithmetic class string under a context.

pub fn Decimal::classify(Self) -> @arithmetic.FpClass
pub fn Decimal::class_name(Self, DecimalContext) -> String

classify returns Finite, Infinity or NaN. class_name returns one of "sNaN", "NaN", "-Infinity", "+Infinity", "-Zero", "+Zero", "-Subnormal", "+Subnormal", "-Normal" or "+Normal"; the normal/subnormal split uses the context’s emin⁡e_{\min}.

Predicates

These functions test the class of a value.

pub fn Decimal::is_finite(Self) -> Bool
pub fn Decimal::is_infinite(Self) -> Bool
pub fn Decimal::is_nan(Self) -> Bool
pub fn Decimal::is_zero(Self) -> Bool
pub fn Decimal::is_negative_zero(Self) -> Bool
pub fn Decimal::is_quiet_nan(Self) -> Bool
pub fn Decimal::is_qnan(Self) -> Bool
pub fn Decimal::is_signaling_nan(Self) -> Bool
pub fn Decimal::is_snan(Self) -> Bool
pub fn Decimal::is_canonical(Self) -> Bool
pub fn Decimal::is_normal(Self, DecimalContext) -> Bool
pub fn Decimal::is_subnormal(Self, DecimalContext) -> Bool

is_qnan and is_snan are the General Decimal Arithmetic spellings of is_quiet_nan and is_signaling_nan. is_canonical always returns true: a Decimal has no non-canonical form; non-canonical encodings are a property of DecimalInterchange. A value is normal under a context when it is finite, non-zero and its adjusted exponent is at least emin⁡e_{\min}; it is subnormal when it is finite, non-zero and its adjusted exponent is below emin⁡e_{\min}. Zeros, infinities and NaNs are neither.

Decimal::nan_payload, get_payload, set_payload, set_payload_signaling

These functions read and replace the payload of a NaN.

pub fn Decimal::nan_payload(Self) -> @bigint.BigInt
pub fn Decimal::get_payload(Self) -> @bigint.BigInt
pub fn Decimal::set_payload(Self, @bigint.BigInt) -> Self
pub fn Decimal::set_payload_signaling(Self, @bigint.BigInt) -> Self

nan_payload and get_payload return the payload of a NaN and 0 for every other value. set_payload returns a quiet NaN with the given payload (its absolute value) and the original sign; set_payload_signaling returns a signaling NaN. Both return a non-NaN argument unchanged.

Construction and conversion

Decimal::make

make builds a finite value from a signed integer coefficient and an exponent, rounding it to a precision.

pub fn Decimal::make(@bigint.BigInt, Int, Int, mode? : @arithmetic.RoundingMode) -> Self

Decimal::make(c, q, p, mode~) represents c⋅10qc \cdot 10^{q}; the sign comes from c. Trailing zeros are removed first, the coefficient is then rounded to p digits with mode (default ToNearestEven) if it is longer, and trailing zeros are removed again. The result is therefore always in the reduced member of its cohort, and make(0, q, p) is +0+0 with exponent 0. No exponent range applies.

Decimal::zero, negative_zero, one, inf, nan, quiet_nan, signaling_nan

These constructors build the special and unit values.

pub fn Decimal::zero(precision? : Int) -> Self
pub fn Decimal::negative_zero(precision? : Int) -> Self
pub fn Decimal::one(precision? : Int) -> Self
pub fn Decimal::inf(@def.Sign, precision? : Int) -> Self
pub fn Decimal::nan(precision? : Int) -> Self
pub fn Decimal::quiet_nan(payload? : @bigint.BigInt, negative? : Bool, precision? : Int) -> Self
pub fn Decimal::signaling_nan(payload? : @bigint.BigInt, negative? : Bool, precision? : Int) -> Self

The default precision is 34. zero, negative_zero and one have exponent 0. inf(sign) is −∞-\infty for Negative and +∞+\infty otherwise. nan is a positive quiet NaN with payload 0; quiet_nan and signaling_nan default to payload 0 and a positive sign.

Decimal::from_int, from_bigint

These constructors convert an integer.

pub fn Decimal::from_int(Int, precision? : Int) -> Self
pub fn Decimal::from_bigint(@bigint.BigInt, precision? : Int) -> Self

Both are make(n, 0, precision) with the default precision 34: the result is reduced (from_int(1000) is 1E+3, exponent 3) and an integer with more than precision digits is rounded half-even.

Decimal::from_double, from_float

These constructors convert a binary floating-point number.

pub fn Decimal::from_double(Double, precision? : Int) -> Self
pub fn Decimal::from_float(Float, precision? : Int) -> Self

Every finite Double is a dyadic rational m⋅2km \cdot 2^{k} and therefore has a finite decimal expansion m⋅5−k⋅10km \cdot 5^{-k} \cdot 10^{k} for k<0k<0; the conversion forms that exact expansion and rounds it half-even to precision digits (default 34). Signed zeros and infinities are preserved; every NaN becomes a quiet NaN with payload 0 and the input’s sign. from_float widens to Double first, which is exact.

Decimal::from_bin_float, to_bin_float

These functions convert between Decimal and the binary BinFloat.

pub fn Decimal::from_bin_float(@bin_float.BinFloat, precision? : Int) -> Self
pub fn Decimal::to_bin_float(Self, precision? : Int, mode? : @arithmetic.RoundingMode) -> @bin_float.BinFloat

from_bin_float(x, precision~) is exact whenever the decimal expansion of x fits in precision decimal digits (default: the precision of x) and is otherwise rounded half-even; a binary zero becomes +0+0 and a NaN a quiet NaN with payload 0. to_bin_float(precision~, mode~) rounds the exact decimal value to a BinFloat of precision bits (default: the decimal’s precision field) with mode (default ToNearestEven). Most decimal fractions are not dyadic, so this direction is usually inexact; converting with TowardNegative and TowardPositive gives a binary enclosure of the decimal value. Zeros map to +0+0 and NaN payloads are not kept.

Decimal::from_nat, from_integral

These functions convert any Luna-Flow integer type.

pub fn[S : @luna-generic.Nat] Decimal::from_nat(S) -> Self
pub fn[S : @luna-generic.Integral] Decimal::from_integral(S) -> Self

They normalize the argument to a BigInt through Integral::normalize and return from_bigint(n).normalized() with precision 34. They are the NatHomomorphism and IntegralHomomorphism implementations.

Parsing and formatting

Decimal::parse, from_string

parse converts decimal text to a Decimal while keeping its quantum.

pub fn Decimal::parse(String, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::from_string(String, precision? : Int) -> Self?

The accepted syntax is an optional sign, digits with an optional decimal point, an optional exponent E/e with optional sign, or one of Inf, Infinity, NaN and sNaN (any letter case) followed for NaNs by optional decimal payload digits. If the significant digits fit precision (default 34) the exponent of the text is kept exactly: "1.2300" has coefficient 12300 and exponent −4-4, and "0.00" is +0+0 with exponent −2-2. A longer coefficient is rounded half-even to precision digits and reduced. No exponent range is applied. Invalid text returns Err(parse_error) from parse and None from from_string.

Decimal::from_string_ctx

from_string_ctx converts text under a context and reports conversion flags.

pub fn Decimal::from_string_ctx(String, DecimalContext) -> (Self, DecimalFlags)

The syntax is the one of parse. The value is rounded to the context precision (raising rounded, and inexact when non-zero digits are discarded), checked against the exponent range (overflow, subnormal, underflow, clamping) and, when clamp is set, folded down. A NaN payload with more digits than the context allows (precision −1-1 digits when clamp is set, otherwise precision) is a syntax error. Invalid text returns a quiet NaN with only the conversion_syntax flag set. In a non-extended context, Inf and NaN spellings are conversion-syntax errors.

///|
test "decimal from_string_ctx rounds and flags" {
  let ctx = @decimal.DecimalContext::decimal32()
  let (x, flags) = @decimal.Decimal::from_string_ctx("3.14159265", ctx)
  inspect(x, content="3.141593")
  inspect(flags.rounded && flags.inexact, content="true")
  let (bad, bad_flags) = @decimal.Decimal::from_string_ctx("1..2", ctx)
  inspect(bad.is_nan(), content="true")
  inspect(bad_flags.conversion_syntax, content="true")
}

Decimal::to_sci_string, to_eng_string

These functions implement the General Decimal Arithmetic to-scientific-string and to-engineering-string conversions of a text operand.

pub fn Decimal::to_sci_string(String, DecimalContext) -> (String, DecimalFlags)
pub fn Decimal::to_eng_string(String, DecimalContext) -> (String, DecimalFlags)

Both take text, convert it with from_string_ctx and format the result. Scientific form writes the coefficient with an exponent E±n whenever the exponent is positive or the adjusted exponent is below −6-6, and plain digits otherwise; engineering form uses an exponent that is a multiple of three. Special values are written Infinity, -Infinity, NaN, sNaN, with a payload such as NaN7. The flags are those of the conversion.

Decimal::to_string, output

to_string formats a value in scientific notation without a context.

pub fn Decimal::to_string(Self) -> String
pub fn Decimal::output(Self, &Logger) -> Unit

Finite values use the scientific-string rule of to_sci_string, so trailing zeros and the exponent are visible: 1.20, 1E+3, 1.2E-7. Special values are written in lower case: inf, -inf, nan, snan, -nan12. output writes the same text to a logger; both come from the Show implementation.

Contexts

DecimalContext

A DecimalContext is an immutable set of arithmetic parameters.

pub struct DecimalContext {
  // private fields
} derive(Eq)

A context holds a precision pp, a shared Luna-Flow rounding mode, a decimal rounding mode (decimal_rounding, the one the arithmetic uses), the adjusted-exponent limits emin⁡≤emax⁡e_{\min} \le e_{\max}, the clamp switch, the extended switch and a tininess rule. No operation reads ambient state: every context operation receives its context as an argument.

DecimalContext::new, try_new

These constructors build a context from named parameters.

pub fn DecimalContext::new(precision? : Int, rounding? : @arithmetic.RoundingMode, decimal_rounding? : DecimalRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, tininess? : DecimalTininessDetection) -> Self
pub fn DecimalContext::try_new(precision? : Int, rounding? : @arithmetic.RoundingMode, decimal_rounding? : DecimalRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, tininess? : DecimalTininessDetection) -> Result[Self, @arithmetic.ArithmeticError]
ParameterDefaultMeaning
precision34coefficient digits pp
roundingToNearestEvenshared rounding mode
decimal_roundingfrom roundingrounding mode used by the arithmetic
e_min, e_max−999 999 999-999\,999\,999, 999 999 999999\,999\,999adjusted-exponent range
clampfalsefold large exponents down to emax⁡−p+1e_{\max}-p+1
extendedtrueIEEE/extended arithmetic; false selects the GDA subset
tininessAfterRoundingwhen a result counts as tiny

When decimal_rounding is omitted it is DecimalRoundingMode::from_arithmetic(rounding); pass it explicitly to use HalfUp, HalfDown or ZeroFiveUp. new aborts when precision <= 0 or e_min > e_max; try_new returns Err(domain_error) instead.

The subset mode (extended=false) reproduces the classic decNumber subset: operands longer than pp digits are rounded first (raising lost_digits), zero results lose their sign and exponent, and special-value text is rejected. It exists for General Decimal Arithmetic test compatibility.

DecimalContext::decimal32, decimal64, decimal128, exact

These constructors return the interchange-format contexts and an exact working context.

pub fn DecimalContext::decimal32() -> Self
pub fn DecimalContext::decimal64() -> Self
pub fn DecimalContext::decimal128() -> Self
pub fn DecimalContext::exact() -> Self
Contextppemin⁡e_{\min}emax⁡e_{\max}clamp
decimal327−95-9596yes
decimal6416−383-383384yes
decimal12834−6143-61436144yes

All three use ToNearestEven (HalfEven), extended arithmetic and after-rounding tininess. exact() has precision 0, which means “unlimited”: results keep every digit and no rounding by precision happens; its exponent range is the default one. It is the only way to obtain precision 0.

DecimalContext::from_arithmetic_context

from_arithmetic_context converts the shared Luna-Flow context.

pub fn DecimalContext::from_arithmetic_context(@arithmetic.ArithmeticContext) -> Self

Precision, rounding and clamp are copied; a missing e_min or e_max becomes ∓999 999 999\mp 999\,999\,999. The result is extended and uses after-rounding tininess. The contextual and checked trait implementations use this conversion.

DecimalContext::precision, rounding, decimal_rounding, e_min, e_max, clamp, extended, tininess

These accessors return the fields of a context.

pub fn DecimalContext::precision(Self) -> Int
pub fn DecimalContext::rounding(Self) -> @arithmetic.RoundingMode
pub fn DecimalContext::decimal_rounding(Self) -> DecimalRoundingMode
pub fn DecimalContext::e_min(Self) -> Int
pub fn DecimalContext::e_max(Self) -> Int
pub fn DecimalContext::clamp(Self) -> Bool
pub fn DecimalContext::extended(Self) -> Bool
pub fn DecimalContext::tininess(Self) -> DecimalTininessDetection

precision is 0 only for exact().

DecimalContext::with_rounding, with_tininess, ieee754, is754version2019

These functions derive a context or describe its standard.

pub fn DecimalContext::with_rounding(Self, @arithmetic.RoundingMode) -> Self
pub fn DecimalContext::with_tininess(Self, DecimalTininessDetection) -> Self
pub fn DecimalContext::ieee754(Self) -> Self
pub fn DecimalContext::is754version2019(Self) -> Bool

with_rounding replaces both rounding fields (the decimal mode becomes from_arithmetic(rounding)). with_tininess replaces the tininess rule. ieee754 returns the context unchanged: every context already follows the IEEE 754-2019 semantics of this package. is754version2019 always returns true.

DecimalContext::equal, not_equal

These functions compare contexts field by field.

pub fn DecimalContext::equal(Self, Self) -> Bool
pub fn DecimalContext::not_equal(Self, Self) -> Bool

Rounding modes and tininess

DecimalRoundingMode

DecimalRoundingMode lists the eight decimal rounding directions.

pub(all) enum DecimalRoundingMode {
  HalfEven
  HalfUp
  HalfDown
  Down
  Ceiling
  Floor
  Up
  ZeroFiveUp
}
pub fn DecimalRoundingMode::equal(Self, Self) -> Bool
pub fn DecimalRoundingMode::not_equal(Self, Self) -> Bool

Let x>0x>0 lie strictly between two adjacent representable coefficients cc and c+1c+1 (in units of the last place). Down returns cc, Up c+1c+1; Ceiling and Floor round toward +∞+\infty and −∞-\infty (so they depend on the sign); HalfEven, HalfUp and HalfDown return the nearer of the two and break an exact tie toward the even coefficient, away from zero, and toward zero respectively; ZeroFiveUp returns c+1c+1 when the last digit of cc is 0 or 5 and cc otherwise. IEEE 754 calls HalfEven roundTiesToEven, HalfUp roundTiesToAway, Down roundTowardZero, Ceiling roundTowardPositive and Floor roundTowardNegative.

DecimalRoundingMode::from_arithmetic, to_arithmetic

These functions map between decimal modes and the shared @arithmetic.RoundingMode.

pub fn DecimalRoundingMode::from_arithmetic(@arithmetic.RoundingMode) -> Self
pub fn DecimalRoundingMode::to_arithmetic(Self) -> @arithmetic.RoundingMode?
@arithmetic.RoundingModeDecimalRoundingMode
ToNearestEvenHalfEven
TowardZeroDown
TowardPositiveCeiling
TowardNegativeFloor
AwayFromZeroUp

to_arithmetic returns None for HalfUp, HalfDown and ZeroFiveUp, which the shared enum does not have.

DecimalTininessDetection

DecimalTininessDetection chooses when a non-zero result is tiny.

pub(all) enum DecimalTininessDetection {
  BeforeRounding
  AfterRounding
}
pub fn DecimalTininessDetection::equal(Self, Self) -> Bool
pub fn DecimalTininessDetection::not_equal(Self, Self) -> Bool

BeforeRounding calls a result tiny when the adjusted exponent of the exact result is below emin⁡e_{\min}; AfterRounding uses the result rounded to pp digits with unbounded exponent. A tiny result raises subnormal, and also underflow when it is inexact.

Status flags

DecimalFlags

DecimalFlags records the conditions raised by one operation.

pub struct DecimalFlags {
  inexact : Bool
  rounded : Bool
  lost_digits : Bool
  invalid_operation : Bool
  division_by_zero : Bool
  overflow : Bool
  underflow : Bool
  subnormal : Bool
  clamped : Bool
  conversion_syntax : Bool
  division_impossible : Bool
  division_undefined : Bool
  invalid_context : Bool
} derive(Eq)
FieldRaised when
inexactthe result differs from the exact result
roundeddigits were discarded, even if they were all zero
lost_digitsa subset-mode operand longer than pp lost non-zero digits
invalid_operationthe operation is invalid (signaling NaN, ∞−∞\infty-\infty, 0×∞0\times\infty, bad quantize, domain error)
division_by_zeroan exact infinite result from finite operands (x/0x/0, log⁡0\log 0)
overflowthe rounded result’s adjusted exponent exceeds emax⁡e_{\max}
underflowthe result is tiny and inexact
subnormalthe result is tiny
clampedthe exponent was changed to fit (fold-down or zero exponent clamp)
conversion_syntaxtext could not be parsed
division_impossiblean integer quotient needs more than pp digits
division_undefined0/00/0 (raised together with invalid_operation)
invalid_contextthe context is outside the range an elementary function supports

Fields are public and read-only; the flags never accumulate implicitly.

DecimalFlags::new, combine, contains, has_error

These functions create, merge and query flag sets.

pub fn DecimalFlags::new() -> Self
pub fn DecimalFlags::combine(Self, Self) -> Self
pub fn DecimalFlags::contains(Self, DecimalSignal) -> Bool
pub fn DecimalFlags::has_error(Self) -> Bool
pub fn DecimalFlags::equal(Self, Self) -> Bool
pub fn DecimalFlags::not_equal(Self, Self) -> Bool

new has every flag clear. combine is the field-wise OR, so it is associative, commutative and idempotent with new() as identity. contains reads the flag named by a DecimalSignal. has_error is invalid_operation∨division_by_zero∨division_undefined∨division_impossible∨invalid_context\text{invalid\_operation} \lor \text{division\_by\_zero} \lor \text{division\_undefined} \lor \text{division\_impossible} \lor \text{invalid\_context}; it does not include conversion_syntax, overflow or underflow.

///|
test "decimal flags accumulate by combine" {
  let ctx = @decimal.DecimalContext::decimal64()
  let one = @decimal.Decimal::one()
  let three = @decimal.Decimal::from_int(3)
  let (third, f1) = one.div_ctx(three, ctx)
  let (_, f2) = one.div_ctx(@decimal.Decimal::zero(), ctx)
  let all = f1.combine(f2)
  inspect(third, content="0.3333333333333333")
  inspect(all.contains(@decimal.DecimalSignal::Inexact), content="true")
  inspect(all.division_by_zero, content="true")
  inspect(all.has_error(), content="true")
}

DecimalSignal

DecimalSignal names one flag of DecimalFlags.

pub(all) enum DecimalSignal {
  ConversionSyntax
  DivisionByZero
  DivisionImpossible
  DivisionUndefined
  InvalidContext
  InvalidOperation
  Overflow
  Underflow
  Subnormal
  Inexact
  Rounded
  Clamped
  LostDigits
}
pub fn DecimalSignal::equal(Self, Self) -> Bool
pub fn DecimalSignal::not_equal(Self, Self) -> Bool

Each constructor corresponds to the field of the same name.

Plain operations without a context

The operators and the functions in this group take no context and return no flags. They are convenient for exact work and for generic code over the Luna-Flow algebra traits; use the context arithmetic whenever rounding, the exponent range or flags matter.

Decimal::add, sub, mul, div, neg

These functions are the arithmetic operators +, -, *, / and unary -.

pub fn Decimal::add(Self, Self) -> Self
pub fn Decimal::sub(Self, Self) -> Self
pub fn Decimal::mul(Self, Self) -> Self
pub fn Decimal::div(Self, Self) -> Self
pub fn Decimal::neg(Self) -> Self

The result precision is max⁡(pa,pb)\max(p_a, p_b) of the operand precision fields.

  • add/sub compute the exact sum, round it half-even to that precision and return the reduced cohort member: 1.20 + 3.40 is 4.6.
  • mul returns the exact product with exponent qa+qbq_a+q_b and is not rounded: 1.25 * 2.50 is 3.1250, and the coefficient may be longer than the precision field.
  • div rounds the quotient half-even to that precision and reduces it. The quotient is computed with a few guard digits and then rounded again, so in rare cases it differs from the correctly rounded result by one unit in the last place; div_ctx rounds once.
  • neg flips the sign bit of every value, including zeros and NaNs.

Special values: a NaN operand gives a quiet NaN with the first NaN’s sign and payload; ∞−∞\infty-\infty, 0×∞0\times\infty, 0/00/0 and ∞/∞\infty/\infty give a positive NaN; x/0x/0 gives a signed infinity; finite/∞/\infty gives +0+0. No exponent range is applied. Exact cancellation gives +0+0; the sum of two negative zeros is −0-0.

///|
test "decimal plain operators" {
  let a = @decimal.Decimal::from_string("1.20").unwrap()
  let b = @decimal.Decimal::from_string("3.40").unwrap()
  inspect(a + b, content="4.6")
  inspect(a * b, content="4.0800")
  inspect(a - b, content="-2.2")
  inspect(-a, content="-1.20")
  inspect(@decimal.Decimal::one() / @decimal.Decimal::from_int(8), content="0.125")
}

Decimal::abs, copy, copy_abs, copy_negate, copy_sign

These functions change only the sign bit.

pub fn Decimal::abs(Self) -> Self
pub fn Decimal::copy(Self) -> Self
pub fn Decimal::copy_abs(Self) -> Self
pub fn Decimal::copy_negate(Self) -> Self
pub fn Decimal::copy_sign(Self, Self) -> Self

They never round, never raise flags and keep exponent, payload and NaN kind. abs and copy_abs clear the sign, copy_negate flips it, copy_sign copies the sign bit of the second operand and copy returns its argument.

Decimal::normalized, trim, with_precision

These functions change the cohort member or the precision field.

pub fn Decimal::normalized(Self) -> Self
pub fn Decimal::trim(Self) -> Self
pub fn Decimal::with_precision(Self, Int, @arithmetic.RoundingMode) -> Self

normalized returns the reduced member of the cohort (all trailing zeros removed, zero with exponent 0), rounding half-even to the value’s own precision if the coefficient is longer. trim removes the trailing zeros of the fractional part: with a negative exponent it stops at exponent 0 (12.300 becomes 12.3, 1200 stays 1200), with a positive exponent it removes all of them (1.20E+3 becomes 1.2E+3); a zero gets exponent 0. with_precision(p, mode) rounds a finite value to p digits with mode, reduces it and stores p as the precision field; special values only get the new precision field. All three are flag-free.

Decimal::div_checked, sqrt

These functions divide and take a square root, reporting domain errors as Result.

pub fn Decimal::div_checked(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::sqrt(Self) -> Result[Self, @arithmetic.ArithmeticError]

div_checked(a, b) is div_ctx under DecimalContext::new(precision=max(p_a, p_b)); it returns Err(division_by_zero) for x/0x/0 and Err(domain_error) for an invalid division. sqrt is sqrt_ctx under DecimalContext::new(precision=p) and returns Err(domain_error) for a negative non-zero operand. Both are correctly rounded half-even.

Context arithmetic

Every function in this group takes a DecimalContext and returns (result, flags). The result is the exact result rounded once to the context precision with the context’s decimal rounding mode, then checked against the exponent range: overflow gives the rounding-mode-dependent result of the design page, tiny results are rounded to the subnormal grid 10Etiny10^{E_{\text{tiny}}}, and with clamp large exponents are folded down to emax⁡−p+1e_{\max}-p+1. When the exact result fits, the exponent is the preferred exponent of the operation, so cohorts carry information. NaN operands propagate as a quiet NaN with the first NaN’s sign and payload (the payload is cut to its low pp digits); any signaling NaN operand raises invalid_operation.

Decimal::add_ctx, sub_ctx, mul_ctx, div_ctx

These functions are the correctly rounded arithmetic operations.

pub fn Decimal::add_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sub_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::mul_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::div_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)

Preferred exponents: min⁡(qa,qb)\min(q_a,q_b) for addition and subtraction, qa+qbq_a+q_b for multiplication, qa−qbq_a-q_b for division. An exact quotient is returned in the member closest to the preferred exponent; an inexact quotient has pp digits. A zero sum is +0+0 except under Floor (where it is −0-0 if either operand is negative) or when both operands are −0-0.

Special cases: ∞−∞\infty-\infty and 0×∞0\times\infty, ∞/∞\infty/\infty give NaN with invalid_operation; 0/00/0 gives NaN with invalid_operation and division_undefined; x/0x/0 for finite non-zero xx gives a signed infinity with division_by_zero; finite/∞/\infty gives a signed zero with exponent EtinyE_{\text{tiny}} and clamped.

///|
test "decimal context arithmetic keeps preferred exponents" {
  let ctx = @decimal.DecimalContext::decimal64()
  let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
  inspect(d("1.20").add_ctx(d("3.40"), ctx).0, content="4.60")
  inspect(d("1.25").mul_ctx(d("2.50"), ctx).0, content="3.1250")
  inspect(d("2.400").div_ctx(d("1.2"), ctx).0, content="2.00")
  let (q, flags) = d("2").div_ctx(d("3"), ctx)
  inspect(q, content="0.6666666666666667")
  inspect(flags.inexact, content="true")
}

Decimal::fma_ctx

fma_ctx computes x⋅y+zx \cdot y + z with a single rounding.

pub fn Decimal::fma_ctx(Self, Self, Self, DecimalContext) -> (Self, DecimalFlags)

The product is formed exactly and added to z exactly; only the sum is rounded. 0×∞0\times\infty is invalid even when z is a quiet NaN. ∞⋅y+(−∞)\infty \cdot y + (-\infty) with opposite signs is invalid. In a non-extended context the operation returns NaN with invalid_operation.

Decimal::sqrt_ctx

sqrt_ctx returns the correctly rounded square root.

pub fn Decimal::sqrt_ctx(Self, DecimalContext) -> (Self, DecimalFlags)

The preferred exponent is ⌊q/2⌋\lfloor q/2 \rfloor. An exact root is returned in the member closest to it (sqrt(0.0400) is 0.20); an inexact root has pp digits and raises inexact and rounded. −0=−0\sqrt{-0} = -0; a negative non-zero operand or −∞-\infty gives NaN with invalid_operation; +∞=+∞\sqrt{+\infty}=+\infty.

Decimal::plus_ctx, minus_ctx, abs_ctx, apply_ctx

These functions round one operand to the context.

pub fn Decimal::plus_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minus_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::abs_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::apply_ctx(Self, DecimalContext) -> (Self, DecimalFlags)

apply_ctx rounds a value to the context (precision, exponent range, clamping) and quiets a NaN, keeping the sign of zero. plus_ctx is 0+x0 + x: like apply_ctx, but a zero becomes +0+0. minus_ctx is 0−x0 - x and abs_ctx is ∣x∣|x| rounded to the context; signaling NaNs raise invalid_operation.

Decimal::divide_integer, remainder, remainder_near, remainder_ctx

These functions compute integer quotients and remainders.

pub fn Decimal::divide_integer(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder_near(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)

divide_integer(x, y) is trunc⁡(x/y)\operatorname{trunc}(x/y) with exponent 0. When the integer quotient needs more than pp digits, the result is NaN with division_impossible and invalid_operation. remainder(x, y) is x−y⋅trunc⁡(x/y)x - y\cdot\operatorname{trunc}(x/y) with the sign of xx (General Decimal Arithmetic remainder). remainder_near(x, y) is x−y⋅nx - y\cdot n where nn is x/yx/y rounded to the nearest integer, ties to even (IEEE 754 remainder); remainder_ctx is the same operation. The remainder is exact when it fits, with preferred exponent min⁡(qx,qy)\min(q_x, q_y), and its sign is that of xx when it is zero. xrem⁡0x \operatorname{rem} 0 and ∞rem⁡y\infty \operatorname{rem} y are invalid (0rem⁡00 \operatorname{rem} 0 also raises division_undefined); xrem⁡∞=xx \operatorname{rem} \infty = x.

///|
test "decimal remainders" {
  let ctx = @decimal.DecimalContext::decimal64()
  let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
  inspect(d("10").divide_integer(d("3"), ctx).0, content="3")
  inspect(d("10").remainder(d("3"), ctx).0, content="1")
  inspect(d("10").remainder_near(d("6"), ctx).0, content="-2")
  inspect(d("-7.5").remainder(d("2"), ctx).0, content="-1.5")
}

Quantum and exponent operations

Decimal::quantize

quantize rounds a value to the exponent of another value.

pub fn Decimal::quantize(Self, Self, DecimalContext) -> (Self, DecimalFlags)

x.quantize(y, ctx) returns the value of x with exponent qyq_y, rounding with the context’s mode when digits are dropped (raising rounded, and inexact if they were non-zero). The result is NaN with invalid_operation when the target exponent is outside [Etiny,emax⁡][E_{\text{tiny}}, e_{\max}], when the resulting coefficient needs more than pp digits, when its adjusted exponent exceeds emax⁡e_{\max}, or when exactly one operand is infinite. Two infinities give the infinity of x. The quantum never silently changes: if the result cannot have exponent qyq_y the operation fails.

///|
test "decimal quantize to cents" {
  let ctx = @decimal.DecimalContext::decimal64()
  let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
  let (cents, flags) = d("12.3456").quantize(d("0.01"), ctx)
  inspect(cents, content="12.35")
  inspect(flags.inexact, content="true")
  let small = @decimal.DecimalContext::new(precision=3, e_min=-99, e_max=99)
  let (bad, bad_flags) = d("999.9").quantize(d("0.1"), small)
  inspect(bad.is_nan(), content="true")
  inspect(bad_flags.invalid_operation, content="true")
}

Decimal::rescale

rescale sets the exponent to an integer operand.

pub fn Decimal::rescale(Self, Self, DecimalContext) -> (Self, DecimalFlags)

x.rescale(n, ctx) is quantize with target exponent nn, where nn must be a finite integer; any other second operand gives NaN with invalid_operation.

Decimal::same_quantum

same_quantum tests whether two values have the same exponent.

pub fn Decimal::same_quantum(Self, Self) -> Bool

Two finite values have the same quantum when their exponents are equal; two infinities, and two NaNs, always have the same quantum; any other pair does not. It never raises flags.

Decimal::reduce_ctx, normalize_ctx

These functions round a value to the context and remove trailing zeros.

pub fn Decimal::reduce_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::normalize_ctx(Self, DecimalContext) -> (Self, DecimalFlags)

reduce_ctx applies the context, then removes trailing zeros while the exponent stays at most emax⁡e_{\max} (with clamp, at most emax⁡−p+1e_{\max}-p+1). A zero becomes a zero with exponent 0 (keeping its sign in an extended context). normalize_ctx is the same operation under its older General Decimal Arithmetic name.

Decimal::to_integral_exact, to_integral_value

These functions round to an integer.

pub fn Decimal::to_integral_exact(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_integral_value(Self, DecimalContext) -> (Self, DecimalFlags)

A finite value with negative exponent is quantized to exponent 0 with the context’s rounding mode; a value with exponent ≥0\ge 0 is only rounded to the context. to_integral_exact reports rounded/inexact; to_integral_value returns the same value with those two flags cleared. Infinities are returned unchanged; NaNs are quieted.

Decimal::scaleb_ctx, logb_ctx

These functions scale by a power of ten and extract the adjusted exponent.

pub fn Decimal::scaleb_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logb_ctx(Self, DecimalContext) -> (Self, DecimalFlags)

x.scaleb_ctx(n, ctx) returns x⋅10nx \cdot 10^{n} by adding nn to the exponent; nn must be a finite integer with exponent 0 and ∣n∣≤2(emax⁡+p)|n| \le 2(e_{\max}+p), otherwise the result is NaN with invalid_operation. The result keeps the coefficient of x (it is not rounded to pp digits), applies the subnormal and clamp rules, and overflows to a signed infinity with overflow, inexact and rounded in every rounding mode. logb_ctx(x) returns the adjusted exponent ⌊log⁡10∣x∣⌋\lfloor\log_{10}|x|\rfloor as an integer Decimal; logb⁡(±0)=−∞\operatorname{logb}(\pm 0) = -\infty with division_by_zero and logb⁡(±∞)=+∞\operatorname{logb}(\pm\infty) = +\infty.

Adjacent values

Decimal::next_plus, next_minus, next_toward

These functions return the neighbouring representable values.

pub fn Decimal::next_plus(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_minus(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_toward(Self, Self, DecimalContext) -> (Self, DecimalFlags)

next_plus is the smallest representable value greater than x in the context and next_minus the largest smaller one, including subnormals down to 10Etiny10^{E_{\text{tiny}}} and the largest finite value (10p−1) 10emax⁡−p+1(10^{p}-1)\,10^{e_{\max}-p+1}; next_plus(-∞) is the most negative finite value. They raise no flags for finite results. next_toward(x, y) moves x one step toward y; when x=yx = y it returns x with the sign of y for zeros. A step of next_toward that ends in an infinity raises overflow, inexact and rounded; one that ends subnormal or zero raises underflow, subnormal, inexact and rounded.

///|
test "decimal neighbours of one" {
  let ctx = @decimal.DecimalContext::decimal64()
  let one = @decimal.Decimal::one()
  inspect(one.next_plus(ctx).0, content="1.000000000000001")
  inspect(one.next_minus(ctx).0, content="0.9999999999999999")
}

Comparison and ordering

Decimal::compare, equal, not_equal, op_lt, op_le, op_gt, op_ge

compare is the numeric three-way comparison used by Compare and the comparison operators.

pub fn Decimal::compare(Self, Self) -> Int
pub fn Decimal::equal(Self, Self) -> Bool
pub fn Decimal::not_equal(Self, Self) -> Bool
pub fn Decimal::op_lt(Self, Self) -> Bool
pub fn Decimal::op_le(Self, Self) -> Bool
pub fn Decimal::op_gt(Self, Self) -> Bool
pub fn Decimal::op_ge(Self, Self) -> Bool

compare returns −1-1, 0 or 1 by numeric value, with −0=+0-0 = +0 and all members of a cohort equal. NaN has no numeric order, so that Compare stays a total preorder (sorting never aborts) every NaN compares equal to every other NaN and greater than every non-NaN. equal (==) agrees with compare: NaN == NaN is true. This is not IEEE equality; use compare_checked, compare_ctx or the NaN predicates when NaN must be unordered. op_lt and friends are the promoted operator methods of Compare.

///|
test "decimal numeric order is a total preorder" {
  let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
  inspect(d("1.0") == d("1.00"), content="true")
  inspect(d("-0").compare(d("0")), content="0")
  inspect(@decimal.Decimal::nan().compare(d("1E+999")), content="1")
  let sorted = [d("2"), @decimal.Decimal::nan(), d("-1")]
  sorted.sort()
  inspect(sorted.map(fn(x) { x.to_string() }).join(" "), content="-1 2 nan")
}

Decimal::compare_checked

compare_checked is the IEEE numeric comparison with NaN as an error.

pub fn Decimal::compare_checked(Self, Self) -> Result[Int, @arithmetic.ArithmeticError]

It returns Ok(compare(x, y)) when neither operand is a NaN and Err(unordered_comparison) otherwise. It is the CompareChecked implementation.

Decimal::compare_ctx, compare_signal_ctx

These functions are the General Decimal Arithmetic comparisons with a decimal result.

pub fn Decimal::compare_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::compare_signal_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)

They return the Decimal −1-1, 0 or 1, or a quiet NaN when an operand is a NaN. compare_ctx raises invalid_operation only for a signaling NaN; compare_signal_ctx raises it for every NaN (IEEE signaling comparison).

Decimal::compare_total, compare_total_magnitude, compare_total_ctx, compare_total_magnitude_ctx

These functions implement the IEEE 754 totalOrder predicate as a three-way comparison.

pub fn Decimal::compare_total(Self, Self) -> Int
pub fn Decimal::compare_total_magnitude(Self, Self) -> Int
pub fn Decimal::compare_total_ctx(Self, Self, DecimalContext) -> (Int, DecimalFlags)
pub fn Decimal::compare_total_magnitude_ctx(Self, Self, DecimalContext) -> (Int, DecimalFlags)

compare_total orders every representation:

−NaN<−sNaN<−∞<negative finite<−0<+0<positive finite<+∞<+sNaN<+NaN.-\text{NaN} < -\text{sNaN} < -\infty < \text{negative finite} < -0 < +0 < \text{positive finite} < +\infty < +\text{sNaN} < +\text{NaN}.

Equal finite values are ordered by exponent: for positive values the smaller exponent comes first (1.00<1.01.00 < 1.0), for negative values the larger. NaNs of the same sign and kind are ordered by payload (reversed for negative NaNs). It returns 0 only for identical representations. compare_total_magnitude compares the absolute values. The _ctx forms first prepare the operands for the context (which only matters in subset mode) and return the flags of that step.

Decimal::min, max, clamp, clamp_checked

These functions select by numeric order without a context.

pub fn Decimal::min(Self, Self) -> Self
pub fn Decimal::max(Self, Self) -> Self
pub fn Decimal::clamp(Self, min~ : Self, max~ : Self) -> Self
pub fn Decimal::clamp_checked(Self, min~ : Self, max~ : Self) -> Result[Self, @arithmetic.ArithmeticError]

min and max return the other operand when exactly one is a quiet NaN, a quiet NaN when both are NaNs or either is signaling, and the receiver on ties. clamp returns min below the range, max above it, and the value (including a NaN) otherwise; it aborts when a bound is NaN or min > max. clamp_checked returns Err(domain_error) in those cases.

Decimal::min_ctx, max_ctx, min_mag_ctx, max_mag_ctx

These functions are the General Decimal Arithmetic min, max, min-magnitude and max-magnitude operations.

pub fn Decimal::min_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::max_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::min_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::max_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)

A quiet NaN loses to a number; two NaNs give the first quieted; a signaling NaN gives a quiet NaN with invalid_operation. Numerically equal operands are separated by compare_total (so min_ctx(1.0, 1.00) is 1.00 and min_ctx(-0, 0) is -0). The selected value is rounded to the context.

IEEE minimum and maximum

These twelve functions are the IEEE 754-2019 §9.6 minimum and maximum operations.

pub fn Decimal::minimum_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)

minimum_ctx and maximum_ctx propagate NaN: any NaN operand gives a quiet NaN. The _number_ variants return the number when exactly one operand is a NaN. In both, a signaling NaN raises invalid_operation. The magnitude variants compare ∣x∣|x| and ∣y∣|y| and fall back to the signed order on equal magnitudes. Ties are broken by compare_total, so −0<+0-0 < +0. The _mag_ spellings are aliases of the _magnitude_ ones. The selected value is rounded to the context.

Digit-wise operations

Decimal::logical_and, logical_or, logical_xor, logical_invert

These functions apply Boolean operations digit by digit to logical operands.

pub fn Decimal::logical_and(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_or(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_xor(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_invert(Self, DecimalContext) -> (Self, DecimalFlags)

A logical operand is a finite, non-negative value with exponent 0 whose coefficient digits are all 0 or 1, such as 1101. The operation works on the low pp digits and returns a logical operand; any other operand gives NaN with invalid_operation.

Decimal::shift_ctx, rotate_ctx

These functions shift or rotate the coefficient digits.

pub fn Decimal::shift_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rotate_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)

The coefficient is viewed as pp digits. A positive count nn moves digits toward the most significant end, a negative one toward the least significant end; shift_ctx fills with zeros and drops digits that leave the window, rotate_ctx wraps them around. The exponent and sign are kept. The count must be an integer with exponent 0 and ∣n∣≤p|n| \le p; otherwise the result is NaN with invalid_operation. Infinities are returned unchanged.

Elementary functions

Every elementary function exists in two forms. f_ctx(x, ctx) returns (result, flags). try_f_ctx(x, ctx) returns the same pair in Ok, or Err with an ArithmeticError whose certification_failure_detail() names the operation, the target precision and the exhausted refinement budget when the result could not be certified. When certification fails, f_ctx returns NaN with invalid_operation.

Finite results are correctly rounded in every DecimalRoundingMode: the implementation evaluates a guaranteed enclosure of f(x)f(x) in ball_float and accepts it only when both endpoints round to the same Decimal with the same flags (see the design). Exact cases (such as log⁡101000=3\log_{10} 1000 = 3, e0=1e^0 = 1, sin⁡0=0\sin 0 = 0, cospi⁡(1)=−1\operatorname{cospi}(1) = -1, integer powers) are detected and returned exactly without inexact.

All of them return NaN with invalid_context when p>999 999p > 999\,999, emax⁡>999 999e_{\max} > 999\,999 or emin⁡<−999 999e_{\min} < -999\,999, or when a finite operand has more than 999,999 digits or an adjusted exponent beyond about ±106\pm 10^6.

Decimal::exp_ctx, ln_ctx, log10_ctx and their try_ forms

These functions are the General Decimal Arithmetic exponential and logarithms.

pub fn Decimal::exp_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::ln_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log10_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_exp_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_ln_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log10_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]

e±0=1e^{\pm 0} = 1, e+∞=+∞e^{+\infty}=+\infty, e−∞=+0e^{-\infty} = +0. ln⁡\ln and log⁡10\log_{10} of ±0\pm 0 are −∞-\infty (no flag in an extended context), of +∞+\infty are +∞+\infty, of a negative value or −∞-\infty are NaN with invalid_operation; ln⁡1=0\ln 1 = 0, and log⁡10\log_{10} of a power of ten is the exact integer exponent. Arguments so large or small that exe^x certainly overflows or underflows are decided without evaluation.

Decimal::power_ctx, pown_ctx, rootn_ctx, hypot_ctx and their try_ forms

These functions compute powers, roots and the Euclidean norm.

pub fn Decimal::power_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::pown_ctx(Self, Int, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rootn_ctx(Self, Int, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::hypot_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_power_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_pown_ctx(Self, Int, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_rootn_ctx(Self, Int, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_hypot_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]

power_ctx(x, y) is xyx^y with the General Decimal Arithmetic special cases: an integer exponent is computed by exact repeated multiplication with extra working digits and rounded once; x0.5x^{0.5} is sqrt_ctx; a positive base with a non-integer exponent is certified; a negative base with a non-integer exponent is invalid; 000^0 is invalid in an extended context; 0−n0^{-n} is ±∞\pm\infty. pown_ctx(x, n) is power_ctx with the integer n converted to a Decimal of the context precision. rootn_ctx(x, n) is x1/nx^{1/n} for integer n≠0n \ne 0; an even root of a negative value and n=0n=0 are invalid, and rootn⁡(±0,n<0)\operatorname{rootn}(\pm 0, n<0) is an infinity with division_by_zero. hypot_ctx(x, y) is x2+y2\sqrt{x^2+y^2}; it is +∞+\infty if either operand is infinite, even if the other is a quiet NaN.

Extended elementary functions

These IEEE 754-2019 §9.2 functions have the same f_ctx/try_f_ctx shape.

pub fn Decimal::exp2_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exp10_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::expm1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log2_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log1p_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sin_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::cos_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tan_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sinpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::cospi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tanpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::asin_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::acos_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atan_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atan2_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sinh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::cosh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tanh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::asinh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::acosh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atanh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_exp2_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp10_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_expm1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log2_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log1p_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_sin_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cos_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tan_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_sinpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cospi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tanpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_asin_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_acos_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atan_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atan2_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_sinh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cosh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tanh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_asinh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_acosh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atanh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]

Domain and special values:

FunctionInvalid (invalid_operation)Pole (division_by_zero)Exact cases
exp2, exp10nonenoneinteger argument (via power_ctx), ±0↦1\pm 0 \mapsto 1
expm1nonenone±0↦±0\pm0 \mapsto \pm0, −∞↦−1-\infty\mapsto -1
log2x<0x<0, −∞-\infty±0↦−∞\pm 0 \mapsto -\infty1↦01 \mapsto 0
log1px<−1x<-1, ±∞\pm\infty−1↦−∞-1 \mapsto -\infty±0↦±0\pm0 \mapsto \pm0
sin, cos, tan±∞\pm\inftynonesin⁡(±0)=±0\sin(\pm 0)=\pm 0, cos⁡0=1\cos 0 = 1
sinpi, cospi, tanpi±∞\pm\inftytanpi at odd half-integersintegers and half-integers
asin, acos∣x∣>1\lvert x\rvert > 1, ±∞\pm\inftynoneasin⁡(±0)=±0\operatorname{asin}(\pm0)=\pm0
atannonenone±0\pm 0; ±∞↦±π/2\pm\infty \mapsto \pm\pi/2 (certified)
atan2(y, x)nonenoneatan2⁡(±0,+0)=±0\operatorname{atan2}(\pm 0, +0) = \pm 0
sinh, tanh, asinhnonenone±0↦±0\pm0\mapsto\pm0; tanh⁡(±∞)=±1\tanh(\pm\infty)=\pm 1
coshnonenonecosh⁡0=1\cosh 0 = 1, cosh⁡(±∞)=+∞\cosh(\pm\infty)=+\infty
acoshx<1x < 1, −∞-\inftynone1↦01 \mapsto 0
atanh∣x∣>1\lvert x\rvert>1, ±∞\pm\infty±1↦±∞\pm1 \mapsto \pm\infty±0↦±0\pm0 \mapsto \pm0
///|
test "decimal certified elementary functions" {
  let ctx = @decimal.DecimalContext::decimal64()
  let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
  inspect(d("1").exp_ctx(ctx).0, content="2.718281828459045")
  inspect(d("1000").log10_ctx(ctx).0, content="3")
  inspect(d("0.5").sinpi_ctx(ctx).0, content="1")
  let down = ctx.with_rounding(@def.RoundingMode::TowardZero)
  inspect(d("2").ln_ctx(down).0, content="0.6931471805599453")
  match d("2").try_ln_ctx(@decimal.DecimalContext::new()) {
    Ok((value, flags)) => {
      inspect(value.is_nan(), content="true")
      inspect(flags.invalid_context, content="true")
    }
    Err(_) => fail("not a certification failure")
  }
}

Interchange formats

DecimalInterchangeFormat

DecimalInterchangeFormat names an IEEE 754 decimal interchange format.

pub(all) enum DecimalInterchangeFormat {
  Decimal32
  Decimal64
  Decimal128
}
pub fn DecimalInterchangeFormat::context(Self) -> DecimalContext
pub fn DecimalInterchangeFormat::equal(Self, Self) -> Bool
pub fn DecimalInterchangeFormat::not_equal(Self, Self) -> Bool

context returns DecimalContext::decimal32(), decimal64() or decimal128().

DecimalInterchangeEncoding

DecimalInterchangeEncoding selects how the coefficient is stored in the bits.

pub(all) enum DecimalInterchangeEncoding {
  DPD
  BID
}
pub fn DecimalInterchangeEncoding::equal(Self, Self) -> Bool
pub fn DecimalInterchangeEncoding::not_equal(Self, Self) -> Bool

DPD stores three decimal digits per 10-bit declet (densely packed decimal); BID stores the coefficient as a binary integer. Functions without an encoding argument use DPD.

Decimal::to_interchange_hex, to_interchange_hex_with_encoding

These functions encode a value as interchange bits written in hexadecimal.

pub fn Decimal::to_interchange_hex(Self, DecimalInterchangeFormat) -> (String, DecimalFlags)
pub fn Decimal::to_interchange_hex_with_encoding(Self, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> (String, DecimalFlags)

A finite value is first rounded with apply_ctx under the format context (its flags are returned), then encoded with its exponent, so the cohort is kept when it fits. The text is # followed by 8, 16 or 32 upper-case hex digits. Infinities are encoded with a zero trailing field. A NaN keeps its sign and kind; DPD keeps the low p−1p-1 payload digits, while BID keeps the leading p−1p-1 digits of the payload written with pvalue−1p_{\text{value}}-1 digits, so a payload is only portable to BID when the value’s precision equals the format precision.

Decimal::from_interchange_hex, from_interchange_hex_with_encoding

These functions decode interchange hex text.

pub fn Decimal::from_interchange_hex(String, DecimalInterchangeFormat) -> Self?
pub fn Decimal::from_interchange_hex_with_encoding(String, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> Self?

The text may have surrounding ASCII whitespace and a leading #; it must have exactly the format’s number of hex digits, in either case, or the result is None. Decoding is exact and keeps the exponent, the sign of zero, the NaN kind and payload. Non-canonical encodings decode to the value IEEE 754 assigns them: a non-canonical DPD declet to its digits, a BID coefficient ≥10p\ge 10^{p} to zero, an out-of-range BID NaN payload to 0; the unused exponent bits of infinities and NaNs are ignored. The result has the format’s precision.

///|
test "decimal64 interchange in both encodings" {
  let x = @decimal.Decimal::from_string("1.25").unwrap()
  let fmt = @decimal.DecimalInterchangeFormat::Decimal64
  let (dpd, _) = x.to_interchange_hex(fmt)
  let (bid, _) = x.to_interchange_hex_with_encoding(
    fmt,
    @decimal.DecimalInterchangeEncoding::BID,
  )
  inspect(dpd, content="#22300000000000A5")
  inspect(bid, content="#318000000000007D")
  let back = @decimal.Decimal::from_interchange_hex(dpd, fmt).unwrap()
  inspect(back, content="1.25")
}

DecimalInterchange

DecimalInterchange holds the raw bits of one interchange value together with its format and encoding.

pub struct DecimalInterchange {
  // private fields
}
pub fn DecimalInterchange::format(Self) -> DecimalInterchangeFormat
pub fn DecimalInterchange::encoding(Self) -> DecimalInterchangeEncoding
pub fn DecimalInterchange::to_hex(Self) -> String

Use it when bits must be inspected or kept exactly, including non-canonical encodings that a Decimal cannot represent. to_hex writes # and the full-width upper-case hex digits.

DecimalInterchange::from_hex, from_hex_with_encoding, from_decimal, from_decimal_with_encoding

These functions build an interchange value from text or from a Decimal.

pub fn DecimalInterchange::from_hex(String, DecimalInterchangeFormat) -> Self?
pub fn DecimalInterchange::from_hex_with_encoding(String, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> Self?
pub fn DecimalInterchange::from_decimal(Decimal, DecimalInterchangeFormat) -> (Self, DecimalFlags)
pub fn DecimalInterchange::from_decimal_with_encoding(Decimal, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> (Self, DecimalFlags)

from_hex stores the bits unchanged (text rules as in from_interchange_hex). from_decimal encodes like to_interchange_hex and returns the same flags. The forms without an encoding use DPD.

DecimalInterchange::to_decimal, to_decimal_ctx

These functions decode the stored bits.

pub fn DecimalInterchange::to_decimal(Self) -> Decimal
pub fn DecimalInterchange::to_decimal_ctx(Self) -> (Decimal, DecimalFlags)

Decoding is exact. to_decimal_ctx additionally raises subnormal when the decoded value is subnormal in the format; no other flag is possible.

DecimalInterchange::canonical, is_canonical

These functions canonicalize the stored bits.

pub fn DecimalInterchange::canonical(Self) -> Self
pub fn DecimalInterchange::is_canonical(Self) -> Bool

canonical decodes and re-encodes in the same format and encoding: every non-canonical declet, out-of-range BID coefficient, and unused bit of an infinity or NaN is replaced by its canonical form. It is idempotent. is_canonical tests whether the bits are already canonical.

DecimalInterchange::copy, copy_abs, copy_negate, copy_sign

These functions change only the sign bit of the stored bits.

pub fn DecimalInterchange::copy(Self) -> Self
pub fn DecimalInterchange::copy_abs(Self) -> Self
pub fn DecimalInterchange::copy_negate(Self) -> Self
pub fn DecimalInterchange::copy_sign(Self, Self) -> Self

All other bits, canonical or not, are kept. copy_sign aborts unless both operands have the same format and encoding.

Trait implementations

Algebra traits

Decimal implements the Luna-Flow algebra traits through the plain operators.

pub impl @luna-generic.Zero for Decimal
pub impl @luna-generic.One for Decimal
pub impl @luna-generic.AddMonoid for Decimal
pub impl @luna-generic.MulMonoid for Decimal
pub impl @luna-generic.AddGroup for Decimal
pub impl @luna-generic.Semiring for Decimal
pub impl @luna-generic.Ring for Decimal
pub impl @luna-generic.NatHomomorphism for Decimal
pub impl @luna-generic.IntegralHomomorphism for Decimal
pub impl Add for Decimal
pub impl Sub for Decimal
pub impl Mul for Decimal
pub impl Div for Decimal
pub impl Neg for Decimal
pub impl Eq for Decimal
pub impl Compare for Decimal

Zero::zero() and One::one() are Decimal::zero() and Decimal::one(). The ring laws hold exactly for +, - and * as long as no sum is rounded (sums whose exact coefficient fits the operand precision, and every product, since * is exact); a rounded sum is only approximately associative. from_nat and from_integral are documented under construction.

@def.Floating

Decimal implements the floating scalar trait.

pub impl @def.Floating for Decimal

The trait methods are classify, sign, precision, with_precision and normalized, all documented above; @def.is_finite(x) and the other generic predicates work through it.

Contextual traits

Decimal implements the contextual traits of Luna-Flow/arithmetic.

pub fn Decimal::add_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::sub_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::mul_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::div_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::abs_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::sqrt_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::exp_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::zero_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::one_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::epsilon_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::min_normal_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::max_finite_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::classify_contextual(Self) -> @arithmetic.FpClass
pub impl @arithmetic.AddContextual for Decimal
pub impl @arithmetic.SubContextual for Decimal
pub impl @arithmetic.MulContextual for Decimal
pub impl @arithmetic.DivContextual for Decimal
pub impl @arithmetic.AbsContextual for Decimal
pub impl @arithmetic.SqrtContextual for Decimal
pub impl @arithmetic.ExpContextual for Decimal
pub impl @arithmetic.NumericFormatContextual for Decimal

Each *_contextual operation converts the context with DecimalContext::from_arithmetic_context, runs the matching *_ctx operation and returns Err(division_by_zero) when division_by_zero was raised, Err(domain_error) when another has_error flag was raised, and otherwise Ok with diagnostics inexact, rounded, overflow, underflow, subnormal and clamped copied from the flags. Because the converted context has the default exponent range, exp_contextual without explicit e_min/e_max fails with domain_error (invalid_context).

zero_contextual and one_contextual have the context precision. epsilon_contextual is 101−p10^{1-p} (next_plus(1) - 1). min_normal_contextual is 10emin⁡10^{e_{\min}} (default emin⁡=−999 999 999e_{\min} = -999\,999\,999). max_finite_contextual is (10p−1) 10emax⁡−p+1(10^{p}-1)\,10^{e_{\max}-p+1}. classify_contextual is classify.

Checked traits

Decimal implements the checked traits of Luna-Flow/arithmetic.

pub fn Decimal::parse_checked(String, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::sqrt_checked(Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::pow_nat_checked(Self, UInt, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::pow_int_checked(Self, Int, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub impl @arithmetic.ParseChecked for Decimal
pub impl @arithmetic.DivChecked for Decimal
pub impl @arithmetic.CompareChecked for Decimal
pub impl @arithmetic.SqrtChecked for Decimal
pub impl @arithmetic.PowNatChecked for Decimal
pub impl @arithmetic.PowIntChecked for Decimal

parse_checked(s, ctx) is Decimal::parse(s, precision=ctx.precision). DivChecked::div_checked(x, y, ctx) is div_ctx under the converted context with Err(division_by_zero) and Err(domain_error) as in div_checked. sqrt_checked is sqrt_ctx under the converted context and fails for negative operands. pow_nat_checked and pow_int_checked are power_ctx with the integer exponent converted to a Decimal of the context precision; they return Err(division_by_zero) for a zero base with a negative exponent, Err(domain_error) for an invalid power, and pow_nat_checked returns Err(unsupported) for exponents above 999,999,999. CompareChecked is compare_checked.

Show and Debug

Decimal implements Show and Debug.

pub impl Show for Decimal
pub fn Decimal::to_repr(Self) -> @debug.Repr

Show provides to_string and output. to_repr is the derived structural representation used by debug_inspect and assert_eq.

Complete public interface

This snapshot is the generated pkg.generated.mbti of the package. It is the authority when prose and interface disagree.

// Generated using `moon info`, DON'T EDIT IT
package "Luna-Flow/floating/decimal"

import {
  "Luna-Flow/arithmetic",
  "Luna-Flow/floating/bin_float",
  "Luna-Flow/floating/def",
  "Luna-Flow/luna-generic",
  "moonbitlang/core/bigint",
  "moonbitlang/core/debug",
}

// Values

// Errors

// Types and methods
pub struct Decimal {
  // private fields
} derive(@debug.Debug)
pub fn Decimal::abs(Self) -> Self
pub fn Decimal::abs_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::abs_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::acos_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::acosh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::add(Self, Self) -> Self
pub fn Decimal::add_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::add_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::apply_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::asin_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::asinh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atan2_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atan_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atanh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::clamp(Self, min~ : Self, max~ : Self) -> Self
pub fn Decimal::clamp_checked(Self, min~ : Self, max~ : Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::class_name(Self, DecimalContext) -> String
pub fn Decimal::classify(Self) -> @arithmetic.FpClass
pub fn Decimal::classify_contextual(Self) -> @arithmetic.FpClass
pub fn Decimal::coefficient(Self) -> @bigint.BigInt
pub fn Decimal::compare(Self, Self) -> Int
pub fn Decimal::compare_checked(Self, Self) -> Result[Int, @arithmetic.ArithmeticError]
pub fn Decimal::compare_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::compare_signal_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::compare_total(Self, Self) -> Int
pub fn Decimal::compare_total_ctx(Self, Self, DecimalContext) -> (Int, DecimalFlags)
pub fn Decimal::compare_total_magnitude(Self, Self) -> Int
pub fn Decimal::compare_total_magnitude_ctx(Self, Self, DecimalContext) -> (Int, DecimalFlags)
pub fn Decimal::copy(Self) -> Self
pub fn Decimal::copy_abs(Self) -> Self
pub fn Decimal::copy_negate(Self) -> Self
pub fn Decimal::copy_sign(Self, Self) -> Self
pub fn Decimal::cos_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::cosh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::cospi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::div(Self, Self) -> Self
pub fn Decimal::div_checked(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::div_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::div_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::divide_integer(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::epsilon_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::equal(Self, Self) -> Bool
pub fn Decimal::exp10_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exp2_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exp_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::exp_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::expm1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exponent10(Self) -> Int
pub fn Decimal::fma_ctx(Self, Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::from_bigint(@bigint.BigInt, precision? : Int) -> Self
pub fn Decimal::from_bin_float(@bin_float.BinFloat, precision? : Int) -> Self
pub fn Decimal::from_double(Double, precision? : Int) -> Self
pub fn Decimal::from_float(Float, precision? : Int) -> Self
pub fn Decimal::from_int(Int, precision? : Int) -> Self
pub fn[S : @luna-generic.Integral] Decimal::from_integral(S) -> Self
pub fn Decimal::from_interchange_hex(String, DecimalInterchangeFormat) -> Self?
pub fn Decimal::from_interchange_hex_with_encoding(String, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> Self?
pub fn[S : @luna-generic.Nat] Decimal::from_nat(S) -> Self
pub fn Decimal::from_string(String, precision? : Int) -> Self?
pub fn Decimal::from_string_ctx(String, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::get_payload(Self) -> @bigint.BigInt
pub fn Decimal::hypot_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::inf(@def.Sign, precision? : Int) -> Self
pub fn Decimal::is_canonical(Self) -> Bool
pub fn Decimal::is_finite(Self) -> Bool
pub fn Decimal::is_infinite(Self) -> Bool
pub fn Decimal::is_nan(Self) -> Bool
pub fn Decimal::is_negative(Self) -> Bool
pub fn Decimal::is_negative_zero(Self) -> Bool
pub fn Decimal::is_normal(Self, DecimalContext) -> Bool
pub fn Decimal::is_qnan(Self) -> Bool
pub fn Decimal::is_quiet_nan(Self) -> Bool
pub fn Decimal::is_signaling_nan(Self) -> Bool
pub fn Decimal::is_signed(Self) -> Bool
pub fn Decimal::is_snan(Self) -> Bool
pub fn Decimal::is_subnormal(Self, DecimalContext) -> Bool
pub fn Decimal::is_zero(Self) -> Bool
pub fn Decimal::ln_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log10_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log1p_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log2_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logb_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_and(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_invert(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_or(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_xor(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::magnitude(Self) -> @bigint.BigInt
pub fn Decimal::make(@bigint.BigInt, Int, Int, mode? : @arithmetic.RoundingMode) -> Self
pub fn Decimal::max(Self, Self) -> Self
pub fn Decimal::max_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::max_finite_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::max_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::min(Self, Self) -> Self
pub fn Decimal::min_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::min_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::min_normal_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::minimum_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minus_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::mul(Self, Self) -> Self
pub fn Decimal::mul_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::mul_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::nan(precision? : Int) -> Self
pub fn Decimal::nan_payload(Self) -> @bigint.BigInt
pub fn Decimal::neg(Self) -> Self
pub fn Decimal::negative_zero(precision? : Int) -> Self
pub fn Decimal::next_minus(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_plus(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_toward(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::normalize_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::normalized(Self) -> Self
pub fn Decimal::not_equal(Self, Self) -> Bool
pub fn Decimal::one(precision? : Int) -> Self
pub fn Decimal::one_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::op_ge(Self, Self) -> Bool
pub fn Decimal::op_gt(Self, Self) -> Bool
pub fn Decimal::op_le(Self, Self) -> Bool
pub fn Decimal::op_lt(Self, Self) -> Bool
pub fn Decimal::output(Self, &Logger) -> Unit
pub fn Decimal::parse(String, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::parse_checked(String, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::plus_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::pow_int_checked(Self, Int, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::pow_nat_checked(Self, UInt, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::power_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::pown_ctx(Self, Int, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::precision(Self) -> Int
pub fn Decimal::quantize(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::quantum(Self) -> Int
pub fn Decimal::quiet_nan(payload? : @bigint.BigInt, negative? : Bool, precision? : Int) -> Self
pub fn Decimal::reduce_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder_near(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rescale(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rootn_ctx(Self, Int, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rotate_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::same_quantum(Self, Self) -> Bool
pub fn Decimal::scaleb_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::set_payload(Self, @bigint.BigInt) -> Self
pub fn Decimal::set_payload_signaling(Self, @bigint.BigInt) -> Self
pub fn Decimal::shift_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sign(Self) -> @def.Sign
pub fn Decimal::signaling_nan(payload? : @bigint.BigInt, negative? : Bool, precision? : Int) -> Self
pub fn Decimal::sin_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sinh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sinpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sqrt(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::sqrt_checked(Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::sqrt_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::sqrt_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sub(Self, Self) -> Self
pub fn Decimal::sub_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::sub_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tan_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tanh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tanpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_bin_float(Self, precision? : Int, mode? : @arithmetic.RoundingMode) -> @bin_float.BinFloat
pub fn Decimal::to_eng_string(String, DecimalContext) -> (String, DecimalFlags)
pub fn Decimal::to_integral_exact(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_integral_value(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_interchange_hex(Self, DecimalInterchangeFormat) -> (String, DecimalFlags)
pub fn Decimal::to_interchange_hex_with_encoding(Self, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> (String, DecimalFlags)
pub fn Decimal::to_repr(Self) -> @debug.Repr
pub fn Decimal::to_sci_string(String, DecimalContext) -> (String, DecimalFlags)
pub fn Decimal::to_string(Self) -> String
pub fn Decimal::trim(Self) -> Self
pub fn Decimal::try_acos_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_acosh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_asin_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_asinh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atan2_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atan_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atanh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cos_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cosh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cospi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp10_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp2_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_expm1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_hypot_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_ln_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log10_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log1p_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log2_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_power_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_pown_ctx(Self, Int, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_rootn_ctx(Self, Int, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_sin_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_sinh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_sinpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tan_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tanh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tanpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::with_precision(Self, Int, @arithmetic.RoundingMode) -> Self
pub fn Decimal::zero(precision? : Int) -> Self
pub fn Decimal::zero_contextual(@arithmetic.ArithmeticContext) -> Self
pub impl @arithmetic.AbsContextual for Decimal
pub impl @arithmetic.AddContextual for Decimal
pub impl @arithmetic.CompareChecked for Decimal
pub impl @arithmetic.DivChecked for Decimal
pub impl @arithmetic.DivContextual for Decimal
pub impl @arithmetic.ExpContextual for Decimal
pub impl @arithmetic.MulContextual for Decimal
pub impl @arithmetic.NumericFormatContextual for Decimal
pub impl @arithmetic.ParseChecked for Decimal
pub impl @arithmetic.PowIntChecked for Decimal
pub impl @arithmetic.PowNatChecked for Decimal
pub impl @arithmetic.SqrtChecked for Decimal
pub impl @arithmetic.SqrtContextual for Decimal
pub impl @arithmetic.SubContextual for Decimal
pub impl @def.Floating for Decimal
pub impl @luna-generic.AddGroup for Decimal
pub impl @luna-generic.AddMonoid for Decimal
pub impl @luna-generic.IntegralHomomorphism for Decimal
pub impl @luna-generic.MulMonoid for Decimal
pub impl @luna-generic.NatHomomorphism for Decimal
pub impl @luna-generic.One for Decimal
pub impl @luna-generic.Ring for Decimal
pub impl @luna-generic.Semiring for Decimal
pub impl @luna-generic.Zero for Decimal
pub impl Add for Decimal
pub impl Compare for Decimal
pub impl Div for Decimal
pub impl Eq for Decimal
pub impl Mul for Decimal
pub impl Neg for Decimal
pub impl Show for Decimal
pub impl Sub for Decimal

pub struct DecimalContext {
  // private fields
} derive(Eq)
pub fn DecimalContext::clamp(Self) -> Bool
pub fn DecimalContext::decimal128() -> Self
pub fn DecimalContext::decimal32() -> Self
pub fn DecimalContext::decimal64() -> Self
pub fn DecimalContext::decimal_rounding(Self) -> DecimalRoundingMode
pub fn DecimalContext::e_max(Self) -> Int
pub fn DecimalContext::e_min(Self) -> Int
pub fn DecimalContext::equal(Self, Self) -> Bool
pub fn DecimalContext::exact() -> Self
pub fn DecimalContext::extended(Self) -> Bool
pub fn DecimalContext::from_arithmetic_context(@arithmetic.ArithmeticContext) -> Self
pub fn DecimalContext::ieee754(Self) -> Self
pub fn DecimalContext::is754version2019(Self) -> Bool
pub fn DecimalContext::new(precision? : Int, rounding? : @arithmetic.RoundingMode, decimal_rounding? : DecimalRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, tininess? : DecimalTininessDetection) -> Self
pub fn DecimalContext::not_equal(Self, Self) -> Bool
pub fn DecimalContext::precision(Self) -> Int
pub fn DecimalContext::rounding(Self) -> @arithmetic.RoundingMode
pub fn DecimalContext::tininess(Self) -> DecimalTininessDetection
pub fn DecimalContext::try_new(precision? : Int, rounding? : @arithmetic.RoundingMode, decimal_rounding? : DecimalRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, tininess? : DecimalTininessDetection) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecimalContext::with_rounding(Self, @arithmetic.RoundingMode) -> Self
pub fn DecimalContext::with_tininess(Self, DecimalTininessDetection) -> Self

pub struct DecimalFlags {
  inexact : Bool
  rounded : Bool
  lost_digits : Bool
  invalid_operation : Bool
  division_by_zero : Bool
  overflow : Bool
  underflow : Bool
  subnormal : Bool
  clamped : Bool
  conversion_syntax : Bool
  division_impossible : Bool
  division_undefined : Bool
  invalid_context : Bool
} derive(Eq)
pub fn DecimalFlags::combine(Self, Self) -> Self
pub fn DecimalFlags::contains(Self, DecimalSignal) -> Bool
pub fn DecimalFlags::equal(Self, Self) -> Bool
pub fn DecimalFlags::has_error(Self) -> Bool
pub fn DecimalFlags::new() -> Self
pub fn DecimalFlags::not_equal(Self, Self) -> Bool

pub struct DecimalInterchange {
  // private fields
}
pub fn DecimalInterchange::canonical(Self) -> Self
pub fn DecimalInterchange::copy(Self) -> Self
pub fn DecimalInterchange::copy_abs(Self) -> Self
pub fn DecimalInterchange::copy_negate(Self) -> Self
pub fn DecimalInterchange::copy_sign(Self, Self) -> Self
pub fn DecimalInterchange::encoding(Self) -> DecimalInterchangeEncoding
pub fn DecimalInterchange::format(Self) -> DecimalInterchangeFormat
pub fn DecimalInterchange::from_decimal(Decimal, DecimalInterchangeFormat) -> (Self, DecimalFlags)
pub fn DecimalInterchange::from_decimal_with_encoding(Decimal, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> (Self, DecimalFlags)
pub fn DecimalInterchange::from_hex(String, DecimalInterchangeFormat) -> Self?
pub fn DecimalInterchange::from_hex_with_encoding(String, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> Self?
pub fn DecimalInterchange::is_canonical(Self) -> Bool
pub fn DecimalInterchange::to_decimal(Self) -> Decimal
pub fn DecimalInterchange::to_decimal_ctx(Self) -> (Decimal, DecimalFlags)
pub fn DecimalInterchange::to_hex(Self) -> String

pub(all) enum DecimalInterchangeEncoding {
  DPD
  BID
} derive(Eq)
pub fn DecimalInterchangeEncoding::equal(Self, Self) -> Bool
pub fn DecimalInterchangeEncoding::not_equal(Self, Self) -> Bool

pub(all) enum DecimalInterchangeFormat {
  Decimal32
  Decimal64
  Decimal128
} derive(Eq)
pub fn DecimalInterchangeFormat::context(Self) -> DecimalContext
pub fn DecimalInterchangeFormat::equal(Self, Self) -> Bool
pub fn DecimalInterchangeFormat::not_equal(Self, Self) -> Bool

pub(all) enum DecimalRoundingMode {
  HalfEven
  HalfUp
  HalfDown
  Down
  Ceiling
  Floor
  Up
  ZeroFiveUp
} derive(Eq)
pub fn DecimalRoundingMode::equal(Self, Self) -> Bool
pub fn DecimalRoundingMode::from_arithmetic(@arithmetic.RoundingMode) -> Self
pub fn DecimalRoundingMode::not_equal(Self, Self) -> Bool
pub fn DecimalRoundingMode::to_arithmetic(Self) -> @arithmetic.RoundingMode?

pub(all) enum DecimalSignal {
  ConversionSyntax
  DivisionByZero
  DivisionImpossible
  DivisionUndefined
  InvalidContext
  InvalidOperation
  Overflow
  Underflow
  Subnormal
  Inexact
  Rounded
  Clamped
  LostDigits
} derive(Eq)
pub fn DecimalSignal::equal(Self, Self) -> Bool
pub fn DecimalSignal::not_equal(Self, Self) -> Bool

pub(all) enum DecimalTininessDetection {
  BeforeRounding
  AfterRounding
} derive(Eq)
pub fn DecimalTininessDetection::equal(Self, Self) -> Bool
pub fn DecimalTininessDetection::not_equal(Self, Self) -> Bool

// Type aliases

// Traits