uint128

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 6 Imported by: 1

README

uint128

GoDoc

uint128 is a fork of github.com/lukechampine/uint128. If you want a properly tested codebase, go use that one. This fork implements sql.Scanner instead of fmt.Scanner, along with implementing encoding.BinaryMarshaler and encoding.TextMarshaler. Some panics were removed in favor of error handling

go get github.com/ftqo/uint128

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Zero = Uint128{0, 0}                           // 0
	Max  = Uint128{math.MaxUint64, math.MaxUint64} // 340282366920938463463374607431768211455
)

Functions

This section is empty.

Types

type Uint128

type Uint128 struct {
	Lo, Hi uint64
}

A Uint128 is an unsigned 128-bit number.

func FromBig

func FromBig(i *big.Int) (Uint128, error)

FromBig converts i to a Uint128 value.

func FromBytes

func FromBytes(b []byte) (u Uint128, err error)

FromBytes converts b to a Uint128 value.

func FromBytesBE

func FromBytesBE(b []byte) (Uint128, error)

FromBytesBE converts big-endian b to a Uint128 value.

func FromInt

func FromInt(v uint64) Uint128

FromInt converts v to a Uint128 value.

func FromString

func FromString(s string) (u Uint128, err error)

FromString converts string s into a Uint128 value

func New

func New(lo, hi uint64) Uint128

New returns the Uint128 value (lo,hi).

func (Uint128) Add

func (u Uint128) Add(v Uint128) Uint128

Add returns u+v.

func (Uint128) Add64

func (u Uint128) Add64(v uint64) Uint128

Add64 returns u+v.

func (Uint128) AddWrap

func (u Uint128) AddWrap(v Uint128) Uint128

AddWrap returns u+v with wraparound semantics; for example, Max.AddWrap(FromInt(1)) == Zero.

func (Uint128) AddWrap64

func (u Uint128) AddWrap64(v uint64) Uint128

AddWrap64 returns u+v with wraparound semantics; for example, Max.AddWrap64(1) == Zero.

func (Uint128) And

func (u Uint128) And(v Uint128) Uint128

And returns u&v.

func (Uint128) And64

func (u Uint128) And64(v uint64) Uint128

And64 returns u&v.

func (Uint128) Big

func (u Uint128) Big() *big.Int

Big returns u as a *big.Int.

func (Uint128) Bytes

func (u Uint128) Bytes() []byte

Bytes returns the bytes encoded in Little Endian.

func (Uint128) BytesBE

func (u Uint128) BytesBE() (b []byte)

BytesBE returns the bytes encoded in Big Endian.

func (Uint128) Cmp

func (u Uint128) Cmp(v Uint128) int

Cmp compares u and v and returns:

-1 if u <  v
 0 if u == v
+1 if u >  v

func (Uint128) Cmp64

func (u Uint128) Cmp64(v uint64) int

Cmp64 compares u and v and returns:

-1 if u <  v
 0 if u == v
+1 if u >  v

func (Uint128) Div

func (u Uint128) Div(v Uint128) Uint128

Div returns u/v.

func (Uint128) Div64

func (u Uint128) Div64(v uint64) Uint128

Div64 returns u/v.

func (Uint128) DivRound

func (u Uint128) DivRound(v Uint128) Uint128

DivRound returns u/v, rounded using the remainder.

func (Uint128) Equals

func (u Uint128) Equals(v Uint128) bool

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) Equals64

func (u Uint128) Equals64(v uint64) bool

Equals64 returns true if u == v.

func (Uint128) GreaterThan added in v0.0.2

func (u Uint128) GreaterThan(v Uint128) bool

GreaterThan returns true if u > v.

func (Uint128) GreaterThan64 added in v0.0.2

func (u Uint128) GreaterThan64(v uint64) bool

GreaterThan64 returns true if u > v.

func (Uint128) GreaterThanOrEqual added in v0.0.2

func (u Uint128) GreaterThanOrEqual(v Uint128) bool

GreaterThanOrEqual returns true if u >= v.

func (Uint128) GreaterThanOrEqual64 added in v0.0.2

func (u Uint128) GreaterThanOrEqual64(v uint64) bool

GreaterThanOrEqual64 returns true if u >= v.

func (Uint128) IsZero

func (u Uint128) IsZero() bool

IsZero returns true if u == 0.

func (Uint128) LeadingZeros

func (u Uint128) LeadingZeros() int

LeadingZeros returns the number of leading zero bits in u; the result is 128 for u == 0.

func (Uint128) Len

func (u Uint128) Len() int

Len returns the minimum number of bits required to represent u; the result is 0 for u == 0.

