Documentation ¶
Index ¶
- Constants
- Variables
- type Uint128
- func (u *Uint128) AbsBytes() []byte
- func (u *Uint128) Add(x *Uint128) (*Uint128, error)
- func (u *Uint128) AddInt(i int64) (*Uint128, error)
- func (u *Uint128) AddUint(i uint64) (*Uint128, error)
- func (u *Uint128) BigValue() *big.Int
- func (u *Uint128) Bytes() [Uint128Bytes]byte
- func (u *Uint128) Cmp(x *Uint128) int
- func (u *Uint128) DeepCopy() *Uint128
- func (u *Uint128) Div(x *Uint128) (*Uint128, error)
- func (u *Uint128) DivInt(i int64) (*Uint128, error)
- func (u *Uint128) Eq(x *Uint128) bool
- func (u *Uint128) Exp(x *Uint128) (*Uint128, error)
- func (u *Uint128) Float64() float64
- func (u *Uint128) Ge(x *Uint128) bool
- func (u *Uint128) Gt(x *Uint128) bool
- func (u *Uint128) IntValue() int64
- func (u *Uint128) IsZero() bool
- func (u *Uint128) Le(x *Uint128) bool
- func (u *Uint128) Lt(x *Uint128) bool
- func (u *Uint128) Mod(x *Uint128) (*Uint128, error)
- func (u *Uint128) Mul(x *Uint128) (*Uint128, error)
- func (u *Uint128) MulInt(i int64) (*Uint128, error)
- func (u *Uint128) Rsh(n uint) *Uint128
- func (u *Uint128) String() string
- func (u *Uint128) Sub(x *Uint128) (*Uint128, error)
- func (u *Uint128) SubUint(x uint64) (*Uint128, error)
- func (u *Uint128) UintValue() uint64
- func (u *Uint128) Validate() error
Constants ¶
const ( // Uint128Bytes the number of bytes Uint128 type will take. Uint128Bytes = 16 // Uint128Bits defines the number of bits for Uint128 type. Uint128Bits = 128 )
Variables ¶
var ( // ErrUint128Overflow indicates the value is greater than maximum of 2^128-1. ErrUint128Overflow = errors.New("Uint128: overflow") // ErrUint128Underflow indicates the value is less than minimum of 0. ErrUint128Underflow = errors.New("Uint128: underflow") // ErrUint128InvalidBytes indicates the bytes size is not equal to Uint128Bytes. ErrUint128InvalidBytes = errors.New("Uint128: invalid bytes") // ErrUint128InvalidString indicates the string is not valid when converted to Uint128. ErrUint128InvalidString = errors.New("Uint128: invalid string") // ErrUint128DividedByZero indicates a division-by-zero error occurs ErrUint128DividedByZero = errors.New("Uint128: divided by zero") )
Functions ¶
This section is empty.
Types ¶
type Uint128 ¶
type Uint128 struct {
// contains filtered or unexported fields
}
Uint128 defines a uint128 type with safe arithmetic operations implemented, based on big.Int.
Supported arithmetic operations:
u1 = u1.Add(u2) u1 = u1.Sub(u2) u1 = u1.Mul(u2) u1 = u1.Div(u2) u1 = u1.Mod(u2) u1 = u1.Exp(u2) etc.
func NewUint128 ¶
func NewUint128() *Uint128
NewUint128 returns a new Uint128 struct with default value 0.
func NewUint128FromBigInt ¶
NewUint128FromBigInt returns a new Uint128 struct with given value and value check.
func NewUint128FromBytes ¶
NewUint128FromBytes converts big-endian byte slice to Uint128, len(bytes) must be not greater than Uint128Bytes.
func NewUint128FromInt ¶
NewUint128FromInt returns a new Uint128 struct with given value and value check.
func NewUint128FromString ¶
NewUint128FromString returns a new Uint128 struct with given value and value check.
func NewUint128FromUint ¶
NewUint128FromUint returns a new Uint128 with given value
func (*Uint128) AbsBytes ¶
RawBytes returns the underlying byte slice of u with prefix 0(byte) removed.
func (*Uint128) Bytes ¶
func (u *Uint128) Bytes() [Uint128Bytes]byte
Bytes returns the value of u as a big-endian byte array.
func (*Uint128) IntValue ¶
IntValue returns the int64 representation of u. Panic if u is greater than maximum int64