Categorygithub.com/ericlagergren/decimal
modulepackage
3.4.0+incompatible
Repository: https://github.com/ericlagergren/decimal.git
Documentation: pkg.go.dev

# README

decimal Build Status GoDoc

decimal implements arbitrary precision, decimal floating-point numbers, per the General Decimal Arithmetic specification.

Features

  • Useful zero values. The zero value of a decimal.Big is 0, just like math/big.

  • Multiple operating modes. Different operating modes allow you to tailor the package's behavior to your needs. The GDA mode strictly implements the GDA specification, while the Go mode implements familiar Go idioms.

  • High performance. decimal is consistently one of the fastest arbitrary-precision decimal floating-point libraries, regardless of language.

  • An extensive math library. The math/ subpackage implements elementary and trigonometric functions, continued fractions, and more.

  • A familiar, idiomatic API. decimal's API follows math/big's API, so there isn't a steep learning curve.

Installation

go get github.com/ericlagergren/decimal

Documentation

GoDoc

Versioning

decimal uses Semantic Versioning. The current version is 3.3.1.

decimal only explicitly supports the two most recent major Go 1.X versions.

License

BSD 3-clause

# Packages

Package math implements various useful mathematical functions and constants.
Package misc contains miscellaneous decimal routes.
Package sql provides the ability to use Big decimals with SQL databases.
Package suite provides a simple API for parsing and using IBM Labs' "Floating-Point Test-Suite for IEEE" This package is deprecated and will be removed in the next major version.

# Functions

BinarySplit sets z to the result of the binary splitting formula and returns z.
BinarySplitDynamic sets z to the result of the binary splitting formula.
Max returns the greater of the provided values.
MaxAbs returns the greater of the absolute value of the provided values.
Min returns the lesser of the provided values.
MinAbs returns the lesser of the absolute value of the provided values.
New creates a new Big decimal with the given value and scale.
Raw directly returns x's raw compact and unscaled values.
WithContext is shorthand to create a Big decimal from a Context.
WithPrecision is shorthand to create a Big decimal with a given precision.

# Constants

no IEEE 754-2008 equivalent.
Clamped occurs if the scale has been modified to fit the constraints of the decimal representation.
ConversionSyntax occurs when a string is converted to a decimal and does not have a valid syntax.
default precision for literals.
DivisionByZero occurs when division is attempted with a finite, non-zero dividend and a divisor with a value of zero.
DivisionImpossible occurs when the result of integer division would contain too many digits (i.e.
DivisionUndefined occurs when division is attempted with in which both the divided and divisor are zero.
GDA strictly adheres to the General Decimal Arithmetic Specification Version 1.70.
Go adheres to typical Go idioms.
Inexact occurs when the result of an operation (e.g.
InsufficientStorage occurs when the system doesn't have enough storage (i.e.
InvalidContext occurs when an invalid context was detected during an operation.
InvalidOperation occurs when: - an operand to an operation is a signaling NaN - an attempt is made to add or subtract infinities of opposite signs - an attempt is made to multiply zero by an infinity of either sign - an attempt is made to divide an infinity by an infinity - the divisor for a remainder operation is zero - the dividend for a remainder operation is an infinity - either operand of the quantize operation is an infinity, or the result of a quantize operation would require greater precision than is available - the operand of the ln or the log10 operation is less than zero - the operand of the square-root operation has a sign of 1 and a non-zero coefficient - both operands of the power operation are zero, or if the left-hand operand is less than zero and the right-hand operand does not have an integral value or is an infinity .
IsCanonical is true since Big decimals are always normalized.
largest allowed Context precision.
largest allowed scale.
smallest allowed Context precision.
smallest allowed scale.
Overflow occurs when the adjusted scale, after rounding, would be greater than MaxScale.
Radix is the base in which decimal arithmetic is performed.
Rounded occurs when the result of an operation is rounded, or if an Overflow/Underflow occurs.
Subnormal ocurs when the result of a conversion or operation is subnormal (i.e.
== IEEE 754-2008 roundTiesToAway.
== IEEE 754-2008 roundTiesToEven.
no IEEE 754-2008 equivalent.
== IEEE 754-2008 roundTowardNegative.
== IEEE 754-2008 roundTowardPositive.
== IEEE 754-2008 roundTowardZero.
Underflow occurs when the result is inexact and the adjusted scale would be smaller (more negative) than MinScale.
no precision, but may error.

# Variables

Context128 is the IEEE 754R Decimal128 format.
Context32 is the IEEE 754R Decimal32 format.
Context64 is the IEEE 754R Decimal64 format.
ContextUnlimited provides unlimited precision decimals.
Regexp matches any valid string representing a decimal that can be passed to SetString.

# Structs

Big is a floating-point, arbitrary-precision It is represented as a number and a scale.
Context is a per-decimal contextual object that governs specific operations.
An ErrNaN is used when a decimal operation would lead to a NaN under IEEE-754 rules.
Term is a specific term in a continued fraction.

# Interfaces

Contexter allows Generators to provide a different Context than z's.
Generator represents a continued fraction.
Lentzer, if implemented, allows Generators to provide their own backing storage for the Lentz function.
Walliser is analogous to Lentzer, except it's for the Wallis function.

# Type aliases

Condition is a bitmask value raised after or during specific operations.
OperatingMode dictates how the decimal approaches specific non-numeric operations like conversions to strings and panicking on NaNs.
Payload is a NaN value's payload.
RoundingMode determines how a decimal will be rounded.
SplitFunc returns the intermediate value for a given n.