num

package
v0.42.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UintToString

func UintToString(u *Uint) string

UintToString convert a uint to uint64 return "0" if nil.

func UintToUint64

func UintToUint64(u *Uint) uint64

UintToUint64 convert a uint to uint64 return 0 if nil.

Types

type DChain

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

DChain ...

func DecChain

func DecChain(d Decimal) *DChain

DecChain offers the same chainable interface for decimals.

func UintDecChain

func UintDecChain(u *Uint) *DChain

UintDecChain returns a chainable decimal from a given uint this moves the conversion stuff out from the caller.

func (*DChain) Add

func (d *DChain) Add(vals ...Decimal) *DChain

Add adds any number of decimals together.

func (*DChain) Div

func (d *DChain) Div(x Decimal) *DChain

Div divides.

func (*DChain) DivRound

func (d *DChain) DivRound(x Decimal, precision int32) *DChain

DivRound divides with a specified precision.

func (*DChain) Get

func (d *DChain) Get() Decimal

Get returns the final value.

func (*DChain) GetUint

func (d *DChain) GetUint(round DecRounding) (*Uint, bool)

GetUint returns the decimal as a uint, returns true on overflow pass in type of rounding to apply not that the rounding does not affect the underlying decimal value rounding is applied to a copy only.

func (*DChain) Mul

func (d *DChain) Mul(x Decimal) *DChain

Mul multiplies, obviously.

func (*DChain) Sub

func (d *DChain) Sub(vals ...Decimal) *DChain

Sub subtracts any number of decimals from the chainable value.

type DecRounding

type DecRounding int

DecRounding ...

const (
	DecFloor DecRounding = iota
	DecRound
	DecCeil
)

constants.

type Decimal

type Decimal = decimal.Decimal

Decimal is a shopspring.Decimal.

func DecimalFromFloat

func DecimalFromFloat(v float64) Decimal

DecimalFromFloat ...

func DecimalFromInt64

func DecimalFromInt64(i int64) Decimal

DecimalFromInt64 ...

func DecimalFromString

func DecimalFromString(s string) (Decimal, error)

DecimalFromString ...

func DecimalFromUint

func DecimalFromUint(u *Uint) Decimal

DecimalFromUint ...

func DecimalZero

func DecimalZero() Decimal

DecimalZero ...

func MaxD

func MaxD(a, b Decimal) Decimal

MaxD ...

func MaxDecimal

func MaxDecimal() Decimal

MaxDecimal ...

func MinD

func MinD(a, b Decimal) Decimal

MinD ...

func NewDecimalFromBigInt

func NewDecimalFromBigInt(value *big.Int, exp int32) Decimal

NewDecimalFromBigInt ...

func NewDecimalFromFloat

func NewDecimalFromFloat(f float64) Decimal

NewDecimalFromFloat ...

type Int

type Int struct {
	// The unsigned version of the integer.
	U *Uint
	// contains filtered or unexported fields
}

Int a wrapper to a signed big int.

func IntFromUint

func IntFromUint(u *Uint, s bool) *Int

IntFromUint ...

func NewInt

func NewInt(val int64) *Int

NewInt creates a new Int with the value of the int64 passed as a parameter.

func NewIntFromUint

func NewIntFromUint(val *Uint) *Int

NewIntFromUint creates a new Int with the value of the uint passed as a parameter.

func (*Int) Add

func (i *Int) Add(a *Int) *Int

Add will add the passed in value to the base value i = i + a.

func (*Int) AddSum

func (i *Int) AddSum(vals ...*Int) *Int

AddSum adds all of the parameters to i i = i + a + b + c.

func (Int) Clone

func (i Int) Clone() *Int

Clone creates a copy of the object so nothing is shared.

func (*Int) FlipSign

func (i *Int) FlipSign()

FlipSign changes the sign of the number from - to + and back again.

func (Int) GT

func (i Int) GT(o *Int) bool

GT returns if i > o.

func (Int) Int64

func (i Int) Int64() int64

Int64 ...

func (*Int) IsNegative

func (i *Int) IsNegative() bool

IsNegative tests if the stored value is negative true if < 0 false if >= 0.

func (*Int) IsPositive

func (i *Int) IsPositive() bool

IsPositive tests if the stored value is positive true if > 0 false if <= 0.

func (*Int) IsZero

func (i *Int) IsZero() bool

IsZero tests if the stored value is zero true if == 0.

func (Int) LT

func (i Int) LT(o *Int) bool

LT returns if i < o.

func (Int) String

func (i Int) String() string

String returns a string version of the number.

func (*Int) Sub

func (i *Int) Sub(a *Int) *Int

Sub will subtract the passed in value from the base value i = i - a.

func (*Int) SubSum

func (i *Int) SubSum(vals ...*Int) *Int

SubSum subtracts all of the parameters from i i = i - a - b - c.

type UChain

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

UChain ...

func UintChain

func UintChain(z *Uint) *UChain

UintChain returns a Uint that supports chainable operations The Uint passed to the constructor is the value that will be updated, so be careful Things like x := NewUint(0).Add(y, z) x.Mul(x, foo) can be written as: x := UintChain(NewUint(0)).Add(y, z).Mul(foo).Get().

func (*UChain) Add

func (c *UChain) Add(vals ...*Uint) *UChain

Add is equivalent to AddSum.

func (*UChain) Div

func (c *UChain) Div(x *Uint) *UChain

Div divides the current value by x.

func (*UChain) Get

func (c *UChain) Get() *Uint

Get gets the result of the chained operation (the value of the wrapped uint).

func (*UChain) Mul

func (c *UChain) Mul(x *Uint) *UChain

Mul multiplies the current value by x.

func (*UChain) Sub

func (c *UChain) Sub(vals ...*Uint) *UChain

Sub subtracts any numbers from the chainable value.

type Uint

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

Uint A wrapper for a big unsigned int.

func Max

func Max(a, b *Uint) *Uint

Max returns the largest of the 2 numbers.

func MaxUint

func MaxUint() *Uint

MaxUint returns max value for uint256.

func Min

func Min(a, b *Uint) *Uint

Min returns the smallest of the 2 numbers.

func NewUint

func NewUint(val uint64) *Uint

NewUint creates a new Uint with the value of the uint64 passed as a parameter.

func Sum

func Sum(vals ...*Uint) *Uint

Sum just removes the need to write num.NewUint(0).Sum(x, y, z) so you can write num.Sum(x, y, z) instead, equivalent to x + y + z.

func UintFromBig

func UintFromBig(b *big.Int) (*Uint, bool)

UintFromBig construct a new Uint with a big.Int returns true if overflow happened.

func UintFromBytes

func UintFromBytes(b []byte) *Uint

UintFromBytes allows for the conversion from Uint.Bytes() back to a Uint.

func UintFromDecimal

func UintFromDecimal(d Decimal) (*Uint, bool)

UintFromDecimal returns a decimal version of the Uint, setting the bool to true if overflow occurred.

func UintFromString

func UintFromString(str string, base int) (*Uint, bool)

UintFromString created a new Uint from a string interpreted using the give base. A big.Int is used to read the string, so all error related to big.Int parsing applied here. will return true if an error/overflow happened.

func Zero

func Zero() *Uint

Zero ...

func (*Uint) Add

func (u *Uint) Add(x, y *Uint) *Uint

Add will add x and y then store the result into u this is equivalent to: `u = x + y` u is returned for convenience, no new variable is created.

func (*Uint) AddOverflow

func (u *Uint) AddOverflow(x, y *Uint) (*Uint, bool)

AddOverflow will subtract y to x then store the result into u this is equivalent to: `u = x - y` u is returned for convenience, no new variable is created. False is returned if an overflow occurred.

func (*Uint) AddSum

func (u *Uint) AddSum(vals ...*Uint) *Uint

AddSum adds multiple values at the same time to a given uint so x.AddSum(y, z) is equivalent to x + y + z.

func (Uint) BigInt

func (u Uint) BigInt() *big.Int

BigInt ...

func (Uint) Bytes

func (u Uint) Bytes() [32]byte

Bytes return the internal representation of the Uint as [32]bytes, BigEndian encoded array.

func (Uint) Clone

func (u Uint) Clone() *Uint

Clone create copy of this value this is the equivalent to: x := u.

func (*Uint) Copy

func (u *Uint) Copy(x *Uint) *Uint

Copy create a copy of the uint this if the equivalent to: u = x.

func (*Uint) Delta

func (u *Uint) Delta(x, y *Uint) (*Uint, bool)

Delta will subtract y from x and store the result unless x-y overflowed, in which case the neg field will be set and the result of y - x is set instead.

func (*Uint) DeltaI

func (u *Uint) DeltaI(x, y *Uint) *Int

DeltaI will subtract y from x and store the result.

func (*Uint) Div

func (u *Uint) Div(x, y *Uint) *Uint

Div will divide x by y then store the result into u this is equivalent to: `u = x / y` u is returned for convenience, no new variable is created.

func (Uint) EQ

func (u Uint) EQ(oth *Uint) bool

EQ with check if the value stored in u is equal to oth this is equivalent to: `u == oth`.

func (Uint) EQUint64

func (u Uint) EQUint64(oth uint64) bool

EQUint64 with check if the value stored in u is equal to oth this is equivalent to: `u == oth`.

func (*Uint) Exp

func (u *Uint) Exp(x, y *Uint) *Uint

Exp ...

func (Uint) Float64

func (u Uint) Float64() float64

Float64 ...

func (Uint) Format

func (u Uint) Format(s fmt.State, ch rune)

Format implement fmt.Formatter.

func (Uint) GT

func (u Uint) GT(oth *Uint) bool

GT with check if the value stored in u is greater than oth this is equivalent to: `u > oth`.

func (Uint) GTE

func (u Uint) GTE(oth *Uint) bool

GTE with check if the value stored in u is greater than or equal to oth this is equivalent to: `u >= oth`.

func (Uint) GTEUint64

func (u Uint) GTEUint64(oth uint64) bool

GTEUint64 with check if the value stored in u is greater than or equal to oth this is equivalent to: `u >= oth`.

func (Uint) GTUint64

func (u Uint) GTUint64(oth uint64) bool

GTUint64 with check if the value stored in u is greater than oth this is equivalent to: `u > oth`.

func (Uint) Hex

func (u Uint) Hex() string

Hex returns the hexadecimal representation of the stored value.

func (Uint) IsNegative

func (u Uint) IsNegative() bool

IsNegative returns whether the value is < 0.

func (Uint) IsZero

func (u Uint) IsZero() bool

IsZero return whether u == 0 or not.

func (Uint) LT

func (u Uint) LT(oth *Uint) bool

LT with check if the value stored in u is lesser than oth this is equivalent to: `u < oth`.

func (Uint) LTE

func (u Uint) LTE(oth *Uint) bool

LTE with check if the value stored in u is lesser than or equal to oth this is equivalent to: `u <= oth`.

func (Uint) LTEUint64

func (u Uint) LTEUint64(oth uint64) bool

LTEUint64 with check if the value stored in u is lesser than or equal to oth this is equivalent to: `u <= oth`.

func (Uint) LTUint64

func (u Uint) LTUint64(oth uint64) bool

LTUint64 with check if the value stored in u is lesser than oth this is equivalent to: `u < oth`.

func (*Uint) Mod

func (u *Uint) Mod(x, y *Uint) *Uint

Mod sets u to the modulus x%y for y != 0 and returns u. If y == 0, u is set to 0.

func (*Uint) Mul

func (u *Uint) Mul(x, y *Uint) *Uint

Mul will multiply x and y then store the result into u this is equivalent to: `u = x * y` u is returned for convenience, no new variable is created.

func (Uint) NEQ

func (u Uint) NEQ(oth *Uint) bool

NEQ with check if the value stored in u is different than oth this is equivalent to: `u != oth`.

func (Uint) NEQUint64

func (u Uint) NEQUint64(oth uint64) bool

NEQUint64 with check if the value stored in u is different than oth this is equivalent to: `u != oth`.

func (*Uint) Set

func (u *Uint) Set(oth *Uint) *Uint

Set ...

func (*Uint) SetUint64

func (u *Uint) SetUint64(val uint64) *Uint

SetUint64 ...

func (Uint) String

func (u Uint) String() string

String returns the stored value as a string this is internally using big.Int.String().

func (*Uint) Sub

func (u *Uint) Sub(x, y *Uint) *Uint

Sub will subtract y from x then store the result into u this is equivalent to: `u = x - y` u is returned for convenience, no new variable is created.

func (*Uint) SubOverflow

func (u *Uint) SubOverflow(x, y *Uint) (*Uint, bool)

SubOverflow will subtract y to x then store the result into u this is equivalent to: `u = x - y` u is returned for convenience, no new variable is created. False is returned if an overflow occurred.

func (*Uint) ToDecimal

func (u *Uint) ToDecimal() Decimal

ToDecimal returns the value of the Uint as a Decimal.

func (Uint) Uint64

func (u Uint) Uint64() uint64

Uint64 ...

Jump to

Keyboard shortcuts

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