big

package
v0.0.0-...-5288846 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(z, x *big.Int) *big.Int

Abs sets z to |x| (the absolute value of x) and returns z.

func Add

func Add(x, y *big.Int) *big.Int

Add returns the sum of x+y.

func And

func And(x, y *big.Int) *big.Int

And sets z = x & y and returns z.

func AndNot

func AndNot(x, y *big.Int) *big.Int

AndNot sets z = x &^ y and returns z.

func Binomial

func Binomial(n, k int64) *big.Int

Binomial returns the binomial coefficient of (n, k).

func Bit

func Bit(x *big.Int, i int) uint

Bit returns the value of the i'th bit of x. That is, it returns (x>>i)&1. The bit index i must be >= 0.

func BitLen

func BitLen(z *big.Int) int

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

func Bits

func Bits(x *big.Int) []big.Word

Bits provides raw (unchecked but fast) access to x by returning its absolute value as a little-endian Word slice. The result and x share the same underlying array. Bits is intended to support implementation of missing low-level Int functionality outside this package; it should be avoided otherwise.

func Bytes

func Bytes(z *big.Int) []byte

Bytes returns the absolute value of x as a big-endian byte slice.

func Cmp

func Cmp(x, y *big.Int) (r int)

Cmp compares x and y and returns:

-1 if x <  y
 0 if x == y
+1 if x >  y

func CmpAbs

func CmpAbs(x, y *big.Int) int

CmpAbs compares the absolute values of x and y and returns:

-1 if |x| <  |y|
 0 if |x| == |y|
+1 if |x| >  |y|

func Div

func Div(x, y *big.Int) *big.Int

Div returns the quotient x/y for y != 0. If y == 0, a division-by-zero run-time panic occurs. Div implements Euclidean division (unlike Go); see DivMod for more details.

func DivMod

func DivMod(x, y, m *big.Int) (*big.Int, *big.Int)

DivMod sets z to the quotient x div y and m to the modulus x mod y and returns the pair (z, m) for y != 0. If y == 0, a division-by-zero run-time panic occurs.

DivMod implements Euclidean division and modulus (unlike Go):

q = x div y  such that
m = x - y*q  with 0 <= m < |y|

(See Raymond T. Boute, “The Euclidean definition of the functions div and mod”. ACM Transactions on Programming Languages and Systems (TOPLAS), 14(2):127-144, New York, NY, USA, 4/1992. ACM press.) See QuoRem for T-division and modulus (like Go).

func Exp

func Exp(x, y, m *big.Int) *big.Int

Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z. If m == nil or m == 0, z = x**y unless y <= 0 then z = 1. If m > 0, y < 0, and x and n are not relatively prime, z is unchanged and nil is returned.

Modular exponentation of inputs of a particular size is not a cryptographically constant-time operation.

func GCD

func GCD(x, y, a, b *big.Int) *big.Int

GCD sets z to the greatest common divisor of a and b, which both must be > 0, and returns z. If x or y are not nil, GCD sets their value such that z = a*x + b*y. If either a or b is <= 0, GCD sets z = x = y = 0.

func Int64

func Int64(x *big.Int) int64

Int64 returns the int64 representation of x. If x cannot be represented in an int64, the result is undefined.

func IsInt64

func IsInt64(x *big.Int) bool

IsInt64 reports whether x can be represented as an int64.

func IsUint64

func IsUint64(x *big.Int) bool

IsUint64 reports whether x can be represented as a uint64.

func Jacobi

func Jacobi(x, y *big.Int) int

Jacobi returns the Jacobi symbol (x/y), either +1, -1, or 0. The y argument must be an odd integer.

func Lsh

func Lsh(x *big.Int, n uint) *big.Int

Lsh sets z = x << n and returns z.

func Mod

func Mod(x, y *big.Int) *big.Int

Mod sets z to the modulus x%y for y != 0 and returns z. If y == 0, a division-by-zero run-time panic occurs. Mod implements Euclidean modulus (unlike Go); see DivMod for more details.

func ModInverse

func ModInverse(g, n *big.Int) *big.Int

ModInverse sets z to the multiplicative inverse of g in the ring ℤ/nℤ and returns z. If g and n are not relatively prime, g has no multiplicative inverse in the ring ℤ/nℤ. In this case, z is unchanged and the return value is nil.

func ModSqrt

func ModSqrt(x, p *big.Int) *big.Int

ModSqrt sets z to a square root of x mod p if such a square root exists, and returns z. The modulus p must be an odd prime. If x is not a square mod p, ModSqrt leaves z unchanged and returns nil. This function panics if p is not an odd integer.

func Mul

func Mul(x, y *big.Int) *big.Int

Mul returns the product x*y.

func MulRange

func MulRange(a, b int64) *big.Int

MulRange returns the product of all integers in the range [a, b] inclusively. If a > b (empty range), the result is 1.

