Documentation ¶
Index ¶
- func UintToString(u *Uint) string
- func UintToUint64(u *Uint) uint64
- type DChain
- func (d *DChain) Add(vals ...Decimal) *DChain
- func (d *DChain) Div(x Decimal) *DChain
- func (d *DChain) DivRound(x Decimal, precision int32) *DChain
- func (d *DChain) Get() Decimal
- func (d *DChain) GetUint(round DecRounding) (*Uint, bool)
- func (d *DChain) Mul(x Decimal) *DChain
- func (d *DChain) Sub(vals ...Decimal) *DChain
- type DecRounding
- type Decimal
- func DecimalFromFloat(v float64) Decimal
- func DecimalFromInt64(i int64) Decimal
- func DecimalFromString(s string) (Decimal, error)
- func DecimalFromUint(u *Uint) Decimal
- func DecimalZero() Decimal
- func MaxD(a, b Decimal) Decimal
- func MaxDecimal() Decimal
- func MinD(a, b Decimal) Decimal
- func NewDecimalFromBigInt(value *big.Int, exp int32) Decimal
- func NewDecimalFromFloat(f float64) Decimal
- type Int
- func (i *Int) Add(a *Int) *Int
- func (i *Int) AddSum(vals ...*Int) *Int
- func (i Int) Clone() *Int
- func (i *Int) FlipSign()
- func (i Int) GT(o *Int) bool
- func (i Int) Int64() int64
- func (i *Int) IsNegative() bool
- func (i *Int) IsPositive() bool
- func (i *Int) IsZero() bool
- func (i Int) LT(o *Int) bool
- func (i Int) String() string
- func (i *Int) Sub(a *Int) *Int
- func (i *Int) SubSum(vals ...*Int) *Int
- type UChain
- type Uint
- func Max(a, b *Uint) *Uint
- func MaxUint() *Uint
- func Min(a, b *Uint) *Uint
- func NewUint(val uint64) *Uint
- func Sum(vals ...*Uint) *Uint
- func UintFromBig(b *big.Int) (*Uint, bool)
- func UintFromBytes(b []byte) *Uint
- func UintFromDecimal(d Decimal) (*Uint, bool)
- func UintFromString(str string, base int) (*Uint, bool)
- func Zero() *Uint
- func (u *Uint) Add(x, y *Uint) *Uint
- func (u *Uint) AddOverflow(x, y *Uint) (*Uint, bool)
- func (u *Uint) AddSum(vals ...*Uint) *Uint
- func (u Uint) BigInt() *big.Int
- func (u Uint) Bytes() [32]byte
- func (u Uint) Clone() *Uint
- func (u *Uint) Copy(x *Uint) *Uint
- func (u *Uint) Delta(x, y *Uint) (*Uint, bool)
- func (u *Uint) DeltaI(x, y *Uint) *Int
- func (u *Uint) Div(x, y *Uint) *Uint
- func (u Uint) EQ(oth *Uint) bool
- func (u Uint) EQUint64(oth uint64) bool
- func (u *Uint) Exp(x, y *Uint) *Uint
- func (u Uint) Float64() float64
- func (u Uint) Format(s fmt.State, ch rune)
- func (u Uint) GT(oth *Uint) bool
- func (u Uint) GTE(oth *Uint) bool
- func (u Uint) GTEUint64(oth uint64) bool
- func (u Uint) GTUint64(oth uint64) bool
- func (u Uint) Hex() string
- func (u Uint) IsNegative() bool
- func (u Uint) IsZero() bool
- func (u Uint) LT(oth *Uint) bool
- func (u Uint) LTE(oth *Uint) bool
- func (u Uint) LTEUint64(oth uint64) bool
- func (u Uint) LTUint64(oth uint64) bool
- func (u *Uint) Mod(x, y *Uint) *Uint
- func (u *Uint) Mul(x, y *Uint) *Uint
- func (u Uint) NEQ(oth *Uint) bool
- func (u Uint) NEQUint64(oth uint64) bool
- func (u *Uint) Set(oth *Uint) *Uint
- func (u *Uint) SetUint64(val uint64) *Uint
- func (u Uint) String() string
- func (u *Uint) Sub(x, y *Uint) *Uint
- func (u *Uint) SubOverflow(x, y *Uint) (*Uint, bool)
- func (u *Uint) ToDecimal() Decimal
- func (u Uint) Uint64() uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UintToString ¶
UintToString convert a uint to uint64 return "0" if nil.
func UintToUint64 ¶
UintToUint64 convert a uint to uint64 return 0 if nil.
Types ¶
type DChain ¶
type DChain struct {
// contains filtered or unexported fields
}
DChain ...
func UintDecChain ¶
UintDecChain returns a chainable decimal from a given uint this moves the conversion stuff out from the caller.
type DecRounding ¶
type DecRounding int
DecRounding ...
const ( DecFloor DecRounding = iota DecRound DecCeil )
constants.
type Decimal ¶
Decimal is a shopspring.Decimal.
func NewDecimalFromBigInt ¶
NewDecimalFromBigInt ...
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 NewIntFromUint ¶
NewIntFromUint creates a new Int with the value of the uint passed as a parameter.
func (*Int) FlipSign ¶
func (i *Int) FlipSign()
FlipSign changes the sign of the number from - to + and back again.
func (*Int) IsNegative ¶
IsNegative tests if the stored value is negative true if < 0 false if >= 0.
func (*Int) IsPositive ¶
IsPositive tests if the stored value is positive true if > 0 false if <= 0.
type UChain ¶
type UChain struct {
// contains filtered or unexported fields
}
UChain ...
func UintChain ¶
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().
type Uint ¶
type Uint struct {
// contains filtered or unexported fields
}
Uint A wrapper for a big unsigned int.
func Sum ¶
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 ¶
UintFromBig construct a new Uint with a big.Int returns true if overflow happened.
func UintFromBytes ¶
UintFromBytes allows for the conversion from Uint.Bytes() back to a Uint.
func UintFromDecimal ¶
UintFromDecimal returns a decimal version of the Uint, setting the bool to true if overflow occurred.
func UintFromString ¶
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 (*Uint) Add ¶
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 ¶
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 ¶
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) Bytes ¶
Bytes return the internal representation of the Uint as [32]bytes, BigEndian encoded array.
func (*Uint) Delta ¶
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) Div ¶
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 ¶
EQ with check if the value stored in u is equal to oth this is equivalent to: `u == oth`.
func (Uint) EQUint64 ¶
EQUint64 with check if the value stored in u is equal to oth this is equivalent to: `u == oth`.
func (Uint) GT ¶
GT with check if the value stored in u is greater than oth this is equivalent to: `u > oth`.
func (Uint) GTE ¶
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 ¶
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 ¶
GTUint64 with check if the value stored in u is greater than oth this is equivalent to: `u > oth`.
func (Uint) IsNegative ¶
IsNegative returns whether the value is < 0.
func (Uint) LT ¶
LT with check if the value stored in u is lesser than oth this is equivalent to: `u < oth`.
func (Uint) LTE ¶
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 ¶
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 ¶
LTUint64 with check if the value stored in u is lesser than oth this is equivalent to: `u < oth`.
func (*Uint) Mod ¶
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 ¶
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 ¶
NEQ with check if the value stored in u is different than oth this is equivalent to: `u != oth`.
func (Uint) NEQUint64 ¶
NEQUint64 with check if the value stored in u is different than oth this is equivalent to: `u != oth`.
func (Uint) String ¶
String returns the stored value as a string this is internally using big.Int.String().
func (*Uint) Sub ¶
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 ¶
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.