uint128

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2025 License: BSD-3-Clause, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxUint64Str  = "18446744073709551615"
	MaxUint128Str = "340282366920938463463374607431768211455"

	MaxStrLen       = 39 // maximum number of digits in a 128-bit unsigned integer
	MaxStrLen64     = 20 // maximum number of digits in a 64-bit unsigned integer
	MaxSafeStrLen64 = 19 // maximum number of digits that can be safely parsed as a 64-bit unsigned integer

	ZeroStr = "0"
)

Variables

View Source
var (
	Zero = Uint128{}

	Max   = Uint128{math.MaxUint64, math.MaxUint64}
	Max64 = Uint128{math.MaxUint64, 0}

	Pow10Uint64 = [...]uint64{
		1,
		10,
		100,
		1000,
		10000,
		100000,
		1000000,
		10000000,
		100000000,
		1000000000,
		10000000000,
		100000000000,
		1000000000000,
		10000000000000,
		100000000000000,
		1000000000000000,
		10000000000000000,
		100000000000000000,
		1000000000000000000,
		10000000000000000000,
	}

	Pow10Uint128 = [...]Uint128{
		{Lo: 1},
		{Lo: 10},
		{Lo: 100},
		{Lo: 1000},
		{Lo: 10000},
		{Lo: 100000},
		{Lo: 1000000},
		{Lo: 10000000},
		{Lo: 100000000},
		{Lo: 1000000000},
		{Lo: 10000000000},
		{Lo: 100000000000},
		{Lo: 1000000000000},
		{Lo: 10000000000000},
		{Lo: 100000000000000},
		{Lo: 1000000000000000},
		{Lo: 10000000000000000},
		{Lo: 100000000000000000},
		{Lo: 1000000000000000000},
		{Lo: 10000000000000000000},
		{Lo: 7766279631452241920, Hi: 5},
		{Lo: 3875820019684212736, Hi: 54},
		{Lo: 1864712049423024128, Hi: 542},
		{Lo: 200376420520689664, Hi: 5421},
		{Lo: 2003764205206896640, Hi: 54210},
		{Lo: 1590897978359414784, Hi: 542101},
		{Lo: 15908979783594147840, Hi: 5421010},
		{Lo: 11515845246265065472, Hi: 54210108},
		{Lo: 4477988020393345024, Hi: 542101086},
		{Lo: 7886392056514347008, Hi: 5421010862},
		{Lo: 5076944270305263616, Hi: 54210108624},
		{Lo: 13875954555633532928, Hi: 542101086242},
		{Lo: 9632337040368467968, Hi: 5421010862427},
		{Lo: 4089650035136921600, Hi: 54210108624275},
		{Lo: 4003012203950112768, Hi: 542101086242752},
		{Lo: 3136633892082024448, Hi: 5421010862427522},
		{Lo: 12919594847110692864, Hi: 54210108624275221},
		{Lo: 68739955140067328, Hi: 542101086242752217},
		{Lo: 687399551400673280, Hi: 5421010862427522170},
	}
)

Functions

func QuoRem256By128

func QuoRem256By128(u Uint128, carry Uint128, v Uint128) (Uint128, Uint128, errors.Error)

fastQuo returns quotient and remainder of u/v

Types

type Uint128

type Uint128 struct {
	Lo uint64
	Hi uint64
}

func FromBigInt

func FromBigInt(i *big.Int) (Uint128, errors.Error)

func FromBytes

func FromBytes(bs [16]byte) Uint128

func FromBytesBigEndian

func FromBytesBigEndian(b [16]byte) Uint128

func FromString

func FromString(s string) (Uint128, errors.Error)

func FromUint64

func FromUint64(u uint64) Uint128

func QuoRem192By64

func QuoRem192By64(u Uint128, carry uint64, v uint64) (Uint128, uint64, errors.Error)

QuoRem192By64 return q, r which: q must be a u128 u = q*v + r Returns error if u.carry >= v, because the result can't fit into u128

func SubUnsafe

func SubUnsafe(u Uint128, v Uint128) Uint128

SubUnsafe returns u - v with u >= v must be called only when u >= v or the result will be incorrect

func (Uint128) Add

func (self Uint128) Add(other Uint128) (Uint128, errors.Error)

