Documentation ¶
Overview ¶
Package number contains the implementation of the number data type.
Index ¶
- func Add(a, b *apd.Decimal) *apd.Decimal
- func Cmp(a, b *apd.Decimal) int
- func Divide(a, b *apd.Decimal) (*apd.Decimal, error)
- func Format(n *apd.Decimal, precision int) string
- func Int(n *apd.Decimal) int
- func Int64(x *apd.Decimal) int64
- func IsZero(n *apd.Decimal) bool
- func Log(x *apd.Decimal) *apd.Decimal
- func Multiply(a, b *apd.Decimal) *apd.Decimal
- func NewNumber(s string) *apd.Decimal
- func Pow(a, b *apd.Decimal) *apd.Decimal
- func Remainder(a, b *apd.Decimal) (*apd.Decimal, error)
- func Subtract(a, b *apd.Decimal) *apd.Decimal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add(a, b *apd.Decimal) *apd.Decimal
Add returns the result of adding two numbers together.
func Cmp ¶
func Cmp(a, b *apd.Decimal) int
Cmp compares x and y and returns (regardless of the precision):
-1 if x < y 0 if x == y +1 if x > y
func Divide ¶
func Divide(a, b *apd.Decimal) (*apd.Decimal, error)
Divide returns the division of two numbers. If b == 0 an error will be returned and the result is zero.
func Format ¶ added in v0.11.0
Format returns the string representation with the provided precision. If precision is less than 0 then the number is returned exactly. Otherwise, the number will be rounded or zero padded to the precision provided.
func Int ¶ added in v0.11.0
func Int(n *apd.Decimal) int
Int returns the int value. This is only for internal use when we need the actual int for things like array lengths. Non-integers will be truncated (rounded down).
func Int64 ¶ added in v0.11.0
func Int64(x *apd.Decimal) int64
Int64 returns the int64 value. This is only for internal use when we need the actual int for things like array sizes. Non-integers will be truncated (rounded down).
func IsZero ¶ added in v0.11.0
func IsZero(n *apd.Decimal) bool
IsZero returns true if the value is equivalent to zero (at any precision).
func Log ¶ added in v0.12.1
func Log(x *apd.Decimal) *apd.Decimal
Log is the natural logarithm (base e).
func Multiply ¶
func Multiply(a, b *apd.Decimal) *apd.Decimal
Multiply returns the product (multiplication) of two numbers.
func NewNumber ¶
func NewNumber(s string) *apd.Decimal
NewNumber creates a new number from a string that is well formatted.
func Pow ¶ added in v0.11.2
func Pow(a, b *apd.Decimal) *apd.Decimal
Pow returns the result of applying a to the power of b.
func Remainder ¶
func Remainder(a, b *apd.Decimal) (*apd.Decimal, error)
Remainder returns the remainder from the division of two numbers. This is not to be confused with a modulo which also returns the remainder but as an absolute number. The remainder may be negative if one of the inputs are.
Like Divide, if b == 0 an error will be returned and the result will be zero.
Types ¶
This section is empty.