cremath

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Precision is the number of decimal places
	Precision = 36

	// DecimalPrecisionBits is the number of bits required to represent
	// the above precision
	// Ceiling[Log2[10^Precision - 1]]
	DecimalPrecisionBits = 120
)

Variables

View Source
var (
	ErrEmptyDecimalStr      = errors.New("decimal string cannot be empty")
	ErrInvalidDecimalLength = errors.New("invalid decimal length")
	ErrInvalidDecimalStr    = errors.New("invalid decimal string")
)

Decimal errors

Functions

This section is empty.

Types

type BigDec

type BigDec struct {
	// contains filtered or unexported fields
}

func MaxBigDec

func MaxBigDec(d1, d2 BigDec) BigDec

MaxBigDec returns maximum decimal between two.

func MinBigDec

func MinBigDec(d1, d2 BigDec) BigDec

MinBigDec returns minimum decimal between two.

func MustNewBigDecFromStr

func MustNewBigDecFromStr(s string) BigDec

func NewBigDec

func NewBigDec(i int64) BigDec

NewBigDec creates a new BigDec from integer assuming whole number

func NewBigDecFromBigInt

func NewBigDecFromBigInt(i *big.Int) BigDec

NewBigDecFromBigInt creates a new BigDec from big integer assuming whole numbers CONTRACT: prec <= Precision

func NewBigDecFromBigIntWithPrec

func NewBigDecFromBigIntWithPrec(i *big.Int, prec int64) BigDec

NewBigDecFromBigIntWithPrec creates a new BigDec from big integer assuming whole numbers CONTRACT: prec <= Precision

func NewBigDecFromDec

func NewBigDecFromDec(d sdk.Dec) BigDec

func NewBigDecFromInt

func NewBigDecFromInt(i sdk.Int) BigDec

NewBigDecFromInt creates a new BigDec from big integer assuming whole numbers CONTRACT: prec <= Precision

func NewBigDecFromIntWithPrec

func NewBigDecFromIntWithPrec(i sdk.Int, prec int64) BigDec

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

func NewBigDecFromStr

func NewBigDecFromStr(str string) (BigDec, error)

NewBigDecFromStr 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 NewBigDecWithPrec

func NewBigDecWithPrec(i, prec int64) BigDec

NewBigDecWithPrec creates a new BigDec from integer with decimal place at prec CONTRACT: prec <= Precision

func OneBigDec

func OneBigDec() BigDec

func ZeroBigDec

func ZeroBigDec() BigDec

func (BigDec) Abs

func (d BigDec) Abs() BigDec

func (BigDec) Add

func (d BigDec) Add(d2 BigDec) BigDec

func (BigDec) AddMut

func (d BigDec) AddMut(d2 BigDec) BigDec

AddMut sets d to the sum d+d2 and returns d.

func (BigDec) BigInt

func (d BigDec) BigInt() *big.Int

BigInt returns a copy of the underlying big.Int.

func (BigDec) Ceil

func (d BigDec) Ceil() BigDec

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

func (BigDec) Clone

func (d BigDec) Clone() BigDec

Clone performs a deep copy of the receiver and returns the new result.

func (BigDec) Dec

func (d BigDec) Dec() sdk.Dec

func (BigDec) DecRoundUp

func (d BigDec) DecRoundUp() sdk.Dec

func (BigDec) Equal

func (d BigDec) Equal(d2 BigDec) bool

func (BigDec) Format

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

format decimal state

func (BigDec) GT

func (d BigDec) GT(d2 BigDec) bool

func (BigDec) GTE

func (d BigDec) GTE(d2 BigDec) bool

func (BigDec) IsInteger

func (d BigDec) IsInteger() bool

is integer, e.g. decimals are zero

func (BigDec) IsNegative

func (d BigDec) IsNegative() bool

func (BigDec) IsNil

func (d BigDec) IsNil() bool

func (BigDec) IsPositive

func (d BigDec) IsPositive() bool

func (BigDec) IsZero

func (d BigDec) IsZero() bool

func (BigDec) LT

func (d BigDec) LT(d2 BigDec) bool

func (BigDec) LTE

func (d BigDec) LTE(d2 BigDec) bool

func (BigDec) Marshal

func (d BigDec) Marshal() ([]byte, error)

