Documentation ¶
Overview ¶
Package fixed implements fixed-size numeric types.
Index ¶
- func AppendUvarint[T Uint[T]](b []byte, v T) []byte
- func MaxVarintLen[T Uint[T]]() int
- func Uvarint[T Uint[T]](b []byte) (T, int)
- func VarintLen[T Uint[T]](v T) int
- type Uint
- type Uint1024
- func (x Uint1024) Add(y Uint1024) Uint1024
- func (x Uint1024) AddCheck(y Uint1024) (z Uint1024, carry uint64)
- func (x Uint1024) And(y Uint1024) Uint1024
- func (x Uint1024) BitLen() int
- func (x Uint1024) Bytes(b *[128]byte)
- func (x Uint1024) Cmp(y Uint1024) int
- func (x Uint1024) Equal(y Uint1024) bool
- func (x Uint1024) Exp(y, m Uint1024) Uint1024
- func (x Uint1024) GoString() string
- func (x Uint1024) IsZero() bool
- func (x Uint1024) LeadingZeros() int
- func (x Uint1024) Lsh(n uint) Uint1024
- func (x Uint1024) Mul(y Uint1024) Uint1024
- func (x Uint1024) MulCheck(y Uint1024) (Uint1024, bool)
- func (x Uint1024) Or(y Uint1024) Uint1024
- func (x Uint1024) QuoRem(y Uint1024) (q, r Uint1024)
- func (x Uint1024) Rsh(n uint) Uint1024
- func (x *Uint1024) SetBytes(b []byte) error
- func (Uint1024) Size() int
- func (x Uint1024) String() string
- func (x Uint1024) Sub(y Uint1024) Uint1024
- func (x Uint1024) SubCheck(y Uint1024) (z Uint1024, borrow uint64)
- func (x Uint1024) Xor(y Uint1024) Uint1024
- type Uint128
- func (x Uint128) Add(y Uint128) Uint128
- func (x Uint128) AddCheck(y Uint128) (z Uint128, carry uint64)
- func (x Uint128) And(y Uint128) Uint128
- func (x Uint128) BitLen() int
- func (x Uint128) Bytes(b *[16]byte)
- func (x Uint128) Cmp(y Uint128) int
- func (x Uint128) Equal(y Uint128) bool
- func (x Uint128) GoString() string
- func (x Uint128) IsZero() bool
- func (x Uint128) LeadingZeros() int
- func (x Uint128) Lsh(n uint) Uint128
- func (x Uint128) Mul(y Uint128) Uint128
- func (x Uint128) MulCheck(y Uint128) (Uint128, bool)
- func (x Uint128) Or(y Uint128) Uint128
- func (x Uint128) QuoRem(y Uint128) (q, r Uint128)
- func (x Uint128) Rsh(n uint) Uint128
- func (x *Uint128) SetBytes(b []byte) error
- func (Uint128) Size() int
- func (x Uint128) String() string
- func (x Uint128) Sub(y Uint128) Uint128
- func (x Uint128) SubCheck(y Uint128) (z Uint128, borrow uint64)
- func (x Uint128) Xor(y Uint128) Uint128
- type Uint192
- func (x Uint192) Add(y Uint192) Uint192
- func (x Uint192) AddCheck(y Uint192) (z Uint192, carry uint64)
- func (x Uint192) And(y Uint192) Uint192
- func (x Uint192) BitLen() int
- func (x Uint192) Cmp(y Uint192) int
- func (x Uint192) Equal(y Uint192) bool
- func (x Uint192) GoString() string
- func (x Uint192) IsZero() bool
- func (x Uint192) LeadingZeros() int
- func (x Uint192) Lsh(n uint) Uint192
- func (x Uint192) Mul(y Uint192) Uint192
- func (x Uint192) MulCheck(y Uint192) (Uint192, bool)
- func (x Uint192) Or(y Uint192) Uint192
- func (x Uint192) QuoRem(y Uint192) (q, r Uint192)
- func (x Uint192) Rsh(n uint) Uint192
- func (Uint192) Size() int
- func (x Uint192) String() string
- func (x Uint192) Sub(y Uint192) Uint192
- func (x Uint192) SubCheck(y Uint192) (z Uint192, borrow uint64)
- func (x Uint192) Xor(y Uint192) Uint192
- type Uint2048
- func (x Uint2048) Add(y Uint2048) Uint2048
- func (x Uint2048) AddCheck(y Uint2048) (z Uint2048, carry uint64)
- func (x Uint2048) And(y Uint2048) Uint2048
- func (x Uint2048) BitLen() int
- func (x Uint2048) Bytes(b *[256]byte)
- func (x Uint2048) Cmp(y Uint2048) int
- func (x Uint2048) Equal(y Uint2048) bool
- func (x Uint2048) Exp(y, m Uint2048) Uint2048
- func (x Uint2048) GoString() string
- func (x Uint2048) IsZero() bool
- func (x Uint2048) LeadingZeros() int
- func (x Uint2048) Lsh(n uint) Uint2048
- func (x Uint2048) Mul(y Uint2048) Uint2048
- func (x Uint2048) MulCheck(y Uint2048) (Uint2048, bool)
- func (x Uint2048) Or(y Uint2048) Uint2048
- func (x Uint2048) QuoRem(y Uint2048) (q, r Uint2048)
- func (x Uint2048) Rsh(n uint) Uint2048
- func (x *Uint2048) SetBytes(b []byte) error
- func (Uint2048) Size() int
- func (x Uint2048) String() string
- func (x Uint2048) Sub(y Uint2048) Uint2048
- func (x Uint2048) SubCheck(y Uint2048) (z Uint2048, borrow uint64)
- func (x Uint2048) Xor(y Uint2048) Uint2048
- type Uint256
- func (x Uint256) Add(y Uint256) Uint256
- func (x Uint256) AddCheck(y Uint256) (z Uint256, carry uint64)
- func (x Uint256) And(y Uint256) Uint256
- func (x Uint256) BitLen() int
- func (x Uint256) Bytes(b *[32]byte)
- func (x Uint256) Cmp(y Uint256) int
- func (x Uint256) Equal(y Uint256) bool
- func (x Uint256) Exp(y, m Uint256) Uint256
- func (x Uint256) GoString() string
- func (x Uint256) IsZero() bool
- func (x Uint256) LeadingZeros() int
- func (x Uint256) Lsh(n uint) Uint256
- func (x Uint256) Mul(y Uint256) Uint256
- func (x Uint256) MulCheck(y Uint256) (Uint256, bool)
- func (x Uint256) Or(y Uint256) Uint256
- func (x Uint256) QuoRem(y Uint256) (q, r Uint256)
- func (x Uint256) Rsh(n uint) Uint256
- func (x *Uint256) SetBytes(b []byte) error
- func (Uint256) Size() int
- func (x Uint256) String() string
- func (x Uint256) Sub(y Uint256) Uint256
- func (x Uint256) SubCheck(y Uint256) (z Uint256, borrow uint64)
- func (x Uint256) Xor(y Uint256) Uint256
- type Uint512
- func (x Uint512) Add(y Uint512) Uint512
- func (x Uint512) AddCheck(y Uint512) (z Uint512, carry uint64)
- func (x Uint512) And(y Uint512) Uint512
- func (x Uint512) BitLen() int
- func (x Uint512) Bytes(b *[64]byte)
- func (x Uint512) Cmp(y Uint512) int
- func (x Uint512) Equal(y Uint512) bool
- func (x Uint512) Exp(y, m Uint512) Uint512
- func (x Uint512) GoString() string
- func (x Uint512) IsZero() bool
- func (x Uint512) LeadingZeros() int
- func (x Uint512) Lsh(n uint) Uint512
- func (x Uint512) Mul(y Uint512) Uint512
- func (x Uint512) MulCheck(y Uint512) (Uint512, bool)
- func (x Uint512) Or(y Uint512) Uint512
- func (x Uint512) QuoRem(y Uint512) (q, r Uint512)
- func (x Uint512) Rsh(n uint) Uint512
- func (x *Uint512) SetBytes(b []byte) error
- func (Uint512) Size() int
- func (x Uint512) String() string
- func (x Uint512) Sub(y Uint512) Uint512
- func (x Uint512) SubCheck(y Uint512) (z Uint512, borrow uint64)
- func (x Uint512) Xor(y Uint512) Uint512
- type Uint96
- func (x Uint96) Add(y Uint96) Uint96
- func (x Uint96) AddCheck(y Uint96) (z Uint96, carry uint32)
- func (x Uint96) And(y Uint96) Uint96
- func (x Uint96) BitLen() int
- func (x Uint96) Bytes(b *[12]byte)
- func (x Uint96) Cmp(y Uint96) int
- func (x Uint96) Equal(y Uint96) bool
- func (x Uint96) GoString() string
- func (x Uint96) IsZero() bool
- func (x Uint96) LeadingZeros() int
- func (x Uint96) Lsh(n uint) Uint96
- func (x Uint96) Mul(y Uint96) Uint96
- func (x Uint96) MulCheck(y Uint96) (Uint96, bool)
- func (x Uint96) Or(y Uint96) Uint96
- func (x Uint96) QuoRem(y Uint96) (q, r Uint96)
- func (x Uint96) Rsh(n uint) Uint96
- func (x *Uint96) SetBytes(b []byte) error
- func (Uint96) Size() int
- func (x Uint96) String() string
- func (x Uint96) Sub(y Uint96) Uint96
- func (x Uint96) SubCheck(y Uint96) (z Uint96, borrow uint32)
- func (x Uint96) Xor(y Uint96) Uint96
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendUvarint ¶
AppendUvarint appends the unsigned varint encoding of x to b and returns the resulting slice.
func MaxVarintLen ¶
MaxVarintLen returns the maximum number of bytes needed to represent a varint.
Types ¶
type Uint ¶
type Uint[T any] interface { // Size returns the width of the integer in bits. Size() int // BitLen returns the number of bits required to represent x. BitLen() int // LeadingZeros returns the number of leading zeros in x. LeadingZeros() int // IsZero repors whether x is zero. IsZero() bool // Cmp compares x and y and returns // // - +1 if x > y // - 0 if x == y // - -1 if x < y Cmp(T) int // Equal reports whether x == y. // // In general, prefer the == operator to using this method. Equal(T) bool // Add returns x+y. Add(T) T // Sub returns x-y. Sub(T) T // Mul returns x*y. Mul(T) T // QuoRem returns (q, r) such that // // q = x/y // r = x - y*q QuoRem(T) (q, r T) // And returns x&y. And(T) T // Or returns x|y. Or(T) T // Xor returns x^y. Xor(T) T // Lsh returns x<<n. Lsh(uint) T // Rsh returns x>>n. Rsh(uint) T // String returns the base-10 representation of x. String() string // contains filtered or unexported methods }
Uint is an unsigned integer.
type Uint1024 ¶
type Uint1024 struct {
// contains filtered or unexported fields
}
Uint1024 is an unsigned, 1024-bit integer.
It can be compared for equality with ==.
func ParseUint1024 ¶
ParseUint1024 returns the value of s in the given base.
func U1024 ¶
U1024 constructs a Uint1024.
The inputs are in ascending (low to high) order. For example, a uint64 x can be converted to a Uint1024, with
U1024(x, 0, 0, ...)
or more simply
U1024From64(x)
func U1024From64 ¶
U1024From64 constructs a Uint1024 from a uint64.
func (Uint1024) Equal ¶
Equal reports whether x == y.
In general, prefer the == operator to using this method.
func (Uint1024) LeadingZeros ¶
LeadingZeros returns the number of leading zeros in x.
type Uint128 ¶
type Uint128 struct {
// contains filtered or unexported fields
}
Uint128 is an unsigned, 128-bit integer.
It can be compared for equality with ==.
func ParseUint128 ¶
ParseUint128 returns the value of s in the given base.
func U128 ¶
U128 constructs a Uint128.
The inputs are in ascending (low to high) order. For example, a uint64 x can be converted to a Uint128, with
U128(x, 0, 0, ...)
or more simply
U128From64(x)
func (Uint128) Equal ¶
Equal reports whether x == y.
In general, prefer the == operator to using this method.
func (Uint128) LeadingZeros ¶
LeadingZeros returns the number of leading zeros in x.
type Uint192 ¶
type Uint192 struct {
// contains filtered or unexported fields
}
Uint192 is an unsigned, 192-bit integer.
It can be compared for equality with ==.
func ParseUint192 ¶
ParseUint192 returns the value of s in the given base.
func U192 ¶
U192 constructs a Uint192.
The inputs are in ascending (low to high) order. For example, a uint64 x can be converted to a Uint192, with
U192(x, 0, 0, ...)
or more simply
U192From64(x)
func (Uint192) Equal ¶
Equal reports whether x == y.
In general, prefer the == operator to using this method.
func (Uint192) LeadingZeros ¶
LeadingZeros returns the number of leading zeros in x.
type Uint2048 ¶
type Uint2048 struct {
// contains filtered or unexported fields
}
Uint2048 is an unsigned, 2048-bit integer.
It can be compared for equality with ==.
func ParseUint2048 ¶
ParseUint2048 returns the value of s in the given base.
func U2048 ¶
func U2048(u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, u11, u12, u13, u14, u15, u16, u17, u18, u19, u20, u21, u22, u23, u24, u25, u26, u27, u28, u29, u30, u31 uint64) Uint2048
U2048 constructs a Uint2048.
The inputs are in ascending (low to high) order. For example, a uint64 x can be converted to a Uint2048, with
U2048(x, 0, 0, ...)
or more simply
U2048From64(x)
func U2048From64 ¶
U2048From64 constructs a Uint2048 from a uint64.
func (Uint2048) Equal ¶
Equal reports whether x == y.
In general, prefer the == operator to using this method.
func (Uint2048) LeadingZeros ¶
LeadingZeros returns the number of leading zeros in x.
type Uint256 ¶
type Uint256 struct {
// contains filtered or unexported fields
}
Uint256 is an unsigned, 256-bit integer.
It can be compared for equality with ==.
func ParseUint256 ¶
ParseUint256 returns the value of s in the given base.
func U256 ¶
U256 constructs a Uint256.
The inputs are in ascending (low to high) order. For example, a uint64 x can be converted to a Uint256, with
U256(x, 0, 0, ...)
or more simply
U256From64(x)
func (Uint256) Equal ¶
Equal reports whether x == y.
In general, prefer the == operator to using this method.
func (Uint256) LeadingZeros ¶
LeadingZeros returns the number of leading zeros in x.
type Uint512 ¶
type Uint512 struct {
// contains filtered or unexported fields
}
Uint512 is an unsigned, 512-bit integer.
It can be compared for equality with ==.
func ParseUint512 ¶
ParseUint512 returns the value of s in the given base.
func U512 ¶
U512 constructs a Uint512.
The inputs are in ascending (low to high) order. For example, a uint64 x can be converted to a Uint512, with
U512(x, 0, 0, ...)
or more simply
U512From64(x)
func (Uint512) Equal ¶
Equal reports whether x == y.
In general, prefer the == operator to using this method.
func (Uint512) LeadingZeros ¶
LeadingZeros returns the number of leading zeros in x.
type Uint96 ¶
type Uint96 struct {
// contains filtered or unexported fields
}
Uint96 is an unsigned, 96-bit integer.
It can be compared for equality with ==.
func ParseUint96 ¶
ParseUint96 returns the value of s in the given base.
func U96 ¶
U96 constructs a Uint96.
The inputs are in ascending (low to high) order. For example, a uint64 x can be converted to a Uint96, with
U96(x, 0, 0, ...)
or more simply
U96From64(x)
func (Uint96) Equal ¶
Equal reports whether x == y.
In general, prefer the == operator to using this method.
func (Uint96) LeadingZeros ¶
LeadingZeros returns the number of leading zeros in x.