numeric

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: LGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Precision = 18

	// bytes required to represent the above precision
	// Ceiling[Log2[999 999 999 999 999 999]]
	DecimalPrecisionBits = 60
)

number of decimal places

Variables

This section is empty.

Functions

func DecsEqual

func DecsEqual(d1s, d2s []Dec) bool

DecsEqual test if two decimal arrays are equal

Types

type Dec

type Dec struct {
	*big.Int `json:"int"`
}

Dec represent a decimal. NOTE: never use new(Dec) or else we will panic unmarshalling into the nil embedded big.Int

func MaxDec

func MaxDec(d1, d2 Dec) Dec

MaxDec maximum decimal between two

func MinDec

func MinDec(d1, d2 Dec) Dec

MinDec minimum decimal between two

func MustNewDecFromStr

func MustNewDecFromStr(s string) Dec

MustNewDecFromStr Decimal from string, panic on error

func NewDec

func NewDec(i int64) Dec

NewDec creates a new Dec from integer assuming whole number

func NewDecFromBigInt

func NewDecFromBigInt(i *big.Int) Dec

NewDecFromBigInt creates a new Dec from big integer assuming whole numbers CONTRACT: prec <= Precision

func NewDecFromBigIntWithPrec

func NewDecFromBigIntWithPrec(i *big.Int, prec int64) Dec

NewDecFromBigIntWithPrec creates a new Dec from big integer assuming whole numbers CONTRACT: prec <= Precision

func NewDecFromHex

func NewDecFromHex(str string) Dec

NewDecFromHex Assumes Hex string input Split into 2 64 bit integers to guarentee 128 bit precision

func NewDecFromInt

func NewDecFromInt(i *big.Int) Dec

NewDecFromInt creates a new Dec from big integer assuming whole numbers CONTRACT: prec <= Precision

func NewDecFromIntWithPrec

func NewDecFromIntWithPrec(i *big.Int, prec int64) Dec

NewDecFromIntWithPrec creates a new Dec from big integer with decimal place at prec CONTRACT: prec <= Precision

func NewDecFromStr

func NewDecFromStr(str string) (d Dec, err error)

NewDecFromStr creates a decimal from an input decimal string. valid must come in the form:

(-) whole integers (.) decimal integers

examples of acceptable input include:

-123.456
456.7890
345
-456789

NOTE - An error will return if more decimal places are provided in the string than the constant Precision.

CONTRACT - This function does not mutate the input str.

func NewDecFromString

func NewDecFromString(i string) (Dec, error)

NewDecFromString from string to DEC

func NewDecWithPrec

func NewDecWithPrec(i, prec int64) Dec

NewDecWithPrec creates a new Dec from integer with decimal place at prec CONTRACT: prec <= Precision

func OneDec

func OneDec() Dec

OneDec ...

func Pow

func Pow(base Dec, exp int) Dec

Pow calcs power of numeric with int

func SmallestDec

func SmallestDec() Dec

SmallestDec ...

func ZeroDec

func ZeroDec() Dec

ZeroDec ...

func (Dec) Abs

func (d Dec) Abs() Dec

Abs ...

func (Dec) Add

func (d Dec) Add(d2 Dec) Dec

Add addition

func (Dec) Ceil

func (d Dec) Ceil() Dec

Ceil returns the smallest interger value (as a decimal) that is greater than or equal to the given decimal.

func (Dec) Equal

func (d Dec) Equal(d2 Dec) bool

Equal ...

func (Dec) Format

func (d Dec) Format(s fmt.State, verb rune)

Format decimal state

func (Dec) GT

func (d Dec) GT(d2 Dec) bool

GT ...

func (Dec) GTE

func (d Dec) GTE(d2 Dec) bool

GTE ...

func (Dec) IsInteger

func (d Dec) IsInteger() bool

IsInteger is integer, e.g. decimals are zero

func (Dec) IsNegative

func (d Dec) IsNegative() bool

IsNegative ...

func (Dec) IsNil

func (d Dec) IsNil() bool

IsNil ...

func (Dec) IsPositive

func (d Dec) IsPositive() bool

IsPositive ...

func (Dec) IsZero

func (d Dec) IsZero() bool

IsZero ...

func (Dec) LT

func (d Dec) LT(d2 Dec) bool

LT ...

func (Dec) LTE

func (d Dec) LTE(d2 Dec) bool

LTE ...

func (Dec) MarshalJSON

func (d Dec) MarshalJSON() ([]byte, error)

MarshalJSON marshals the decimal

func (Dec) MarshalYAML

func (d Dec) MarshalYAML() (interface{}, error)

MarshalYAML returns Ythe AML representation.

func (Dec) Mul

func (d Dec) Mul(d2 Dec) Dec

Mul multiplication

func (Dec) MulInt

func (d Dec) MulInt(i *big.Int) Dec

MulInt multiplication

func (Dec) MulInt64

func (d Dec) MulInt64(i int64) Dec

MulInt64 - multiplication with int64

func (Dec) MulTruncate

func (d Dec) MulTruncate(d2 Dec) Dec

MulTruncate multiplication truncate

func (Dec) Neg

func (d Dec) Neg() Dec

Neg ...

func (Dec) Quo

func (d Dec) Quo(d2 Dec) Dec

Quo quotient

func (Dec) QuoInt

func (d Dec) QuoInt(i *big.Int) Dec

QuoInt quotient

func (Dec) QuoInt64

func (d Dec) QuoInt64(i int64) Dec

QuoInt64 - quotient with int64

func (Dec) QuoRoundUp

func (d Dec) QuoRoundUp(d2 Dec) Dec

QuoRoundUp quotient, round up

func (Dec) QuoTruncate

func (d Dec) QuoTruncate(d2 Dec) Dec

QuoTruncate quotient truncate

func (Dec) RoundInt

func (d Dec) RoundInt() *big.Int

RoundInt round the decimal using bankers rounding

func (Dec) RoundInt64

func (d Dec) RoundInt64() int64

RoundInt64 rounds the decimal using bankers rounding

func (Dec) String

func (d Dec) String() string

func (Dec) Sub

func (d Dec) Sub(d2 Dec) Dec

Sub subtraction

func (Dec) TruncateDec

func (d Dec) TruncateDec() Dec

TruncateDec truncates the decimals from the number and returns a Dec

func (Dec) TruncateInt

func (d Dec) TruncateInt() *big.Int

TruncateInt truncates the decimals from the number and returns an Int

func (Dec) TruncateInt64

func (d Dec) TruncateInt64() int64

TruncateInt64 truncates the decimals from the number and returns an int64

func (*Dec) UnmarshalJSON

func (d *Dec) UnmarshalJSON(bz []byte) error

UnmarshalJSON defines custom decoding scheme

Jump to

Keyboard shortcuts

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