func (Uint128) LessThan added in v0.0.2

func (u Uint128) LessThan(v Uint128) bool

LessThan returns true if u < v.

func (Uint128) LessThan64 added in v0.0.2

func (u Uint128) LessThan64(v uint64) bool

LessThan64 returns true if u < v.

func (Uint128) LessThanOrEqual added in v0.0.2

func (u Uint128) LessThanOrEqual(v Uint128) bool

LessThanOrEqual returns true if u <= v.

func (Uint128) LessThanOrEqual64 added in v0.0.2

func (u Uint128) LessThanOrEqual64(v uint64) bool

LessThanOrEqual64 returns true if u <= v.

func (Uint128) Lsh

func (u Uint128) Lsh(n uint) (s Uint128)

Lsh returns u<<n.

func (Uint128) MarshalBinary

func (u Uint128) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

func (Uint128) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Uint128) Mod

func (u Uint128) Mod(v Uint128) (r Uint128)

Mod returns r = u%v.

func (Uint128) Mod64

func (u Uint128) Mod64(v uint64) (r uint64)

Mod64 returns r = u%v.

func (Uint128) Mul

func (u Uint128) Mul(v Uint128) Uint128

Mul returns u*v, panicking on overflow.

func (Uint128) Mul64

func (u Uint128) Mul64(v uint64) Uint128

Mul64 returns u*v, panicking on overflow.

func (Uint128) MulWrap

func (u Uint128) MulWrap(v Uint128) Uint128

MulWrap returns u*v with wraparound semantics; for example, Max.MulWrap(Max) == 1.

func (Uint128) MulWrap64

func (u Uint128) MulWrap64(v uint64) Uint128

MulWrap64 returns u*v with wraparound semantics; for example, Max.MulWrap64(2) == Max.Sub64(1).

func (Uint128) OnesCount

func (u Uint128) OnesCount() int

OnesCount returns the number of one bits ("population count") in u.

func (Uint128) Or

func (u Uint128) Or(v Uint128) Uint128

Or returns u|v.

func (Uint128) Or64

func (u Uint128) Or64(v uint64) Uint128

Or64 returns u|v.

func (Uint128) QuoRem

func (u Uint128) QuoRem(v Uint128) (q, r Uint128)

QuoRem returns q = u/v and r = u%v.

func (Uint128) QuoRem64

func (u Uint128) QuoRem64(v uint64) (q Uint128, r uint64)

QuoRem64 returns q = u/v and r = u%v.

func (Uint128) Reverse

func (u Uint128) Reverse() Uint128

Reverse returns the value of u with its bits in reversed order.

func (Uint128) ReverseBytes

func (u Uint128) ReverseBytes() Uint128

ReverseBytes returns the value of u with its bytes in reversed order.

func (Uint128) RotateLeft

func (u Uint128) RotateLeft(k int) Uint128

RotateLeft returns the value of u rotated left by (k mod 128) bits.

func (Uint128) RotateRight

func (u Uint128) RotateRight(k int) Uint128

RotateRight returns the value of u rotated left by (k mod 128) bits.

func (Uint128) Rsh

func (u Uint128) Rsh(n uint) (s Uint128)

Rsh returns u>>n.

func (*Uint128) Scan

func (u *Uint128) Scan(src interface{}) error

Scan implements sql.Scanner. It supports reading []byte of length 16 or strings of any length < 40

func (Uint128) String

func (u Uint128) String() string

String returns the base-10 representation of u as a string.

func (Uint128) Sub

func (u Uint128) Sub(v Uint128) Uint128

Sub returns u-v.

func (Uint128) Sub64

func (u Uint128) Sub64(v uint64) Uint128

Sub64 returns u-v.

func (Uint128) SubWrap

func (u Uint128) SubWrap(v Uint128) Uint128

SubWrap returns u-v with wraparound semantics; for example, Zero.SubWrap(FromInt(1)) == Max.

func (Uint128) SubWrap64

func (u Uint128) SubWrap64(v uint64) Uint128

SubWrap64 returns u-v with wraparound semantics; for example, Zero.SubWrap64(1) == Max.

func (Uint128) TrailingZeros

func (u Uint128) TrailingZeros() int

TrailingZeros returns the number of trailing zero bits in u; the result is 128 for u == 0.

func (*Uint128) UnmarshalBinary

func (u *Uint128) UnmarshalBinary(b []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*Uint128) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Uint128) Xor

func (u Uint128) Xor(v Uint128) Uint128

Xor returns u^v.

func (Uint128) Xor64

func (u Uint128) Xor64(v uint64) Uint128

Xor64 returns u^v.

Jump to

Keyboard shortcuts

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