Documentation ¶
Overview ¶
Package math provides integer math utilities.
Package bigfloat provides the implementation of a few additional operations for the standard library big.Float type.
Index ¶
- Variables
- func BigMax(x, y *big.Int) *big.Int
- func BigMin(x, y *big.Int) *big.Int
- func BigPow(a, b int64) *big.Int
- func Byte(bigint *big.Int, padlength, n int) byte
- func Exp(base, exponent *big.Int) *big.Int
- func ExpFloat(z *big.Float) *big.Float
- func FirstBitSet(v *big.Int) int
- func Log(z *big.Float) *big.Float
- func MustParseBig256(s string) *big.Int
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func ParseBig256(s string) (*big.Int, bool)
- func Pow(z *big.Float, w *big.Float) *big.Float
- func ReadBits(bigint *big.Int, buf []byte)
- func S256(x *big.Int) *big.Int
- func Sqrt(z *big.Float) *big.Float
- func U256(x *big.Int) *big.Int
- type HexOrDecimal256
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Byte ¶
Byte returns the byte at position n, with the supplied padlength in Little-Endian encoding. n==0 returns the MSB Example: bigint '5', padlength 32, n=31 => 5
func Exp ¶
Exp implements exponentiation by squaring. Exp returns a newly-allocated big integer and does not change base or exponent. The result is truncated to 256 bits.
Courtesy @karalabe and @chfast
func ExpFloat ¶ added in v0.0.6
Exp returns a big.Float representation of exp(z). Precision is the same as the one of the argument. The function returns +Inf when z = +Inf, and 0 when z = -Inf.
func FirstBitSet ¶
FirstBitSet returns the index of the first 1 bit in v, counting from LSB.
func Log ¶ added in v0.0.6
Log returns a big.Float representation of the natural logarithm of z. Precision is the same as the one of the argument. The function panics if z is negative, returns -Inf when z = 0, and +Inf when z = +Inf
func MustParseBig256 ¶
MustParseBig parses s as a 256 bit big integer and panics if the string is invalid.
func PaddedBigBytes ¶
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func ParseBig256 ¶
ParseBig256 parses s as a 256 bit integer in decimal or hexadecimal syntax. Leading zeros are accepted. The empty string parses as zero.
func Pow ¶ added in v0.0.6
Pow returns a big.Float representation of z**w. Precision is the same as the one of the first argument. The function panics when z is negative.
func ReadBits ¶
ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.
func S256 ¶
S256 interprets x as a two's complement number. x must not exceed 256 bits (the result is undefined if it does) and is not modified.
S256(0) = 0 S256(1) = 1 S256(2**255) = -2**255 S256(2**256-1) = -1
Types ¶
type HexOrDecimal256 ¶
HexOrDecimal256 marshals big.Int as hex or decimal.
func (*HexOrDecimal256) MarshalText ¶
func (i *HexOrDecimal256) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (*HexOrDecimal256) UnmarshalText ¶
func (i *HexOrDecimal256) UnmarshalText(input []byte) error
UnmarshalText implements encoding.TextUnmarshaler.