Documentation ¶
Index ¶
- func AbsV[T Signed](a T) T
- func IntToString(u *Int) string
- func MaxV[T Num](a, b T) T
- func MinV[T Num](a, b T) T
- func NumericToString(n *Numeric) string
- func UintToString(u *Uint) string
- func UintToUint64(u *Uint) uint64
- type Decimal
- func DecimalFromFloat(v float64) Decimal
- func DecimalFromInt(u *Int) Decimal
- func DecimalFromInt64(i int64) Decimal
- func DecimalFromString(s string) (Decimal, error)
- func DecimalFromUint(u *Uint) Decimal
- func DecimalOne() Decimal
- func DecimalZero() Decimal
- func MaxD(a, b Decimal) Decimal
- func MaxDecimal() Decimal
- func MinD(a, b Decimal) Decimal
- func MustDecimalFromString(f string) 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) EQ(o *Int) bool
- func (i *Int) FlipSign()
- func (i Int) GT(o *Int) bool
- func (i Int) GTE(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) LTE(o *Int) bool
- func (i Int) String() string
- func (i *Int) Sub(a *Int) *Int
- func (i *Int) SubSum(vals ...*Int) *Int
- type Num
- type Numeric
- func (n *Numeric) Clone() *Numeric
- func (n *Numeric) Decimal() *Decimal
- func (n *Numeric) IsDecimal() bool
- func (n *Numeric) IsUint() bool
- func (n *Numeric) ScaleTo(op, tdp int64) (*Uint, error)
- func (n *Numeric) SetDecimal(d *Decimal) *Numeric
- func (n *Numeric) SetUint(u *Uint) *Numeric
- func (n *Numeric) String() string
- func (n *Numeric) SupportDecimalPlaces(dp int64) bool
- func (n *Numeric) Uint() *Uint
- type Signed
- 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 UintFromHex(hex string) (*Uint, error)
- func UintFromString(str string, base int) (*Uint, bool)
- func UintOne() *Uint
- func UintZero() *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) AddUint64(x *Uint, y uint64) *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
- type Unsigned
- type WrappedDecimal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IntToString ¶
func NumericToString ¶ added in v0.65.0
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 Decimal ¶
func DecimalFromFloat ¶
func DecimalFromInt ¶
func DecimalFromInt64 ¶
func DecimalFromString ¶
func DecimalFromUint ¶
func DecimalOne ¶ added in v0.60.0
func DecimalOne() Decimal
func DecimalZero ¶
func DecimalZero() Decimal
func MaxDecimal ¶
func MaxDecimal() Decimal
func MustDecimalFromString ¶
func 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 IntFromBig ¶
IntFromBig construct a new Int with a big.Int returns true if overflow happened.
func IntFromString ¶
IntFromString creates a new Int 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 happened.
func IntFromUint ¶
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 Numeric ¶ added in v0.65.0
type Numeric struct {
// contains filtered or unexported fields
}
func NumericFromString ¶ added in v0.65.0
func (*Numeric) ScaleTo ¶ added in v0.65.0
ScaleTo calculates the current contained value - decimal or uint - scaled to the target decimals.
func (*Numeric) SetDecimal ¶ added in v0.65.0
func (*Numeric) SupportDecimalPlaces ¶ added in v0.65.0
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 UintFromHex ¶
UintFromHex instantiate a uint from and hex string.
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) AddUint64 ¶
AddUint64 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) 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.
type WrappedDecimal ¶
type WrappedDecimal struct {
// contains filtered or unexported fields
}
func NewWrappedDecimal ¶
func NewWrappedDecimal(integerRepresentation *Uint, underlyingValue Decimal) WrappedDecimal
NewWrappedDecimal returns a new instance of a decimal coupled with the Uint representation that has been chosen for it.
func (WrappedDecimal) Original ¶
func (w WrappedDecimal) Original() Decimal
Original returns the underlying decimal value.
func (WrappedDecimal) Representation ¶
func (w WrappedDecimal) Representation() *Uint
Representation returns the Uint representation of a decimal that has been affixed when calling the constructor.