Marshal implements the gogo proto custom type interface.

func (BigDec) MarshalAmino

func (d BigDec) MarshalAmino() ([]byte, error)

func (BigDec) MarshalJSON

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

MarshalJSON marshals the decimal

func (BigDec) MarshalTo

func (d BigDec) MarshalTo(data []byte) (n int, err error)

MarshalTo implements the gogo proto custom type interface.

func (BigDec) MarshalYAML

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

MarshalYAML returns the YAML representation.

func (BigDec) Mul

func (d BigDec) Mul(d2 BigDec) BigDec

func (BigDec) MulInt

func (d BigDec) MulInt(i sdk.Int) BigDec

func (BigDec) MulInt64

func (d BigDec) MulInt64(i int64) BigDec

func (BigDec) MulInt64Mut

func (d BigDec) MulInt64Mut(i int64) BigDec

MulInt64Mut - multiplication with int64

func (BigDec) MulIntMut

func (d BigDec) MulIntMut(i sdk.Int) BigDec

func (BigDec) MulMut

func (d BigDec) MulMut(d2 BigDec) BigDec

MulMut sets d to the product d*d2 and returns d.

func (BigDec) MulRoundUp

func (d BigDec) MulRoundUp(d2 BigDec) BigDec

func (BigDec) MulRoundUpMut

func (d BigDec) MulRoundUpMut(d2 BigDec) BigDec

func (BigDec) MulTruncate

func (d BigDec) MulTruncate(d2 BigDec) BigDec

func (BigDec) MulTruncateMut

func (d BigDec) MulTruncateMut(d2 BigDec) BigDec

func (BigDec) Neg

func (d BigDec) Neg() BigDec

func (BigDec) Power

func (d BigDec) Power(power uint64) BigDec

func (BigDec) PowerMut

func (d BigDec) PowerMut(power uint64) BigDec

PowerMut returns the result of raising to a positive integer power

func (BigDec) Quo

func (d BigDec) Quo(d2 BigDec) BigDec

func (BigDec) QuoInt

func (d BigDec) QuoInt(i sdk.Int) BigDec

func (BigDec) QuoInt64

func (d BigDec) QuoInt64(i int64) BigDec

func (BigDec) QuoInt64Mut

func (d BigDec) QuoInt64Mut(i int64) BigDec

QuoInt64Mut - quotient with int64

func (BigDec) QuoIntMut

func (d BigDec) QuoIntMut(i sdk.Int) BigDec

func (BigDec) QuoMut

func (d BigDec) QuoMut(d2 BigDec) BigDec

QuoMut sets d to the quotient d/d2 and returns z.

func (BigDec) QuoRoundUp

func (d BigDec) QuoRoundUp(d2 BigDec) BigDec

func (BigDec) QuoRoundUpMut

func (d BigDec) QuoRoundUpMut(d2 BigDec) BigDec

func (BigDec) QuoTruncate

func (d BigDec) QuoTruncate(d2 BigDec) BigDec

func (BigDec) QuoTruncateMut

func (d BigDec) QuoTruncateMut(d2 BigDec) BigDec

func (BigDec) Size

func (d BigDec) Size() int

Size implements the gogo proto custom type interface.

func (BigDec) Sqrt

func (d BigDec) Sqrt() BigDec

func (BigDec) SqrtMut

func (d BigDec) SqrtMut() BigDec

func (BigDec) String

func (d BigDec) String() string

func (BigDec) Sub

func (d BigDec) Sub(d2 BigDec) BigDec

func (BigDec) SubMut

func (d BigDec) SubMut(d2 BigDec) BigDec

SubMut sets d to the difference d-d2 and returns d.

func (BigDec) Truncate

func (d BigDec) Truncate() BigDec

Truncate truncates the decimals from the number and returns a BigDec

func (BigDec) TruncateInt

func (d BigDec) TruncateInt() sdk.Int

TruncateInt truncates the decimals from the number and returns an Int

func (*BigDec) Unmarshal

func (d *BigDec) Unmarshal(data []byte) error

Unmarshal implements the gogo proto custom type interface.

func (*BigDec) UnmarshalAmino

func (d *BigDec) UnmarshalAmino(bz []byte) error

func (*BigDec) UnmarshalJSON

func (d *BigDec) 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