big

package
v0.0.0-...-90c9d3a Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 2 Imported by: 0

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

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

func ProbablyPrime(z *Int, n int) bool

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 NewInt

func NewInt(x int64) *Int

NewInt allocates and returns a new Int set to x.

func (*Int) Add

func (z *Int) Add(x, y *Int) *Int

Add computes z = x+y.

func (*Int) Bytes

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

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

func (*Int) Cmp

func (x *Int) Cmp(y *Int) (r int)

Cmp compares x and y. The result is

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

func (*Int) Div

func (z *Int) Div(x, y *Int) (q, r *Int)

Div calculates q = (x-r)/y where 0 <= r < y. The receiver is set to q.

func (*Int) Exp

func (z *Int) Exp(x, y, m *Int) *Int

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

func (z *Int) Len() int

Len returns the length of the absolute value of x in bits. Zero is considered to have a length of one.

func (*Int) Mod

func (z *Int) Mod(x, y *Int) (r *Int)

Mod calculates q = (x-r)/y and returns r.

func (*Int) Mul

func (z *Int) Mul(x, y *Int) *Int

Mul computes z = x*y.

func (*Int) Neg

func (z *Int) Neg(x *Int) *Int

Neg computes z = -x.

func (*Int) New

func (z *Int) New(x int64) *Int

New allocates and returns a new Int set to x.

func (*Int) Rsh

func (z *Int) Rsh(x *Int, n int) *Int

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

func (*Int) Set

func (z *Int) Set(x *Int) *Int

Set sets z to x.

func (*Int) SetBytes

func (z *Int) SetBytes(b []byte) *Int

SetBytes interprets b as the bytes of a big-endian, unsigned integer and sets x to that value.

func (*Int) SetString

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

SetString sets z to the value of s, interpreted in the given base. If base is 0 then SetString attempts to detect the base by at the prefix of s. '0x' implies base 16, '0' implies base 8. Otherwise base 10 is assumed.

func (*Int) String

func (z *Int) String() string

func (*Int) Sub

func (z *Int) Sub(x, y *Int) *Int

Sub computes z = x-y.

type Word

type Word uintptr

Jump to

Keyboard shortcuts

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