Documentation ¶
Index ¶
- func AbsV[T Signed](a T) T
- func CmpV[T1 Num, T2 Num](a T1, b T2) bool
- func DeltaV[T Signed](a, b T) T
- func IntToString(u *Int) string
- func MaxAbs[T Signed](vals ...T) T
- func MaxV[T Num](a, b T) T
- func MinV[T Num](a, b T) T
- func NumericToString(n *Numeric) string
- func UintFromDecimalWithFraction(d Decimal) (*Uint, Decimal)
- func UintToString(u *Uint) string
- func UintToUint64(u *Uint) uint64
- type Decimal
- func DecimalE() 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 DecimalMinusOne() Decimal
- func DecimalOne() Decimal
- func DecimalPart(a Decimal) Decimal
- func DecimalTwo() Decimal
- func DecimalZero() Decimal
- func MaxD(a, b Decimal) Decimal
- func MaxDecimal() Decimal
- func Mean(numbers []Decimal) (Decimal, error)
- func MinD(a, b Decimal) Decimal
- func MustDecimalFromString(f string) Decimal
- func NewDecimalFromBigInt(value *big.Int, exp int32) Decimal
- func NewDecimalFromFloat(f float64) Decimal
- func UnmarshalBinaryDecimal(data []byte) (Decimal, error)
- func Variance(numbers []Decimal) (Decimal, error)
- type Int
- func (i *Int) Add(a *Int) *Int
- func (i *Int) AddSum(vals ...*Int) *Int
- func (i Int) Clone() *Int
- func (i *Int) Div(m *Int) *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) Mul(m *Int) *Int
- 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) Int() *Int
- func (n *Numeric) IsDecimal() bool
- func (n *Numeric) IsInt() 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) SetInt(in *Int) *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 Median(nums []*Uint) *Uint
- func Min(a, b *Uint) *Uint
- func MustUintFromBig(b *big.Int) *Uint
- func MustUintFromString(str string, base int) *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 UintFromUint64(ui uint64) *Uint
- 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) MarshalBinary() (data []byte, err error)
- func (u Uint) MarshalJSON() ([]byte, error)
- 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) Scan(value interface{}) error
- func (u *Uint) Set(oth *Uint) *Uint
- func (u *Uint) SetUint64(val uint64) *Uint
- func (u *Uint) Sqrt(x *Uint) *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
- func (u *Uint) UnmarshalBinary(data []byte) error
- func (u *Uint) UnmarshalJSON(numericBytes []byte) error
- func (u Uint) Value() (driver.Value, error)
- type Unsigned
- type WrappedDecimal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CmpV ¶ added in v0.71.0
CmpV compares 2 numeric values of any type, we attempt to cast T1 to T2 and back to see if that conversion loses any information, if no data is lost this way, we compare both values as T2, otherwise we compare both as T1.
func DeltaV ¶ added in v0.77.0
func DeltaV[T Signed](a, b T) T
DeltaV generic delta function signed primitives.
func IntToString ¶
func MaxAbs ¶ added in v0.71.0
func MaxAbs[T Signed](vals ...T) T
MaxAbs - get max value based on absolute values of abolute vals.
func NumericToString ¶ added in v0.65.0
func UintFromDecimalWithFraction ¶ added in v0.72.6
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 DecimalMinusOne ¶ added in v0.73.0
func DecimalMinusOne() Decimal
func DecimalOne ¶ added in v0.60.0
func DecimalOne() Decimal
func DecimalPart ¶ added in v0.72.6
func DecimalTwo ¶ added in v0.73.0
func DecimalTwo() Decimal
func DecimalZero ¶
func DecimalZero() Decimal
func MaxDecimal ¶
func MaxDecimal() Decimal
func MustDecimalFromString ¶
func NewDecimalFromFloat ¶
func UnmarshalBinaryDecimal ¶ added in v0.73.0
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 IntFromDecimal ¶ added in v0.73.0
IntFromDecimal returns the Int part of a decimal.
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.
func (*Int) Mul ¶ added in v0.73.0
Mul will multiply the passed in value to the base value i = i * m.
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 Median ¶ added in v0.74.0
Median calculates the median of the slice of uints. it is assumed that no nils are allowed, no zeros are allowed.
func MustUintFromBig ¶ added in v0.73.0
UintFromBig construct a new Uint with a big.Int panics if overflow happened.
func MustUintFromString ¶ added in v0.73.0
MustUintFromString creates a new Uint from a string interpreted using the given base. A big.Int is used to read the string, so all errors related to big.Int parsing are applied here. The core will panic if an error/overflow happens.
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 UintFromUint64 ¶ added in v0.73.0
UintFromUint64 allows for the conversion from uint64.
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) MarshalBinary ¶ added in v0.74.0
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (Uint) MarshalJSON ¶ added in v0.74.0
MarshalJSON implements the json.Marshaler interface.
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) Scan ¶ added in v0.74.0
Scan implements the sql.Scanner interface for database deserialization.
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.
func (*Uint) UnmarshalBinary ¶ added in v0.74.0
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. As a string representation is already used when encoding to text, this method stores that string as []byte.
func (*Uint) UnmarshalJSON ¶ added in v0.74.0
UnmarshalJSON implements the json.Unmarshaler interface.
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.