Documentation ¶
Overview ¶
Package math implements custom Cosmos SDK math types used for arithmetic operations. Signed and unsigned integer types utilize Golang's standard library big integers types, having a maximum bit length of 256 bits.
Index ¶
- Constants
- func IntEq(t *testing.T, exp, got Int) (*testing.T, bool, string, string, string)
- func UintOverflow(i *big.Int) error
- type Int
- func (i Int) Abs() Int
- func (i Int) Add(i2 Int) (res Int)
- func (i Int) AddRaw(i2 int64) Int
- func (i Int) BigInt() *big.Int
- func (i Int) Equal(i2 Int) bool
- func (i Int) GT(i2 Int) bool
- func (i Int) GTE(i2 Int) bool
- func (i Int) Int64() int64
- func (i Int) IsInt64() bool
- func (i Int) IsNegative() bool
- func (i Int) IsNil() bool
- func (i Int) IsPositive() bool
- func (i Int) IsUint64() bool
- func (i Int) IsZero() bool
- func (i Int) LT(i2 Int) bool
- func (i Int) LTE(i2 Int) bool
- func (i Int) Marshal() ([]byte, error)
- func (i Int) MarshalAmino() ([]byte, error)
- func (i Int) MarshalJSON() ([]byte, error)
- func (i *Int) MarshalTo(data []byte) (n int, err error)
- func (i Int) MarshalYAML() (interface{}, error)
- func (i Int) Mod(i2 Int) Int
- func (i Int) ModRaw(i2 int64) Int
- func (i Int) Mul(i2 Int) (res Int)
- func (i Int) MulRaw(i2 int64) Int
- func (i Int) Neg() (res Int)
- func (i Int) Quo(i2 Int) (res Int)
- func (i Int) QuoRaw(i2 int64) Int
- func (i Int) Sign() int
- func (i *Int) Size() int
- func (i Int) String() string
- func (i Int) Sub(i2 Int) (res Int)
- func (i Int) SubRaw(i2 int64) Int
- func (i Int) Uint64() uint64
- func (i *Int) Unmarshal(data []byte) error
- func (i *Int) UnmarshalAmino(bz []byte) error
- func (i *Int) UnmarshalJSON(bz []byte) error
- type Uint
- func (u Uint) Add(u2 Uint) Uint
- func (u Uint) AddUint64(u2 uint64) Uint
- func (u Uint) BigInt() *big.Int
- func (u Uint) Decr() Uint
- func (u Uint) Equal(u2 Uint) bool
- func (u Uint) GT(u2 Uint) bool
- func (u Uint) GTE(u2 Uint) bool
- func (u Uint) Incr() Uint
- func (u Uint) IsZero() bool
- func (u Uint) LT(u2 Uint) bool
- func (u Uint) LTE(u2 Uint) bool
- func (u Uint) Marshal() ([]byte, error)
- func (u Uint) MarshalAmino() ([]byte, error)
- func (u Uint) MarshalJSON() ([]byte, error)
- func (u *Uint) MarshalTo(data []byte) (n int, err error)
- func (u Uint) Mod(u2 Uint) Uint
- func (u Uint) Mul(u2 Uint) (res Uint)
- func (u Uint) MulUint64(u2 uint64) (res Uint)
- func (u Uint) Quo(u2 Uint) (res Uint)
- func (u Uint) QuoUint64(u2 uint64) Uint
- func (u *Uint) Size() int
- func (u Uint) String() string
- func (u Uint) Sub(u2 Uint) Uint
- func (u Uint) SubUint64(u2 uint64) Uint
- func (u Uint) Uint64() uint64
- func (u *Uint) Unmarshal(data []byte) error
- func (u *Uint) UnmarshalAmino(bz []byte) error
- func (u *Uint) UnmarshalJSON(bz []byte) error
Constants ¶
const MaxBitLen = 256
MaxBitLen defines the maximum bit length supported bit Int and Uint types.
Variables ¶
This section is empty.
Functions ¶
func IntEq ¶
intended to be used with require/assert: require.True(IntEq(...))
Types ¶
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int wraps big.Int with a 257 bit range bound Checks overflow, underflow and division by zero Exists in range from -(2^256 - 1) to 2^256 - 1
func NewIntFromBigInt ¶
NewIntFromBigInt constructs Int from big.Int. If the provided big.Int is nil, it returns an empty instance. This function panics if the bit length is > 256.
func NewIntFromString ¶
NewIntFromString constructs Int from string
func NewIntFromUint64 ¶
NewIntFromUint64 constructs an Int from a uint64.
func NewIntWithDecimal ¶
NewIntWithDecimal constructs Int with decimal Result value is n*10^dec
func (Int) GTE ¶
GTE returns true if receiver Int is greater than or equal to the parameter Int.
func (Int) Int64 ¶
Int64 converts Int to int64 Panics if the value is out of range
func (Int) LTE ¶
LTE returns true if first Int is less than or equal to second
func (Int) Marshal ¶
Marshal implements the gogo proto custom type interface.
func (Int) MarshalAmino ¶
Override Amino binary serialization by proxying to protobuf.
func (Int) MarshalJSON ¶
MarshalJSON defines custom encoding scheme
func (*Int) MarshalTo ¶
MarshalTo implements the gogo proto custom type interface.
func (Int) MarshalYAML ¶
MarshalYAML returns the YAML representation.
func (Int) ModRaw ¶
ModRaw returns remainder after dividing with int64
func (Int) Uint64 ¶
Uint64 converts Int to uint64 Panics if the value is out of range
func (*Int) Unmarshal ¶
Unmarshal implements the gogo proto custom type interface.
type Uint ¶
type Uint struct {
// contains filtered or unexported fields
}
Uint wraps integer with 256 bit range bound Checks overflow, underflow and division by zero Exists in range from 0 to 2^256-1
func NewUintFromBigInt ¶
NewUintFromBigUint constructs Uint from big.Uint
func NewUintFromString ¶
NewUintFromString constructs Uint from string
func ParseUint ¶
ParseUint reads a string-encoded Uint value and return a Uint.
func RelativePow ¶
RelativePow raises x to the power of n, where x (and the result, z) are scaled by factor b for example, RelativePow(210, 2, 100) = 441 (2.1^2 = 4.41)
func (Uint) AddUint64 ¶
Add convert uint64 and add it to Uint
func (Uint) Decr ¶
Decr decrements the Uint by one. Decr will panic if the Uint is zero.
func (Uint) GT ¶
GT returns true if first Uint is greater than second
func (Uint) GTE ¶
GTE returns true if first Uint is greater than second
func (Uint) LTE ¶
LTE returns true if first Uint is lesser than or equal to the second
func (Uint) Marshal ¶
Marshal implements the gogo proto custom type interface.
func (Uint) MarshalAmino ¶
Override Amino binary serialization by proxying to protobuf.
func (Uint) MarshalJSON ¶
MarshalJSON defines custom encoding scheme
func (*Uint) MarshalTo ¶
MarshalTo implements the gogo proto custom type interface.
func (Uint) Uint64 ¶
Uint64 converts Uint to uint64 Panics if the value is out of range
func (*Uint) Unmarshal ¶
Unmarshal implements the gogo proto custom type interface.