Documentation ¶
Index ¶
- Variables
- type Context64
- func (ctx Context64) Add(d, e Decimal64) Decimal64
- func (ctx Context64) FMA(d, e, f Decimal64) Decimal64
- func (ctx Context64) Mul(d, e Decimal64) Decimal64
- func (ctx Context64) MustParse(s string) Decimal64
- func (ctx Context64) Parse(s string) (Decimal64, error)
- func (ctx Context64) Quo(d, e Decimal64) Decimal64
- func (ctx Context64) Round(d, e Decimal64) Decimal64
- func (ctx Context64) Scan(d *Decimal64, state fmt.ScanState, verb rune) error
- func (ctx Context64) Sub(d, e Decimal64) Decimal64
- func (ctx Context64) ToIntegral(d Decimal64) Decimal64
- func (ctx Context64) With(d Decimal64) Contextual
- type Contextual
- type Decimal64
- func (d Decimal64) Abs() Decimal64
- func (d Decimal64) Add(e Decimal64) Decimal64
- func (d Decimal64) Append(buf []byte, format byte, prec int) []byte
- func (d Decimal64) Class() string
- func (d Decimal64) Cmp(e Decimal64) int
- func (d Decimal64) Cmp64(e Decimal64) Decimal64
- func (d Decimal64) CopySign(e Decimal64) Decimal64
- func (d Decimal64) Equal(e Decimal64) bool
- func (d Decimal64) FMA(e, f Decimal64) Decimal64
- func (d Decimal64) Float64() float64
- func (d Decimal64) Format(s fmt.State, verb rune)
- func (d *Decimal64) GobDecode(buf []byte) error
- func (d Decimal64) GobEncode() ([]byte, error)
- func (d Decimal64) Int64() int64
- func (d Decimal64) Int64x() (i int64, exact bool)
- func (d Decimal64) IsInf() bool
- func (d Decimal64) IsInt() bool
- func (d Decimal64) IsNaN() bool
- func (d Decimal64) IsQNaN() bool
- func (d Decimal64) IsSNaN() bool
- func (d Decimal64) IsSubnormal() bool
- func (d Decimal64) IsZero() bool
- func (d Decimal64) Logb() Decimal64
- func (d Decimal64) MarshalBinary() ([]byte, error)
- func (d Decimal64) MarshalJSON() ([]byte, error)
- func (d Decimal64) MarshalText() ([]byte, error)
- func (d Decimal64) Max(e Decimal64) Decimal64
- func (d Decimal64) MaxMag(e Decimal64) Decimal64
- func (d Decimal64) Min(e Decimal64) Decimal64
- func (d Decimal64) MinMag(e Decimal64) Decimal64
- func (d Decimal64) Mul(e Decimal64) Decimal64
- func (d Decimal64) Neg() Decimal64
- func (d Decimal64) NextMinus() Decimal64
- func (d Decimal64) NextPlus() Decimal64
- func (d Decimal64) Quo(e Decimal64) Decimal64
- func (d Decimal64) Round(e Decimal64) Decimal64
- func (d Decimal64) ScaleB(e Decimal64) Decimal64
- func (d Decimal64) ScaleBInt(i int) Decimal64
- func (d *Decimal64) Scan(state fmt.ScanState, verb rune) error
- func (d Decimal64) Sign() int
- func (d Decimal64) Signbit() bool
- func (d Decimal64) Sqrt() Decimal64
- func (d Decimal64) String() string
- func (d Decimal64) Sub(e Decimal64) Decimal64
- func (d Decimal64) Text(format byte, prec int) string
- func (d Decimal64) ToIntegral() Decimal64
- func (d *Decimal64) UnmarshalBinary(data []byte) error
- func (d *Decimal64) UnmarshalJSON(data []byte) error
- func (d *Decimal64) UnmarshalText(text []byte) error
- type Error
- type Rounding
Constants ¶
This section is empty.
Variables ¶
var DefaultContext64 = Context64{Rounding: HalfUp}
DefaultContext64 is the context that arithmetic functions will use in order to do calculations. Setting this context to a different value will globally affect all Decimal64 methods whose behavior depends on context. Note that all such methods are also available as direct methods of Context64. It uses HalfUp rounding.
var DefaultFormatContext64 = Context64{Rounding: HalfEven}
DefaultFormatContext64 is the default context use for formatting Decimal64. Unlike DefaultContext64, it uses HalfEven rounding to conform to standard Go formatting for float types.
var DefaultScanContext64 = DefaultFormatContext64
var E64 = newFromParts(0, -15, 2_718281828459045)
E64 represents the transcendental number e (lim[n→∞](1+1/n)ⁿ).
var ErrNaN64 error = Error("sNaN64")
var Infinity64 = new64(inf64)
Infinity64 is ∞ represented as a Decimal64.
var Max64 = newFromParts(0, expMax, maxSig)
Max64 is the highest finite number representable as a Decimal64. It has the value 9.999999999999999E+384.
var Min64 = newFromParts(0, -398, 1)
Min64 is the closest positive number to zero. It has the value 1E-398.
var NegInfinity64 = new64(neg64 | inf64)
NegInfinity64 is -∞ represented as a Decimal64.
var NegMax64 = newFromParts(1, expMax, maxSig)
NegMax64 is the lowest finite number representable as a Decimal64. It has the value -9.999999999999999E+384.
var NegMin64 = newFromParts(1, -398, 1)
Min64 is the closest negative number to zero. It has the value -1E-398.
var NegOne64 = newFromParts(1, -15, decimal64Base)
NegOne64 is -1 represented as a Decimal64.
var NegZero64 = newFromParts(1, 0, 0)
NegZero64 is -0 represented as a Decimal64. Note that Zero64 != NegZero64, but Zero64.Equal(NegZero64) returns true.
var One64 = newFromParts(0, -15, decimal64Base)
One64 is 1 represented as a Decimal64.
var Pi64 = newFromParts(0, -15, 3_141592653589793)
Pi64 represents the transcendental number π.
var QNaN64 = new64(0x7c << 56)
QNaN64 a quiet NaN represented as a Decimal64.
var SNaN64 = new64(0x7e << 56)
SNaN64 a signalling NaN represented as a Decimal64. Note that the decimal never signals on NaNs but some operations treat sNaN differently to NaN.
var Zero64 = newFromParts(0, 0, 0)
Zero64 is 0 represented as a Decimal64.
Functions ¶
This section is empty.
Types ¶
type Context64 ¶
type Context64 struct { // Rounding sets the rounding behaviour of arithmetic operations. Rounding Rounding }
Context64 may be used to tune the behaviour of arithmetic operations.
func (Context64) MustParse ¶ added in v1.6.0
MustParse64 parses a string as a Decimal64 and returns the value or panics if the string doesn't represent a valid Decimal64.
func (Context64) Parse ¶ added in v1.6.0
Parse64 parses a string representation of a number as a Decimal64.
func (Context64) Round ¶ added in v1.4.0
Round rounds a number to a given power of ten value. The e argument should be a power of ten, such as 1, 10, 100, 1000, etc.
func (Context64) Scan ¶ added in v1.6.0
Scan scans a string into a Decimal64, applying context rounding.
func (Context64) ToIntegral ¶ added in v1.4.0
ToIntegral rounds d to a nearby integer.
func (Context64) With ¶ added in v1.6.0
func (ctx Context64) With(d Decimal64) Contextual
type Contextual ¶ added in v1.6.0
type Contextual struct {
// contains filtered or unexported fields
}
Contextual binds a Decimal64 to a Context64 for greater control of formatting. It implements fmt.Stringer and fmt.Formatter on behalf of the number, using the context to control formatting.
func (Contextual) String ¶ added in v1.6.0
func (c Contextual) String() string
type Decimal64 ¶
type Decimal64 struct {
// contains filtered or unexported fields
}
Decimal64 represents an IEEE 754 64-bit floating point decimal number. It uses the binary representation method. Decimal64 is intentionally a struct to ensure users don't accidentally cast it to uint64.
func MustParse64 ¶
MustParse64 parses a string as a Decimal64 and returns the value or panics if the string doesn't represent a valid Decimal64. It uses DefaultScanContext64.
func New64FromInt64 ¶
New64FromInt64 returns a new Decimal64 with the given value.
func Parse64 ¶
Parse64 parses a string representation of a number as a Decimal64. It uses DefaultScanContext64.
func (Decimal64) Add ¶
Add computes d + e. It uses DefaultContext64 to call Context64.Add.
func (Decimal64) Class ¶
Class returns a string representing the number's 'type' that the decimal is. It can be one of the following:
- "+Normal"
- "-Normal"
- "+Subnormal"
- "-Subnormal"
- "+Zero"
- "-Zero"
- "+Infinity"
- "-Infinity"
- "NaN"
- "sNaN"
func (Decimal64) Cmp ¶
Cmp returns:
-2 if d or e is NaN -1 if d < e 0 if d == e (incl. -0 == 0, -Inf == -Inf, and +Inf == +Inf) +1 if d > e
func (Decimal64) Cmp64 ¶ added in v1.2.0
Cmp64 returns the same output as Cmp as a Decimal64, unless d or e is NaN, in which case it returns a corresponding NaN result.
func (Decimal64) Equal ¶ added in v1.5.0
Equal indicates whether two numbers are equal. It is equivalent to d.Cmp(e) == 0.
func (Decimal64) FMA ¶
FMA computes d × e + f. It uses DefaultContext64 to call Context64.FMA.
func (Decimal64) Int64 ¶
Int64 returns an int64 representation of d, clamped to [math.MinInt64, math.MaxInt64].
func (Decimal64) Int64x ¶ added in v1.8.0
Int64 returns an int64 representation of d, clamped to [math.MinInt64, math.MaxInt64]. The second return value, exact indicates whether New64FromInt64(i) == d.
func (Decimal64) IsSubnormal ¶
IsSubnormal indicates whether d is a subnormal.
func (Decimal64) MarshalBinary ¶ added in v1.2.0
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (Decimal64) MarshalJSON ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Decimal64) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Decimal64) Mul ¶
Mul computes d × e. It uses DefaultContext64 to call Context64.Mul.
func (Decimal64) Quo ¶
Quo computes d ÷ e. It uses DefaultContext64 to call Context64.Quo.
func (Decimal64) Round ¶ added in v1.4.0
Round rounds a number to a given power-of-10 value. The e argument should be a power of ten, such as 1, 10, 100, 1000, etc. It uses DefaultContext64 to call Context64.Round.
func (*Decimal64) Scan ¶
Scan implements fmt.Scanner. It uses DefaultScanContext64.
func (Decimal64) Sub ¶
Sub returns d - e. It uses DefaultContext64 to call Context64.Sub.
func (Decimal64) Text ¶
Text converts the floating-point number x to a string according to the given format and precision prec.
func (Decimal64) ToIntegral ¶ added in v1.4.0
ToIntegral rounds d to a nearby integer. It uses DefaultContext64 to call Context64.ToIntegral.
func (*Decimal64) UnmarshalBinary ¶ added in v1.2.0
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (*Decimal64) UnmarshalJSON ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (*Decimal64) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Rounding ¶ added in v1.5.0
type Rounding int
Rounding defines how arithmetic operations round numbers in certain operations.
const ( // HalfUp rounds to the nearest number, rounding away from zero if the // number is exactly halfway between two possible roundings. HalfUp Rounding = iota // HalfEven rounds to the nearest number, rounding to the nearest even // number if the number is exactly halfway between two possible roundings. HalfEven // Down rounds towards zero. Down )