func Neg

func Neg(z, x *big.Int) *big.Int

Neg sets z to -x and returns z.

func NewInt

func NewInt(x int64) *big.Int

NewInt allocates and returns a new Int set to x.

func Not

func Not(x *big.Int) *big.Int

Not sets z = ^x and returns z.

func Or

func Or(x, y *big.Int) *big.Int

Or sets z = x | y and returns z.

func Quo

func Quo(x, y *big.Int) *big.Int

Quo returns the quotient x/y for y != 0. If y == 0, a division-by-zero run-time panic occurs. Quo implements truncated division (like Go); see QuoRem for more details.

func QuoRem

func QuoRem(x, y, r *big.Int) (*big.Int, *big.Int)

QuoRem returns the quotient x/y and the remainder x%y and returns the pair (z, r) for y != 0. If y == 0, a division-by-zero run-time panic occurs.

QuoRem implements T-division and modulus (like Go):

q = x/y      with the result truncated to zero
r = x - y*q

(See Daan Leijen, “Division and Modulus for Computer Scientists”.) See DivMod for Euclidean division and modulus (unlike Go).

func Rand

func Rand(rnd *rand.Rand, n *big.Int) *big.Int

Rand sets z to a pseudo-random number in [0, n) and returns z.

As this uses the math/rand package, it must not be used for security-sensitive work. Use crypto/rand.Int instead.

func Rem

func Rem(x, y *big.Int) *big.Int

Rem returns the remainder x%y for y != 0. If y == 0, a division-by-zero run-time panic occurs. Rem implements truncated modulus (like Go); see QuoRem for more details.

func Rsh

func Rsh(x *big.Int, n uint) *big.Int

Rsh sets z = x >> n and returns z.

func Set

func Set(z, x *big.Int) *big.Int

Set sets z to x and returns z.

func SetBit

func SetBit(x *big.Int, i int, b uint) *big.Int

SetBit sets z to x, with x's i'th bit set to b (0 or 1). That is, if b is 1 SetBit sets z = x | (1 << i); if b is 0 SetBit sets z = x &^ (1 << i). If b is not 0 or 1, SetBit will panic.

func SetBits

func SetBits(z *big.Int, abs []big.Word) *big.Int

SetBits provides raw (unchecked but fast) access to z by setting its value to abs, interpreted as a little-endian Word slice, and returning z. The result and abs share the same underlying array. SetBits is intended to support implementation of missing low-level Int functionality outside this package; it should be avoided otherwise.

func SetBytes

func SetBytes(z *big.Int, buf []byte) *big.Int

SetBytes interprets buf as the bytes of a big-endian unsigned integer, sets z to that value, and returns z.

func SetInt64

func SetInt64(z *big.Int, x int64) *big.Int

SetInt64 sets z to x and returns z.

func SetString

func SetString(z *big.Int, s string, base int) (*big.Int, bool)

SetString sets z to the value of s, interpreted in the given base, and returns z and a boolean indicating success. The entire string (not just a prefix) must be valid for success. If SetString fails, the value of z is undefined but the returned value is nil.

The base argument must be 0 or a value between 2 and MaxBase. For base 0, the number prefix determines the actual base: A prefix of “0b” or “0B” selects base 2, “0”, “0o” or “0O” selects base 8, and “0x” or “0X” selects base 16. Otherwise, the selected base is 10 and no prefix is accepted.

For bases <= 36, lower and upper case letters are considered the same: The letters 'a' to 'z' and 'A' to 'Z' represent digit values 10 to 35. For bases > 36, the upper case letters 'A' to 'Z' represent the digit values 36 to 61.

For base 0, an underscore character “_” may appear between a base prefix and an adjacent digit, and between successive digits; such underscores do not change the value of the number. Incorrect placement of underscores is reported as an error if there are no other errors. If base != 0, underscores are not recognized and act like any other character that is not a valid digit.

func SetUint64

func SetUint64(z *big.Int, x uint64) *big.Int

SetUint64 sets z to x and returns z.

func Sign

func Sign(x *big.Int) int

Sign returns:

-1 if x <  0
 0 if x == 0
+1 if x >  0

func Sqrt

func Sqrt(x *big.Int) *big.Int

Sqrt sets z to ⌊√x⌋, the largest integer such that z² ≤ x, and returns z. It panics if x is negative.

func Sub

func Sub(x, y *big.Int) *big.Int

Sub returns the difference of x-y.

func TrailingZeroBits

func TrailingZeroBits(x *big.Int) uint

TrailingZeroBits returns the number of consecutive least significant zero bits of |x|.

func Uint64

func Uint64(x *big.Int) uint64

Uint64 returns the uint64 representation of x. If x cannot be represented in a uint64, the result is undefined.

func Xor

func Xor(x, y *big.Int) *big.Int

Xor sets z = x ^ y and returns z.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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