number

package
v0.23.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package number contains the implementation of the number data type.

Index

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

func Format(n *apd.Decimal, precision int) string

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.

func Subtract

func Subtract(a, b *apd.Decimal) *apd.Decimal

Subtract returns the result of subtracting two numbers together.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL