Versions in this module Expand all Collapse all v1 v1.0.0 Nov 10, 2026 Changes in this version + func FromFloat64ToExponent(f float64, exponent int32, mode RoundingMode) (Decimal, Conditions, error) + func FromFloat64ToExponentWithBudget(f float64, exponent int32, mode RoundingMode, budget Budget) (Decimal, Conditions, error) + func FromFloat64WithContext(f float64, ctx Context) (Decimal, Conditions, error) + func FromRatToExponent(r *big.Rat, targetExponent int32, mode RoundingMode) (Decimal, Conditions, error) + func FromRatToExponentWithBudget(r *big.Rat, targetExponent int32, mode RoundingMode, budget Budget) (Decimal, Conditions, error) + func FromRatWithContext(r *big.Rat, ctx Context) (Decimal, Conditions, error) + func ParseToExponentWithBudget[T Literal](s T, exponent int32, mode RoundingMode, budget Budget) (Decimal, Conditions, error) + func ParseToExponent[T Literal](s T, exponent int32, mode RoundingMode) (Decimal, Conditions, error) + func ParseWithContext[T Literal](s T, ctx Context) (Decimal, Conditions, error) + type Budget struct + MaxDigits uint64 + MaxInputBytes uint64 + MaxInputDigits uint64 + MaxOutputBytes uint64 + MaxWork uint64 + type Conditions uint16 + const Clamped + const ConversionSyntax + const Decreased + const DivisionByZero + const DivisionImpossible + const DivisionUndefined + const Increased + const Inexact + const InsufficientStorage + const InvalidContext + const InvalidOperation + const Overflow + const Rounded + const Subnormal + const Underflow + func (c Conditions) Direction() int + func (c Conditions) String() string + type Context struct + func Decimal128Context() Context + func Decimal32Context() Context + func Decimal64Context() Context + func NewContext(precision uint32, rounding RoundingMode, guards *ExponentGuards, ...) (Context, error) + func (c Context) Budget() Budget + func (c Context) ExponentGuards() (ExponentGuards, bool) + func (c Context) Precision() uint32 + func (c Context) Rounding() RoundingMode + func (c Context) Traps() Conditions + func (c Context) WithBudget(b Budget) Context + func (c Context) WithGuards(g ExponentGuards) (Context, error) + func (c Context) WithPrecision(p uint32) (Context, error) + func (c Context) WithRounding(m RoundingMode) (Context, error) + func (c Context) WithTraps(traps Conditions) (Context, error) + func (c Context) WithoutGuards() Context + type Cost struct + Digits uint64 + HeapBytes uint64 + InputBytes uint64 + InputDigits uint64 + OutputBytes uint64 + WorkUnits uint64 + func EstimateAdd(x, y Shape, ctx Context) (Cost, error) + func EstimateBigInt(x Shape) (Cost, error) + func EstimateCompose(coefficientBytes uint64) (Cost, error) + func EstimateDiv(x, y Shape, ctx Context) (Cost, error) + func EstimateDivToExponent(x, y Shape, target int32) (Cost, error) + func EstimateEngineering(x Shape) (Cost, error) + func EstimateFMA(x, y, z Shape, ctx Context) (Cost, error) + func EstimateFixed(x Shape, fractionalDigits uint64, mode RoundingMode) (Cost, error) + func EstimateFromBigInt(bitLen uint64) (Cost, error) + func EstimateFromFloat64(f float64, ctx Context) (Cost, error) + func EstimateFromFloat64ToExponent(f float64, target int32) (Cost, error) + func EstimateFromRat(numBits, denBits uint64, ctx Context) (Cost, error) + func EstimateFromRatToExponent(numBits, denBits uint64, target int32) (Cost, error) + func EstimateMul(x, y Shape, ctx Context) (Cost, error) + func EstimateNewTwosComplement(bytes uint64) (Cost, error) + func EstimateParse(inputBytes uint64, ctx Context) (Cost, error) + func EstimateParseJSON(rawBytes uint64, budget Budget) (Cost, error) + func EstimateParseToExponent(inputBytes uint64, target int32, budget Budget) (Cost, error) + func EstimatePow(x Shape, n int32, ctx Context) (Cost, error) + func EstimateQuantize(x Shape, target int32, ctx Context) (Cost, error) + func EstimateQuo(x, y Shape, ctx Context) (Cost, error) + func EstimateRat(x Shape) (Cost, error) + func EstimateRem(x, y Shape, ctx Context) (Cost, error) + func EstimateRemNear(x, y Shape, ctx Context) (Cost, error) + func EstimateRoundToIntegral(x Shape, ctx Context) (Cost, error) + func EstimateRoundToMultiple(x, m Shape) (Cost, error) + func EstimateRoundToPrecision(x Shape, ctx Context) (Cost, error) + func EstimateScan(src any, budget Budget) (Cost, error) + func EstimateScientific(x Shape, significantDigits uint64, mode RoundingMode) (Cost, error) + func EstimateSqrt(x Shape, ctx Context) (Cost, error) + func EstimateSub(x, y Shape, ctx Context) (Cost, error) + func EstimateSum(s SumShape) (Cost, error) + func (c Cost) Budget() Budget + func (c Cost) Max(o Cost) Cost + type Decimal struct + func FromBigInt(value *big.Int) (Decimal, error) + func FromBigIntWithBudget(value *big.Int, budget Budget) (Decimal, error) + func FromFloat64(f float64) (Decimal, error) + func FromFloat64Exact(f float64) (Decimal, error) + func FromInt64(value int64) Decimal + func FromRat(r *big.Rat) (Decimal, error) + func FromUint64(value uint64) Decimal + func MustParse[T Literal](s T) Decimal + func New(coefficient int64, exponent int32) Decimal + func NewInt128(hi int64, lo uint64, exponent int32) Decimal + func NewTwosComplement(b []byte, order binary.ByteOrder, exponent int32) (Decimal, error) + func NewTwosComplementWithBudget(b []byte, order binary.ByteOrder, exponent int32, budget Budget) (Decimal, error) + func One() Decimal + func ParseJSONWithBudget(raw []byte, budget Budget) (Decimal, error) + func Parse[T Literal](s T) (Decimal, error) + func Sum(values ...Decimal) (Decimal, error) + func SumWithBudget(values []Decimal, budget Budget) (Decimal, error) + func Zero() Decimal + func (d *Decimal) Compose(form byte, negative bool, coefficient []byte, exponent int32) error + func (d *Decimal) ComposeWithBudget(form byte, negative bool, coefficient []byte, exponent int32, budget Budget) error + func (d *Decimal) Scan(src any) error + func (d *Decimal) ScanWithBudget(src any, budget Budget) error + func (d *Decimal) UnmarshalJSON(raw []byte) error + func (d *Decimal) UnmarshalText(text []byte) error + func (d Decimal) Abs() Decimal + func (d Decimal) Acos() (Decimal, error) + func (d Decimal) AcosWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Acosh() (Decimal, error) + func (d Decimal) AcoshWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Add(other Decimal) (Decimal, error) + func (d Decimal) AddWithContext(other Decimal, ctx Context) (Decimal, Conditions, error) + func (d Decimal) AppendEngineering(dst []byte, budget Budget) ([]byte, error) + func (d Decimal) AppendFixed(dst []byte, fractionalDigits uint64, options DisplayOptions) ([]byte, error) + func (d Decimal) AppendScientific(dst []byte, significantDigits uint64, options DisplayOptions) ([]byte, error) + func (d Decimal) AppendText(b []byte) ([]byte, error) + func (d Decimal) AppendTwosComplement(dst []byte, width int, order binary.ByteOrder) ([]byte, error) + func (d Decimal) Asin() (Decimal, error) + func (d Decimal) AsinWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Asinh() (Decimal, error) + func (d Decimal) AsinhWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Atan() (Decimal, error) + func (d Decimal) Atan2(x Decimal) (Decimal, error) + func (d Decimal) Atan2WithContext(x Decimal, ctx Context) (Decimal, Conditions, error) + func (d Decimal) AtanWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Atanh() (Decimal, error) + func (d Decimal) AtanhWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) BigInt(z *big.Int) (*big.Int, error) + func (d Decimal) BigIntWithBudget(z *big.Int, budget Budget) (*big.Int, error) + func (d Decimal) CoefficientDigits() uint64 + func (d Decimal) CoefficientInt128() (hi int64, lo uint64, ok bool) + func (d Decimal) Compare(other Decimal) int + func (d Decimal) CompareFloat64(f float64) (int, error) + func (d Decimal) Cos() (Decimal, error) + func (d Decimal) CosWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Cosh() (Decimal, error) + func (d Decimal) CoshWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Div(other Decimal) (Decimal, error) + func (d Decimal) DivToExponent(other Decimal, targetExponent int32, mode RoundingMode) (Decimal, Conditions, error) + func (d Decimal) DivToExponentWithBudget(other Decimal, targetExponent int32, mode RoundingMode, budget Budget) (Decimal, Conditions, error) + func (d Decimal) DivWithContext(other Decimal, ctx Context) (Decimal, Conditions, error) + func (d Decimal) Engineering() (string, error) + func (d Decimal) EngineeringWithBudget(budget Budget) (string, error) + func (d Decimal) Equal(other Decimal) bool + func (d Decimal) Exp() (Decimal, error) + func (d Decimal) ExpWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Exponent() int32 + func (d Decimal) FMAWithContext(y, z Decimal, ctx Context) (Decimal, Conditions, error) + func (d Decimal) Fixed(fractionalDigits uint64) (string, error) + func (d Decimal) FixedWithOptions(fractionalDigits uint64, options DisplayOptions) (string, error) + func (d Decimal) Float64() (float64, Conditions) + func (d Decimal) Float64Rounded(mode RoundingMode) (float64, Conditions, error) + func (d Decimal) Format(state fmt.State, verb rune) + func (d Decimal) Int64() (int64, error) + func (d Decimal) IsZero() bool + func (d Decimal) Ln() (Decimal, error) + func (d Decimal) LnWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Log10() (Decimal, error) + func (d Decimal) Log10WithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) MarshalJSON() ([]byte, error) + func (d Decimal) MarshalText() ([]byte, error) + func (d Decimal) Max(other Decimal) Decimal + func (d Decimal) Min(other Decimal) Decimal + func (d Decimal) Mul(other Decimal) (Decimal, error) + func (d Decimal) MulWithContext(other Decimal, ctx Context) (Decimal, Conditions, error) + func (d Decimal) Neg() Decimal + func (d Decimal) Pow(n int32) (Decimal, error) + func (d Decimal) PowDecimal(y Decimal) (Decimal, error) + func (d Decimal) PowDecimalWithContext(y Decimal, ctx Context) (Decimal, Conditions, error) + func (d Decimal) PowWithContext(n int32, ctx Context) (Decimal, Conditions, error) + func (d Decimal) Quantize(targetExponent int32, mode RoundingMode) (Decimal, Conditions, error) + func (d Decimal) QuantizeWithContext(targetExponent int32, ctx Context) (Decimal, Conditions, error) + func (d Decimal) Quo(other Decimal) (Decimal, error) + func (d Decimal) QuoWithContext(other Decimal, ctx Context) (Decimal, Conditions, error) + func (d Decimal) Rat(z *big.Rat) (*big.Rat, error) + func (d Decimal) RatWithBudget(z *big.Rat, budget Budget) (*big.Rat, error) + func (d Decimal) Reduce() Decimal + func (d Decimal) Rem(other Decimal) (Decimal, error) + func (d Decimal) RemNear(other Decimal) (Decimal, error) + func (d Decimal) RemNearWithContext(other Decimal, ctx Context) (Decimal, Conditions, error) + func (d Decimal) RemWithContext(other Decimal, ctx Context) (Decimal, Conditions, error) + func (d Decimal) RoundToIntegral(mode RoundingMode) (Decimal, Conditions, error) + func (d Decimal) RoundToIntegralWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) RoundToMultiple(m Decimal, mode RoundingMode) (Decimal, Conditions, error) + func (d Decimal) RoundToMultipleWithBudget(m Decimal, mode RoundingMode, budget Budget) (Decimal, Conditions, error) + func (d Decimal) RoundToPrecision(precision uint32, mode RoundingMode) (Decimal, Conditions, error) + func (d Decimal) RoundToPrecisionWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Scientific(significantDigits uint64) (string, error) + func (d Decimal) ScientificWithOptions(significantDigits uint64, options DisplayOptions) (string, error) + func (d Decimal) Shape() Shape + func (d Decimal) Sign() int + func (d Decimal) Sin() (Decimal, error) + func (d Decimal) SinWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Sinh() (Decimal, error) + func (d Decimal) SinhWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Sqrt() (Decimal, error) + func (d Decimal) SqrtWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) String() string + func (d Decimal) Sub(other Decimal) (Decimal, error) + func (d Decimal) SubWithContext(other Decimal, ctx Context) (Decimal, Conditions, error) + func (d Decimal) Tan() (Decimal, error) + func (d Decimal) TanWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Tanh() (Decimal, error) + func (d Decimal) TanhWithContext(ctx Context) (Decimal, Conditions, error) + func (d Decimal) Text(maxBytes uint64) (string, error) + func (d Decimal) Uint64() (uint64, error) + func (d Decimal) Value() (driver.Value, error) + type DisplayOptions struct + Budget Budget + Mode RoundingMode + type Error struct + Code ErrorCode + Condition Conditions + Input string + Limit uint64 + Op string + Remedy string + Resource EvaluationResource + func (e *Error) Error() string + func (e *Error) Is(target error) bool + func (e *Error) Unwrap() error + type ErrorCode uint8 + const ErrConversionSyntax + const ErrDivisionByZero + const ErrDivisionImpossible + const ErrDivisionUndefined + const ErrEvaluationBoundOverflow + const ErrEvaluationBudgetRequired + const ErrExponentRange + const ErrInexact + const ErrInsufficientStorage + const ErrIntegerRange + const ErrInvalidContext + const ErrInvalidOperation + const ErrNonIntegral + const ErrOverflow + const ErrRounded + const ErrSubnormal + const ErrUnderflow + func (c ErrorCode) Error() string + type EvaluationBound struct + HeapBytes uint64 + Units uint64 + func BoundEvaluation(budget Budget) (EvaluationBound, error) + type EvaluationResource uint8 + const EvaluationCoefficientDigits + const EvaluationUnits + type ExponentGuards struct + Emax int32 + Emin int32 + type Hasher struct + func (Hasher) Equal(x, y Decimal) bool + func (Hasher) Hash(h *maphash.Hash, value Decimal) + type Literal interface + type NullDecimal struct + Decimal Decimal + Valid bool + func (n *NullDecimal) Scan(src any) error + func (n *NullDecimal) ScanWithBudget(src any, budget Budget) error + func (n *NullDecimal) UnmarshalJSON(raw []byte) error + func (n NullDecimal) MarshalJSON() ([]byte, error) + func (n NullDecimal) Value() (driver.Value, error) + type RoundingMode uint8 + const AwayFromZero + const Exact + const TiesAwayFromZero + const TiesToEven + const TiesTowardZero + const TowardNegativeInfinity + const TowardPositiveInfinity + const TowardZero + func (m RoundingMode) String() string + type SQLDecimal struct + Decimal Decimal + func (v SQLDecimal) Decompose(buf []byte) (form byte, negative bool, coefficient []byte, exponent int32) + type Shape struct + Digits uint64 + Exponent int32 + Negative bool + type SumShape struct + Count int + Digits uint64 + MaxAdjusted int64 + MinExponent int32 + Nonzero bool + func ShapeOfSum(values ...Decimal) SumShape