num

package
v1.121.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MaxInt128 is the maximum value representable by an Int128.
	MaxInt128 = Int128{/* contains filtered or unexported fields */}
	// MinInt128 is the minimum value representable by an Int128.
	MinInt128 = Int128{/* contains filtered or unexported fields */}
)
View Source
var MaxUint128 = Uint128{/* contains filtered or unexported fields */}

MaxUint128 is the maximum value representable by a Uint128.

Functions

This section is empty.

Types

type Int128

type Int128 struct {
	// contains filtered or unexported fields
}

Int128 represents a signed 128-bit integer.

func Int128From64

func Int128From64(v int64) Int128

Int128From64 creates an Int128 from an int64 value.

func Int128FromBigInt

func Int128FromBigInt(v *big.Int) Int128

Int128FromBigInt creates an Int128 from a big.Int.

func Int128FromComponents

func Int128FromComponents(high, low uint64) Int128

Int128FromComponents creates an Int128 from two uint64 values representing the high and low bits.

func Int128FromFloat64

func Int128FromFloat64(f float64) Int128

Int128FromFloat64 creates an Int128 from a float64 value.

func Int128FromRand

func Int128FromRand(source RandomSource) Int128

Int128FromRand generates a signed 128-bit random integer.

func Int128FromString

func Int128FromString(s string) (Int128, error)

Int128FromString creates an Int128 from a string.

func Int128FromStringNoCheck

func Int128FromStringNoCheck(s string) Int128

Int128FromStringNoCheck creates an Int128 from a string. Unlike Int128FromString, this allows any string as input.

func Int128FromUint64

func Int128FromUint64(v uint64) Int128

Int128FromUint64 creates an Int128 from a uint64 value.

func (Int128) Abs

func (i Int128) Abs() Int128

Abs returns the absolute value of i as an Int128.

func (Int128) AbsUint128

func (i Int128) AbsUint128() Uint128

AbsUint128 returns the absolute value of i as a Uint128.

func (Int128) Add

func (i Int128) Add(n Int128) Int128

Add returns i + n.

func (Int128) Add64

func (i Int128) Add64(n int64) Int128

Add64 returns i + n.

func (Int128) AsBigFloat

func (i Int128) AsBigFloat() (b *big.Float)

AsBigFloat returns the Int128 as a big.Float.

func (Int128) AsBigInt

func (i Int128) AsBigInt() *big.Int

AsBigInt returns the Int128 as a big.Int.

func (Int128) AsFloat64

func (i Int128) AsFloat64() float64

AsFloat64 returns the Int128 as a float64.

func (Int128) AsInt64

func (i Int128) AsInt64() int64

AsInt64 returns the Int128 as an int64.

func (Int128) AsUint128

func (i Int128) AsUint128() Uint128

AsUint128 returns the Int128 as a Uint128.

func (Int128) AsUint64

func (i Int128) AsUint64() uint64

AsUint64 returns the Int128 as a uint64.

func (Int128) Cmp

func (i Int128) Cmp(n Int128) int

Cmp returns 1 if i > n, 0 if i == n, and -1 if i < n.

func (Int128) Cmp64

func (i Int128) Cmp64(n int64) int

Cmp64 returns 1 if i > n, 0 if i == n, and -1 if i < n.

func (Int128) Components

func (i Int128) Components() (high, low uint64)

Components returns the two uint64 values representing the high and low bits.

func (Int128) Dec

func (i Int128) Dec() Int128

Dec returns i - 1.

func (Int128) Div

func (i Int128) Div(n Int128) Int128

Div returns i / n. If n == 0, a divide by zero panic will occur.

func (Int128) Div64

func (i Int128) Div64(n int64) Int128

Div64 returns i / n. If n == 0, a divide by zero panic will occur.

func (Int128) DivMod

func (i Int128) DivMod(n Int128) (q, r Int128)

DivMod returns both the result of i / n as well i % n. If n == 0, a divide by zero panic will occur.

func (Int128) DivMod64

func (i Int128) DivMod64(n int64) (q, r Int128)

DivMod64 returns both the result of i / n as well i % n. If n == 0, a divide by zero panic will occur.

func (Int128) Equal

func (i Int128) Equal(n Int128) bool

Equal returns true if i == n.

func (Int128) Equal64

func (i Int128) Equal64(n int64) bool

Equal64 returns true if i == n.

func (Int128) Float64 added in v1.9.2

func (i Int128) Float64() (float64, error)

Float64 implements json.Number. Intentionally always returns an error, as we never want to emit floating point values into json for Int128.