func (Uint128) Add64

func (self Uint128) Add64(other uint64) (Uint128, errors.Error)

func (Uint128) And

func (self Uint128) And(other Uint128) Uint128

func (Uint128) And64

func (self Uint128) And64(other uint64) Uint128

func (Uint128) AppendBytes

func (self Uint128) AppendBytes(bs []byte) []byte

func (Uint128) AppendBytesBigEndian

func (self Uint128) AppendBytesBigEndian(bs []byte) []byte

func (Uint128) BigInt

func (self Uint128) BigInt() *big.Int

func (Uint128) BitLen

func (self Uint128) BitLen() int

func (Uint128) Bytes

func (self Uint128) Bytes() [16]byte

func (Uint128) BytesBigEndian

func (self Uint128) BytesBigEndian() [16]byte

func (Uint128) Compare

func (self Uint128) Compare(other Uint128) int

func (Uint128) Div

func (self Uint128) Div(other Uint128) (Uint128, errors.Error)

func (Uint128) Div64

func (self Uint128) Div64(other uint64) (Uint128, errors.Error)

func (Uint128) Equal

func (self Uint128) Equal(other Uint128) bool

func (Uint128) IsZero

func (self Uint128) IsZero() bool

func (Uint128) LeadingZeroBitsCount

func (self Uint128) LeadingZeroBitsCount() int

func (Uint128) Lsh

func (self Uint128) Lsh(n uint) Uint128

func (Uint128) MarshalText

func (self Uint128) MarshalText() ([]byte, error)

func (Uint128) Mod

func (self Uint128) Mod(other Uint128) (Uint128, errors.Error)

func (Uint128) Mod64

func (self Uint128) Mod64(other uint64) (uint64, errors.Error)

func (Uint128) Mul

func (self Uint128) Mul(other Uint128) (Uint128, errors.Error)

func (Uint128) Mul64

func (self Uint128) Mul64(other uint64) (Uint128, errors.Error)

func (Uint128) MulCarry

func (self Uint128) MulCarry(other Uint128) (Uint128, Uint128)

MulCarry returns self * other and carry.

func (Uint128) NonZeroBitsCount

func (self Uint128) NonZeroBitsCount() int

func (Uint128) Or

func (self Uint128) Or(other Uint128) Uint128

func (Uint128) Or64

func (self Uint128) Or64(other uint64) Uint128

func (Uint128) PutBytes

func (self Uint128) PutBytes(bs []byte) errors.Error

func (Uint128) PutBytesBigEndian

func (self Uint128) PutBytesBigEndian(bs []byte) errors.Error

func (Uint128) QuoRem

func (self Uint128) QuoRem(other Uint128) (Uint128, Uint128, errors.Error)

func (Uint128) QuoRem64

func (self Uint128) QuoRem64(other uint64) (Uint128, uint64, errors.Error)

func (Uint128) ReverseBits

func (self Uint128) ReverseBits() Uint128

func (Uint128) ReverseBytes

func (self Uint128) ReverseBytes() Uint128

func (Uint128) RotateBitsLeft

func (self Uint128) RotateBitsLeft(k int) Uint128

func (Uint128) RotateBitsRight

func (self Uint128) RotateBitsRight(k int) Uint128

func (Uint128) Rsh

func (self Uint128) Rsh(n uint) Uint128

func (*Uint128) Scan

func (self *Uint128) Scan(s fmt.ScanState, ch rune) error

func (Uint128) String

func (self Uint128) String() string

func (Uint128) StringToBuf

func (self Uint128) StringToBuf(buf []byte) int

func (Uint128) Sub

func (self Uint128) Sub(other Uint128) (Uint128, errors.Error)

func (Uint128) Sub64

func (self Uint128) Sub64(other uint64) (Uint128, errors.Error)

func (Uint128) TrailingZeroBitsCount

func (self Uint128) TrailingZeroBitsCount() int

func (Uint128) Uint64

func (self Uint128) Uint64() (uint64, errors.Error)

func (*Uint128) UnmarshalText

func (self *Uint128) UnmarshalText(b []byte) error

func (Uint128) Xor

func (self Uint128) Xor(other Uint128) Uint128

func (Uint128) Xor64

func (self Uint128) Xor64(other uint64) Uint128

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL