Documentation ¶
Overview ¶
This package implements multi-precision arithmetic (big numbers). The following numeric types are supported:
- Int signed integers
All methods on Int take the result as the receiver; if it is one of the operands it may be overwritten (and its memory reused). To enable chaining of operations, the result is also returned.
If possible, one should use big over bignum as the latter is headed for deprecation.
Index ¶
- func GcdInt(d, x, y, a, b *Int)
- func ProbablyPrime(z *Int, n int) bool
- type Int
- func (z *Int) Add(x, y *Int) *Int
- func (z *Int) Bytes() []byte
- func (x *Int) Cmp(y *Int) (r int)
- func (z *Int) Div(x, y *Int) (q, r *Int)
- func (z *Int) Exp(x, y, m *Int) *Int
- func (z *Int) Len() int
- func (z *Int) Mod(x, y *Int) (r *Int)
- func (z *Int) Mul(x, y *Int) *Int
- func (z *Int) Neg(x *Int) *Int
- func (z *Int) New(x int64) *Int
- func (z *Int) Rsh(x *Int, n int) *Int
- func (z *Int) Set(x *Int) *Int
- func (z *Int) SetBytes(b []byte) *Int
- func (z *Int) SetString(s string, base int) (*Int, bool)
- func (z *Int) String() string
- func (z *Int) Sub(x, y *Int) *Int
- type Word
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GcdInt ¶
func GcdInt(d, x, y, a, b *Int)
GcdInt sets d to the greatest common divisor of a and b, which must be positive numbers. If x and y are not nil, GcdInt sets x and y such that d = a*x + b*y. If either a or b is not positive, GcdInt sets d = x = y = 0.
func ProbablyPrime ¶
ProbablyPrime performs n Miller-Rabin tests to check whether z is prime. If it returns true, z is prime with probability 1 - 1/4^n. If it returns false, z is not prime.
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.
func (*Int) Exp ¶
Exp sets z = x**y mod m. If m is nil, z = x**y. See Knuth, volume 2, section 4.6.3.
func (*Int) Len ¶
Len returns the length of the absolute value of x in bits. Zero is considered to have a length of one.
func (*Int) SetBytes ¶
SetBytes interprets b as the bytes of a big-endian, unsigned integer and sets x to that value.