func (Int128) Format

func (i Int128) Format(s fmt.State, c rune)

Format implements fmt.Formatter.

func (Int128) GreaterThan

func (i Int128) GreaterThan(n Int128) bool

GreaterThan returns true if i > n.

func (Int128) GreaterThan64

func (i Int128) GreaterThan64(n int64) bool

GreaterThan64 returns true if i > n.

func (Int128) GreaterThanOrEqual added in v1.62.0

func (i Int128) GreaterThanOrEqual(n Int128) bool

GreaterThanOrEqual returns true if i >= n.

func (Int128) GreaterThanOrEqual64 added in v1.62.0

func (i Int128) GreaterThanOrEqual64(n int64) bool

GreaterThanOrEqual64 returns true if i >= n.

func (Int128) Inc

func (i Int128) Inc() Int128

Inc returns i + 1.

func (Int128) Int64 added in v1.9.2

func (i Int128) Int64() (int64, error)

Int64 implements json.Number.

func (Int128) IsInt64

func (i Int128) IsInt64() bool

IsInt64 returns true if this value can be represented as an int64 without any loss.

func (Int128) IsUint128

func (i Int128) IsUint128() bool

IsUint128 returns true if this value can be represented as an Uint128 without any loss.

func (Int128) IsUint64

func (i Int128) IsUint64() bool

IsUint64 returns true if this value can be represented as a uint64 without any loss.

func (Int128) IsZero

func (i Int128) IsZero() bool

IsZero returns true if the value is 0.

func (Int128) LessThan

func (i Int128) LessThan(n Int128) bool

LessThan returns true if i < n.

func (Int128) LessThan64

func (i Int128) LessThan64(n int64) bool

LessThan64 returns true if i < n.

func (Int128) LessThanOrEqual added in v1.62.0

func (i Int128) LessThanOrEqual(n Int128) bool

LessThanOrEqual returns true if i <= n.

func (Int128) LessThanOrEqual64 added in v1.62.0

func (i Int128) LessThanOrEqual64(n int64) bool

LessThanOrEqual64 returns true if i <= n.

func (Int128) MarshalJSON

func (i Int128) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Int128) MarshalText

func (i Int128) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Int128) MarshalYAML

func (i Int128) MarshalYAML() (any, error)

MarshalYAML implements yaml.Marshaler.

func (Int128) Mod

func (i Int128) Mod(n Int128) (r Int128)

Mod returns i % n. If n == 0, a divide by zero panic will occur.

func (Int128) Mod64

func (i Int128) Mod64(n int64) (r Int128)

Mod64 returns i % n. If n == 0, a divide by zero panic will occur.

func (Int128) Mul

func (i Int128) Mul(n Int128) Int128

Mul returns i * n.

func (Int128) Mul64

func (i Int128) Mul64(n int64) Int128

Mul64 returns i * n.

func (Int128) Neg

func (i Int128) Neg() Int128

Neg returns -i.

func (*Int128) Scan

func (i *Int128) Scan(state fmt.ScanState, _ rune) error

Scan implements fmt.Scanner.

func (Int128) Sign

func (i Int128) Sign() int

Sign returns 1 if i > 0, 0 if i == 0, and -1 if i < 0.

func (Int128) String

func (i Int128) String() string

String implements fmt.Stringer.

func (Int128) Sub

func (i Int128) Sub(n Int128) Int128

Sub returns i - n.

func (Int128) Sub64

func (i Int128) Sub64(n int64) Int128

Sub64 returns i - n.

func (Int128) ToBigInt

func (i Int128) ToBigInt(b *big.Int)

ToBigInt stores the Int128's value into the specified big.Int.

func (*Int128) UnmarshalJSON

func (i *Int128) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Int128) UnmarshalText

func (i *Int128) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (*Int128) UnmarshalYAML

func (i *Int128) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements yaml.Unmarshaler.

type RandomSource

type RandomSource interface {
	Uint64() uint64
}

RandomSource defines the method required of a source of random bits. This is a subset of the rand.Source64 interface.

type Uint128

type Uint128 struct {
	// contains filtered or unexported fields
}

Uint128 represents an unsigned 128-bit integer.

func Uint128From64

func Uint128From64(v uint64) Uint128

Uint128From64 creates a Uint128 from a uint64 value.

func Uint128FromBigInt

func Uint128FromBigInt(v *big.Int) Uint128

Uint128FromBigInt creates a Uint128 from a big.Int.

func Uint128FromComponents

