Documentation ¶
Index ¶
- type Int
- func (z *Int) Abs(x *Int) *Int
- func (z *Int) Add(x, y *Int) *Int
- func (x *Int) BitLen() int
- func (x *Int) Cmp(y *Int) (r int)
- func (z *Int) Div(x, y *Int) *Int
- func (z *Int) Exp(x, y, m *Int) *Int
- func (x *Int) FillBytes(buf []byte) []byte
- func (z *Int) GCD(x, y, a, b *Int) *Int
- func (z *Int) Mod(x, y *Int) *Int
- func (z *Int) ModInverse(g, n *Int) *Int
- func (z *Int) Mul(x, y *Int) *Int
- func (z *Int) Neg(x *Int) *Int
- func (z *Int) QuoRem(x, y, r *Int) (*Int, *Int)
- func (z *Int) Set(x *Int) *Int
- func (z *Int) SetBytes(buf []byte) *Int
- func (z *Int) SetInt64(x int64) *Int
- func (z *Int) SetUint64(x uint64) *Int
- func (x *Int) Sign() int
- func (z *Int) Sub(x, y *Int) *Int
- type Word
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
An Int represents a signed multi-precision integer. The zero value for an Int represents the value 0.
Operations always take pointer arguments (*Int) rather than Int values, and each unique Int value requires its own unique *Int pointer. To "copy" an Int value, an existing (or newly allocated) Int must be set to a new value using the Int.Set method; shallow copies of Ints are not supported and may lead to errors.
func (*Int) BitLen ¶
BitLen returns the length of the absolute value of x in bits. The bit length of 0 is 0.
func (*Int) Div ¶
Div sets z to the quotient x/y for y != 0 and returns z. If y == 0, a division-by-zero run-time panic occurs. Div implements Euclidean division (unlike Go); see DivMod for more details.
func (*Int) Exp ¶
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 m are not relatively prime, z is unchanged and nil is returned.
Modular exponentiation of inputs of a particular size is not a cryptographically constant-time operation.
func (*Int) FillBytes ¶
FillBytes sets buf to the absolute value of x, storing it as a zero-extended big-endian byte slice, and returns buf.
If the absolute value of x doesn't fit in buf, FillBytes will panic.
func (*Int) GCD ¶
GCD sets z to the greatest common divisor of a and b and returns z. If x or y are not nil, GCD sets their value such that z = a*x + b*y.
a and b may be positive, zero or negative. (Before Go 1.14 both had to be > 0.) Regardless of the signs of a and b, z is always >= 0.
If a == b == 0, GCD sets z = x = y = 0.
If a == 0 and b != 0, GCD sets z = |b|, x = 0, y = sign(b) * 1.
If a != 0 and b == 0, GCD sets z = |a|, x = sign(a) * 1, y = 0.
func (*Int) Mod ¶
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 (*Int) ModInverse ¶
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 (*Int) QuoRem ¶
QuoRem sets z to the quotient x/y and r to 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).