currency

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ZCN  = 1e10
	MZCN = 1e7
	UZCN = 1e4

	ZCNExponent  = 10
	MZCNExponent = 7
	UZCNExponent = 4
)

Variables

View Source
var (
	// ErrNegativeValue is returned if a float value is a negative number
	ErrNegativeValue = errors.New("negative coin value")
	// ErrTooManyDecimals is returned if a value has more than 10 decimal places
	ErrTooManyDecimals = errors.New("too many decimal places")
	// ErrTooLarge is returned if a value is greater than math.MaxInt64
	ErrTooLarge = errors.New("value is too large")

	// ErrUint64MultOverflow is returned if when multiplying uint64 values overflow uint64
	ErrUint64MultOverflow = errors.New("uint64 multiplication overflow")
	// ErrUint64AddOverflow is returned if when adding uint64 values overflow uint64
	ErrUint64AddOverflow = errors.New("uint64 addition overflow")
	// ErrInt64AddOverflow is returned if when adding int64 values overflow int64
	ErrInt64AddOverflow = errors.New("int64 addition overflow")
	// ErrInt32AddOverflow is returned if when adding int32 values overflow int64
	ErrInt32AddOverflow = errors.New("int64 addition overflow")
	// ErrIntAddOverflow is returned if when adding int values overflow int64
	ErrIntAddOverflow = errors.New("int64 addition overflow")
	// ErrUint64MinusOverflow is returned if when subtracting uint64 values overflow uint64
	ErrUint64MinusOverflow = errors.New("uint64 minus overflow")
	// ErrUint64OverflowsInt64 is returned if when converting a uint64 to an int64 overflow int64
	ErrUint64OverflowsInt64 = errors.New("uint64 overflows int64")
	// ErrUint64OverflowsFloat64 is returned if when converting a uint64 to a float64 overflow float64
	ErrUint64OverflowsFloat64 = errors.New("uint64 overflows float64")
	// ErrInt64UnderflowsUint64 is returned if when converting an int64 to a uint64 underflow uint64
	ErrInt64UnderflowsUint64 = errors.New("int64 underflows uint64")
	// ErrFloat64UnderflowsUint64 is returned if when converting an float6464 to a uint64 underflow uint64
	ErrFloat64UnderflowsUint64 = errors.New("float64 underflows uint64")
)

Functions

This section is empty.

Types

type Coin

type Coin uint64

Coin - any quantity that is represented as an integer in the lowest denomination

func AddCoin

func AddCoin(c, b Coin) (Coin, error)

AddCoin adds c and b, returning an error if the values overflow

func AddInt64

func AddInt64(c Coin, a int64) (Coin, error)

AddInt64 adds c and a, returning an error if the values overflow

func DistributeCoin

func DistributeCoin(c Coin, a int64) (oCur, bal Coin, err error)

func Float64ToCoin

func Float64ToCoin(a float64) (Coin, error)

Float64ToCoin converts an float64 to a uint64 Coin, returning an error if the float64 value underflows uint64

func Int64ToCoin

func Int64ToCoin(a int64) (Coin, error)

Int64ToCoin converts an int64 to a uint64 Coin, returning an error if the int64 value underflows uint64

func Min

func Min(a, b Coin) (c Coin)

func MinusCoin

func MinusCoin(c, b Coin) (Coin, error)

MinusCoin subtracts b from c, returning an error if the values overflow

func MinusInt64

func MinusInt64(c Coin, a int64) (Coin, error)

MinusInt64 subtracts a from c, returning an error if the values overflow

func MultCoin

func MultCoin(c, b Coin) (Coin, error)

MultCoin multiplies Coin c by b, returning an error if the values overflow

func MultFloat64

func MultFloat64(c Coin, a float64) (Coin, error)

MultFloat64 multiplies c by a, returning an error if the values overflow

func ParseZCN

func ParseZCN(c float64) (Coin, error)

func (Coin) Float64

func (c Coin) Float64() (float64, error)

Float64 converts c uint64 Coin to a float64, returning an error if the uint64 value overflows float64

func (Coin) Int64

func (c Coin) Int64() (int64, error)

Int64 converts c uint64 Coin to an int64, returning an error if the uint64 value overflows int64

func (Coin) MarshalMsg

func (z Coin) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Coin) Msgsize

func (z Coin) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (Coin) ToZCN

func (c Coin) ToZCN() (float64, error)

func (*Coin) UnmarshalMsg

func (z *Coin) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

Jump to

Keyboard shortcuts

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