func Uint128FromComponents(high, low uint64) Uint128

Uint128FromComponents creates a Uint128 from two uint64 values representing the high and low bits.

func Uint128FromFloat64

func Uint128FromFloat64(f float64) Uint128

Uint128FromFloat64 creates a Uint128 from a float64 value.

func Uint128FromRand

func Uint128FromRand(source RandomSource) Uint128

Uint128FromRand generates an unsigned 128-bit random integer.

func Uint128FromString

func Uint128FromString(s string) (Uint128, error)

Uint128FromString creates a Uint128 from a string.

func Uint128FromStringNoCheck

func Uint128FromStringNoCheck(s string) Uint128

Uint128FromStringNoCheck creates a Uint128 from a string. Unlike Uint128FromString, this allows any string as input.

func (Uint128) Add

func (u Uint128) Add(n Uint128) Uint128

Add returns u + n.

func (Uint128) Add64

func (u Uint128) Add64(n uint64) Uint128

Add64 returns u + n.

func (Uint128) And

func (u Uint128) And(n Uint128) Uint128

And returns u & n.

func (Uint128) And64

func (u Uint128) And64(n uint64) Uint128

And64 returns u & n.

func (Uint128) AndNot

func (u Uint128) AndNot(n Uint128) Uint128

AndNot returns u &^ n.

func (Uint128) AndNot64

func (u Uint128) AndNot64(n Uint128) Uint128

AndNot64 returns u &^ n.

func (Uint128) AsBigFloat

func (u Uint128) AsBigFloat() *big.Float

AsBigFloat returns the Uint128 as a big.Float.

func (Uint128) AsBigInt

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

AsBigInt returns the Uint128 as a big.Int.

func (Uint128) AsFloat64

func (u Uint128) AsFloat64() float64

AsFloat64 returns the Uint128 as a float64.

func (Uint128) AsInt128

func (u Uint128) AsInt128() Int128

AsInt128 returns the Uint128 as an Int128.

func (Uint128) AsUint64

func (u Uint128) AsUint64() uint64

AsUint64 returns the Uint128 as a uint64.

func (Uint128) Bit

func (u Uint128) Bit(i int) uint

Bit returns the value of the i'th bit of x. That is, it returns (x>>i)&1. If the bit index is less than 0 or greater than 127, zero will be returned.

func (Uint128) BitLen

func (u Uint128) BitLen() int

BitLen returns the length of the absolute value of u in bits. The bit length of 0 is 0.

func (Uint128) Cmp

func (u Uint128) Cmp(n Uint128) int

Cmp returns 1 if u > n, 0 if u == n, and -1 if u < n.

func (Uint128) Cmp64

func (u Uint128) Cmp64(n uint64) int

Cmp64 returns 1 if u > n, 0 if u == n, and -1 if u < n.

func (Uint128) Components

func (u Uint128) Components() (high, low uint64)

Components returns the two uint64 values representing the high and low bits.

func (Uint128) Dec

func (u Uint128) Dec() Uint128

Dec returns u - 1.

func (Uint128) Div

func (u Uint128) Div(n Uint128) Uint128

Div returns u / n. If n == 0, a divide by zero panic will occur.

func (Uint128) Div64

func (u Uint128) Div64(n uint64) Uint128

Div64 returns u / n. If n == 0, a divide by zero panic will occur.

func (Uint128) DivMod

func (u Uint128) DivMod(n Uint128) (q, r Uint128)

DivMod returns both the result of u / n as well u % n. If n == 0, a divide by zero panic will occur.

func (Uint128) DivMod64

func (u Uint128) DivMod64(n uint64) (q, r Uint128)

DivMod64 returns both the result of u / n as well u % n. If n == 0, a divide by zero panic will occur.

func (Uint128) Equal

func (u Uint128) Equal(n Uint128) bool

Equal returns true if u == n.

func (Uint128) Equal64

func (u Uint128) Equal64(n uint64) bool

Equal64 returns true if u == n.

func (Uint128) Float64 added in v1.9.2

func (u Uint128) Float64() (float64, error)

Float64 implements json.Number. Intentionally always returns an error, as we never want to emit floating point values into json for Uint128.

func (Uint128) Format

func (u Uint128) Format(s fmt.State, c rune)

Format implements fmt.Formatter.

func (Uint128) GreaterThan

func (u Uint128) GreaterThan(n Uint128) bool

GreaterThan returns true if u > n.

func (Uint128) GreaterThan64

func (u Uint128) GreaterThan64(n uint64) bool

GreaterThan64 returns true if u > n.

func (Uint128) GreaterThanOrEqual added in v1.62.0

func (u Uint128) GreaterThanOrEqual(n Uint128) bool

GreaterThanOrEqual returns true if u >= n.

func (Uint128) GreaterThanOrEqual64 added in v1.62.0

func (u Uint128) GreaterThanOrEqual64(n uint64) bool

GreaterThanOrEqual64 returns true if u >= n.

func (Uint128) Inc

func (u Uint128) Inc() Uint128

Inc returns u + 1.

func (Uint128) Int64 added in v1.9.2

func (u Uint128) Int64() (int64, error)

Int64 implements json.Number.

func (Uint128) IsInt128

func (u Uint128) IsInt128() bool

IsInt128 returns true if this value can be represented as an Int128 without any loss.

func (Uint128) IsUint64

func (u Uint128) IsUint64() bool

IsUint64 returns true if this value can be represented as a uint64 without any loss.

func (Uint128) IsZero

func (u Uint128) IsZero() bool

IsZero returns true if the value is 0.

func (Uint128) LeadingZeros

func (u Uint128) LeadingZeros() uint

LeadingZeros returns the number of leading bits set to 0.

func (Uint128) LeftShift

func (u Uint128) LeftShift(n uint) Uint128

LeftShift returns u << n.

func (Uint128) LessThan

func (u Uint128) LessThan(n Uint128) bool

LessThan returns true if u < n.

func (Uint128) LessThan64

func (u Uint128) LessThan64(n uint64) bool

LessThan64 returns true if u < n.

func (Uint128) LessThanOrEqual added in v1.62.0

func (u Uint128) LessThanOrEqual(n Uint128) bool

LessThanOrEqual returns true if u <= n.

func (Uint128) LessThanOrEqual64 added in v1.62.0

func (u Uint128) LessThanOrEqual64(n uint64) bool

LessThanOrEqual64 returns true if u <= n.

func (Uint128) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Uint128) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Uint128) MarshalYAML

func (u Uint128) MarshalYAML() (any, error)

MarshalYAML implements yaml.Marshaler.

func (Uint128) Mod

func (u Uint128) Mod(n Uint128) Uint128

Mod returns u % n. If n == 0, a divide by zero panic will occur.

func (Uint128) Mod64

func (u Uint128) Mod64(n uint64) Uint128

Mod64 returns u % n. If n == 0, a divide by zero panic will occur.

func (Uint128) Mul

func (u Uint128) Mul(n Uint128) Uint128

Mul returns u * n.

func (Uint128) Mul64

func (u Uint128) Mul64(n uint64) (dest Uint128)

Mul64 returns u * n.

func (Uint128) Not

func (u Uint128) Not() Uint128

Not returns ^u.

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(n Uint128) Uint128

Or returns u | n.

func (Uint128) Or64

func (u Uint128) Or64(n uint64) Uint128

Or64 returns u | n.

func (Uint128) RightShift

func (u Uint128) RightShift(n uint) Uint128

RightShift returns u >> n.

func (*Uint128) Scan

func (u *Uint128) Scan(state fmt.ScanState, _ rune) error

Scan implements fmt.Scanner.

func (Uint128) SetBit

func (u Uint128) SetBit(i int, b uint) Uint128

SetBit returns a Uint128 with u's i'th bit set to b (0 or 1). Values of b that are not 0 will be treated as 1. If the bit index is less than 0 or greater than 127, nothing will happen.

func (Uint128) String

func (u Uint128) String() string

String implements fmt.Stringer.

func (Uint128) Sub

func (u Uint128) Sub(n Uint128) Uint128

Sub returns u - n.

func (Uint128) Sub64

func (u Uint128) Sub64(n uint64) Uint128

Sub64 returns u - n.

func (Uint128) ToBigInt

func (u Uint128) ToBigInt(b *big.Int)

ToBigInt stores the Uint128's value into the specified big.Int.

func (Uint128) TrailingZeros

func (u Uint128) TrailingZeros() uint

TrailingZeros returns the number of trailing bits set to 0.

func (*Uint128) UnmarshalJSON

func (u *Uint128) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Uint128) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (*Uint128) UnmarshalYAML

func (u *Uint128) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements yaml.Unmarshaler.

func (Uint128) Xor

func (u Uint128) Xor(n Uint128) Uint128

Xor returns u ^ n.

func (Uint128) Xor64

func (u Uint128) Xor64(n uint64) Uint128

Xor64 returns u ^ n.

Jump to

Keyboard shortcuts

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