Documentation ¶
Overview ¶
Package math contains some human-readable mathematical primitives.
Index ¶
- Constants
- type Uint128
- func (u Uint128) Add(v Uint128) Uint128
- func (u Uint128) Add64(v uint64) Uint128
- func (u Uint128) AddWrap(v Uint128) Uint128
- func (u Uint128) AddWrap64(v uint64) Uint128
- func (u Uint128) And(v Uint128) Uint128
- func (u Uint128) And64(v uint64) Uint128
- func (u Uint128) Cmp(v Uint128) int
- func (u Uint128) Cmp64(v uint64) int
- func (u Uint128) Div(v Uint128) Uint128
- func (u Uint128) Div64(v uint64) Uint128
- func (u Uint128) Equals(v Uint128) bool
- func (u Uint128) Equals64(v uint64) bool
- func (u *Uint128) From64(v uint64)
- func (u *Uint128) FromBEBytes(b []byte) error
- func (u *Uint128) FromLEBytes(b []byte) error
- func (u *Uint128) FromString(s string) error
- func (u Uint128) GT(v Uint128) bool
- func (u Uint128) GTE(v Uint128) bool
- func (u Uint128) IsZero() bool
- func (u Uint128) LT(v Uint128) bool
- func (u Uint128) LTE(v Uint128) bool
- func (u Uint128) LeadingZeros() int
- func (u Uint128) Len() int
- func (u Uint128) Lsh(n uint) (s Uint128)
- func (u Uint128) MarshalJSON() (b []byte, err error)
- func (u Uint128) Mod(v Uint128) (r Uint128)
- func (u Uint128) Mod64(v uint64) (r uint64)
- func (u Uint128) Mul(v Uint128) Uint128
- func (u Uint128) Mul64(v uint64) Uint128
- func (u Uint128) MulWrap(v Uint128) Uint128
- func (u Uint128) MulWrap64(v uint64) Uint128
- func (u Uint128) OnesCount() int
- func (u Uint128) Or(v Uint128) Uint128
- func (u Uint128) Or64(v uint64) Uint128
- func (u *Uint128) PutBEBytes(b []byte)
- func (u Uint128) PutLEBytes(b []byte)
- func (u Uint128) QuoRem(v Uint128) (q, r Uint128)
- func (u Uint128) QuoRem64(v uint64) (Uint128, uint64)
- func (u Uint128) Reverse() Uint128
- func (u Uint128) ReverseBytes() Uint128
- func (u Uint128) RotateLeft(k int) Uint128
- func (u Uint128) RotateRight(k int) Uint128
- func (u Uint128) Rsh(n uint) (s Uint128)
- func (u Uint128) SafeAdd(v Uint128) (Uint128, error)
- func (u Uint128) SafeAdd64(v uint64) (Uint128, error)
- func (u Uint128) SafeDiv(v Uint128) (q Uint128, err error)
- func (u Uint128) SafeDiv64(v uint64) (q Uint128, err error)
- func (u Uint128) SafeMod(v Uint128) (r Uint128, err error)
- func (u Uint128) SafeMod64(v uint64) (r uint64, err error)
- func (u Uint128) SafeMul(v Uint128) (Uint128, error)
- func (u Uint128) SafeMul64(v uint64) (Uint128, error)
- func (u Uint128) SafeQuoRem(v Uint128) (q Uint128, r Uint128, err error)
- func (u Uint128) SafeQuoRem64(v uint64) (q Uint128, r uint64, err error)
- func (u Uint128) SafeSub(v Uint128) (Uint128, error)
- func (u Uint128) SafeSub64(v uint64) (Uint128, error)
- func (u Uint128) String() string
- func (u Uint128) Sub(v Uint128) Uint128
- func (u Uint128) Sub64(v uint64) Uint128
- func (u Uint128) SubWrap(v Uint128) Uint128
- func (u Uint128) SubWrap64(v uint64) Uint128
- func (u Uint128) TrailingZeros() int
- func (u *Uint128) UnmarshalJSON(b []byte) error
- func (u Uint128) Xor(v Uint128) Uint128
- func (u Uint128) Xor64(v uint64) Uint128
Constants ¶
const ( // Uint128Size defines the byte size of an Uint128 Uint128Size = 16 // Uint128BitSize defines the bit size of an Uint128 Uint128BitSize = 16 * 8 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Uint128 ¶
type Uint128 struct {
Lo, Hi uint64
}
Uint128 is an unsigned 128-bit number.
func NewUint128 ¶
NewUint128 returns the Uint128 value (lo,hi).
func NewUint128FromUint64 ¶
NewUint128FromUint64 returns an Uint128 from an uint64
func (Uint128) AddWrap ¶
AddWrap returns u+v with wraparound semantics; for example, Max.AddWrap(From64(1)) == Zero.
func (Uint128) AddWrap64 ¶
AddWrap64 returns u+v with wraparound semantics; for example, Max.AddWrap64(1) == Zero.
func (Uint128) Equals ¶
Equals returns true if u == v.
Uint128 values can be compared directly with ==, but use of the Equals method is preferred for consistency.
func (*Uint128) FromBEBytes ¶
FromBEBytes populates the Uin128 value given bytes in big endian order.
func (*Uint128) FromLEBytes ¶
FromLEBytes populates the Uint128 value given bytes in little endian order.
func (*Uint128) FromString ¶
FromString populates the Uint128 with a base0 string.
func (Uint128) LeadingZeros ¶
LeadingZeros returns the number of leading zero bits in u; the result is 128 for u == 0.
func (Uint128) Len ¶
Len returns the minimum number of bits required to represent u; the result is 0 for u == 0.
func (Uint128) MarshalJSON ¶
MarshalJSON implements json.Marshaler and returns Uint128.String converted to bytes.
func (Uint128) MulWrap ¶
MulWrap returns u*v with wraparound semantics; for example, Max.MulWrap(Max) == 1.
func (Uint128) MulWrap64 ¶
MulWrap64 returns u*v with wraparound semantics; for example, Max.MulWrap64(2) == Max.Sub64(1).
func (*Uint128) PutBEBytes ¶
PutBEBytes stores u in b in big-endian order. It panics if len(b) < 16.
func (Uint128) PutLEBytes ¶
PutLEBytes stores u in b in little-endian order. It panics if len(b) < 16.
func (Uint128) QuoRem64 ¶
QuoRem64 returns q = u/v and r = u%v, panicking on division by zero or quotient overflow.
func (Uint128) ReverseBytes ¶
ReverseBytes returns the value of u with its bytes in reversed order.
func (Uint128) RotateLeft ¶
RotateLeft returns the value of u rotated left by (k mod 128) bits.
func (Uint128) RotateRight ¶
RotateRight returns the value of u rotated left by (k mod 128) bits.
func (Uint128) SafeQuoRem ¶
SafeQuoRem returns q = u/v and u%v, returning an error on division by zero or quotient overflow.
func (Uint128) SafeQuoRem64 ¶
SafeQuoRem64 returns q = u/v r = u%v returning an error on division by zero or quotient overflow.
func (Uint128) SubWrap ¶
SubWrap returns u-v with wraparound semantics; for example, Zero.SubWrap(From64(1)) == Max.
func (Uint128) SubWrap64 ¶
SubWrap64 returns u-v with wraparound semantics; for example, Zero.SubWrap64(1) == Max.
func (Uint128) TrailingZeros ¶
TrailingZeros returns the number of trailing zero bits in u; the result is 128 for u == 0.
func (*Uint128) UnmarshalJSON ¶
UnmarshalJSON populates Uint128 from a json string value.