Documentation ¶
Overview ¶
Package bigint contains a very lightweight and high-performance implementation of unsigned multi-precision integers.
Index ¶
- Variables
- type Bigint
- func (x Bigint) Add(y Bigint) Word
- func (x Bigint) BytesLen() int
- func (x Bigint) Cmp(y Bigint) int
- func (x Bigint) MSB() uint
- func (x Bigint) MarshalText() ([]byte, error)
- func (x Bigint) Read(out []byte) (n int, err error)
- func (x Bigint) SetBytes(buf []byte)
- func (x Bigint) String() string
- func (x Bigint) Sub(y Bigint) Word
- func (x *Bigint) UnmarshalText(text []byte) error
- func (x Bigint) Words() []Word
- type Word
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnsupportedOperandSize = errors.New("unsupported operand size") ErrInvalidBufferSize = errors.New("invalid buffer sizer") ErrInvalidLength = errors.New("byte length not a multiple of the word size") ErrMissingPrefix = errors.New("hex string without 0x prefix") )
Errors for bigint package.
Functions ¶
This section is empty.
Types ¶
type Bigint ¶
type Bigint []Word
A Bigint is an unsigned integer x of the form
x = x[n-1]*B^(n-1) + x[n-2]*B^(n-2) + ... + x[1]*B + x[0]
with 0 <= x[i] < B and 0 <= i < n is stored in a slice of length n, with the digits x[i] as the slice elements. The length of the slice never changes and operations are only well-defined for operands of the same length.
func MustParseU384 ¶
MustParseU384 parses s as a Bigint, returning the result. The encoding of s must be the same as in UnmarshalText, it panics when the encoding is not valid.
func ParseU384 ¶
ParseU384 parses s as a Bigint, returning the result. The encoding of s must be the same as in UnmarshalText.
func (Bigint) Add ¶
Add sets x to the sum x+y and returns the carry. The carry output is guaranteed to be 0 or 1.
func (Bigint) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The encoding is the same as returned by String.
func (Bigint) Read ¶
Read reads the big-endian byte representation of x into out and returns the number of bytes read. It returns an error when len(out) <= x.BytesLen() and the bytes cannot be written in one call.
func (Bigint) SetBytes ¶
SetBytes interprets buf as the bytes of a big-endian unsigned integer and sets x to that value.
func (Bigint) String ¶
String returns the hexadecimal representation of x including leading zeroes and with the "0x" prefix.
func (Bigint) Sub ¶
Sub sets x to the difference x-y and returns the borrow. The borrow output is guaranteed to be 0 or 1.
func (*Bigint) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The Bigint is expected in hexadecimal representation starting with the prefix "0x". It must include leading zeroes such that the encoded byte length matches x.BytesLen().