Documentation
¶
Overview ¶
Package xbig provides a more ergonomic interface to the math/big package. It provides functions for creating and manipulating big integers, floats, and rationals, and for performing arithmetic operations on these types.
Index ¶
- func AbsFloat[T floatNums](x T) *big.Float
- func AbsInt[T intNums](x T) *big.Int
- func AbsRat[T ratNums](x T) *big.Rat
- func AddFloat[T, U floatNums](x T, y U) *big.Float
- func AddInt[T, U intNums](x T, y U) *big.Int
- func AddRat[T, U ratNums](x T, y U) *big.Rat
- func AndInt[T, U intNums](x T, y U) *big.Int
- func AndNotInt[T, U intNums](x T, y U) *big.Int
- func CmpAbsInt[T, U intNums](x T, y U) int
- func CmpFloat[T, U floatNums](x T, y U) int
- func CmpInt[T, U intNums](x T, y U) int
- func CmpRat[T, U ratNums](x T, y U) int
- func DivInt[T, U intNums](x T, y U) *big.Int
- func DivModInt[T, U intNums](x T, y U) (*big.Int, *big.Int)
- func E(prec uint) *big.Float
- func ExpFloat[T floatNums](x T) *big.Float
- func ExpInt[T, U intNums](x T, y U) *big.Int
- func ExpModInt[T, U, V intNums](x T, y U, z V) *big.Int
- func FMAFloat[T, U, V floatNums](x T, y U, z V) *big.Float
- func FMAInt[T, U, V intNums](x T, y U, z V) *big.Int
- func FMARat[T, U, V ratNums](x T, y U, z V) *big.Rat
- func GCDInt[T, U intNums](x T, y U) *big.Int
- func GCDPolyInt[T, U intNums](a T, b U) (*big.Int, *big.Int, *big.Int)
- func InvRat[T ratNums](x T) *big.Rat
- func LogBaseFloat[T, U floatNums](a T, b U) *big.Float
- func LogFloat[T floatNums](x T) *big.Float
- func LshInt[T, U intNums](x T, y U) *big.Int
- func ModInt[T, U intNums](x T, y U) *big.Int
- func ModInverseInt[T, U intNums](x T, y U) *big.Int
- func ModSqrtInt[T, U intNums](x T, y U) *big.Int
- func MulFloat[T, U floatNums](x T, y U) *big.Float
- func MulInt[T, U intNums](x T, y U) *big.Int
- func MulRat[T, U ratNums](x T, y U) *big.Rat
- func NegFloat[T floatNums](x T) *big.Float
- func NegInt[T intNums](x T) *big.Int
- func NegRat[T ratNums](x T) *big.Rat
- func NewFloat[T floatNums](x T) *big.Float
- func NewInt[T intNums](x T) *big.Int
- func NewRat[T ratNums](x T) *big.Rat
- func NewRatFrac[T, U ratNums](x T, y U) *big.Rat
- func NotInt[T, U intNums](x T, y U) *big.Int
- func OrInt[T, U intNums](x T, y U) *big.Int
- func Phi(prec uint) *big.Float
- func Pi(prec uint) *big.Float
- func PowFloat[T, U floatNums](x T, y U) *big.Float
- func QuoFloat[T, U floatNums](x T, y U) *big.Float
- func QuoInt[T, U intNums](x T, y U) *big.Int
- func QuoRat[T, U ratNums](x T, y U) *big.Rat
- func QuoRemInt[T, U intNums](x T, y U) (*big.Int, *big.Int)
- func RandInt[T intNums](r *rand.Rand, x T) *big.Int
- func RemInt[T, U intNums](x T, y U) *big.Int
- func RshInt[T, U intNums](x T, y U) *big.Int
- func SetFloat[T floatNums](f *big.Float, x T) *big.Float
- func SetInt[T intNums](f *big.Int, x T) *big.Int
- func SetMantExpFloat[T floatNums](x T, exp int) *big.Float
- func SetModeFloat[T floatNums](x T, mode big.RoundingMode) *big.Float
- func SetPrecFloat[T floatNums](x T, prec uint) *big.Float
- func SetRat[T ratNums](f *big.Rat, x T) *big.Rat
- func SetRatFrac[T, U ratNums](f *big.Rat, x T, y U) *big.Rat
- func SqrtFloat[T floatNums](x T) *big.Float
- func SubFloat[T, U floatNums](x T, y U) *big.Float
- func SubInt[T, U intNums](x T, y U) *big.Int
- func SubRat[T, U ratNums](x T, y U) *big.Rat
- func XorInt[T, U intNums](x T, y U) *big.Int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsFloat ¶
AbsFloat returns the absolute value of the given float value as a new big.Float. The input value is not modified.
See big.Float.Abs for more details.
func AbsInt ¶
AbsInt computes the absolute value of x and returns the result as a new big.Int. The input is unmodified.
See big.Int.Abs for more details.
func AbsRat ¶
AbsRat returns the absolute value of the given rational value as a new big.Rat. The input value is not modified.
See big.Rat.Abs for more details.
func AddFloat ¶
AddFloat adds two float values and returns the result as a new big.Float. The input values are not modified.
See big.Float.Add for more details.
func AddInt ¶
AddInt adds two integers and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Add for more details.
func AddRat ¶
AddRat adds two rational values and returns the result as a new big.Rat. The input values are not modified.
See big.Rat.Add for more details.
func AndInt ¶
AndInt computes the bitwise AND of two integers and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.And for more details.
func AndNotInt ¶
AndNotInt computes the bitwise AND NOT of two integers and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.AndNot for more details.
func CmpAbsInt ¶
func CmpAbsInt[T, U intNums](x T, y U) int
CmpAbsInt compares the absolute values of two integers and returns:
-1 if |x| < |y| 0 if |x| == |y| 1 if |x| > |y|
The inputs are unmodified.
See big.Int.CmpAbs for more details.
func CmpFloat ¶
func CmpFloat[T, U floatNums](x T, y U) int
CmpFloat compares two float values and returns:
-1 if x < y 0 if x == y 1 if x > y
The input values are not modified.
See big.Float.Cmp for more details.
func CmpInt ¶
func CmpInt[T, U intNums](x T, y U) int
CmpInt compares two integers and returns:
-1 if x < y 0 if x == y 1 if x > y
The inputs are unmodified.
See big.Int.Cmp for more details.
func CmpRat ¶
func CmpRat[T, U ratNums](x T, y U) int
CmpRat compares two rational values and returns:
-1 if x < y 0 if x == y 1 if x > y
The input values are not modified.
See big.Rat.Cmp for more details.
func DivInt ¶
DivInt divides two integers and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Div for more details.
func DivModInt ¶
DivModInt divides two integers and returns the quotient and remainder as two new [big.Int]s. The inputs are unmodified.
See big.Int.DivMod for more details.
func ExpFloat ¶ added in v0.2.0
ExpFloat computes e^x and returns the result as a new big.Float. The input value is not modified.
See github.com/ALTree/bigfloat.Exp for more details.
func ExpInt ¶
ExpInt computes x to the power of y and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Exp for more details.
func ExpModInt ¶
ExpModInt computes x to the power of y modulo z and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Exp for more details.
func FMAFloat ¶ added in v0.2.0
FMAFloat computes the fused multiply-add of x, y, and z and returns the result as a new big.Float. The input values are not modified. The precision of the result is the maximum of the precision of x, y, and z.
func FMAInt ¶ added in v0.2.0
FMAInt computes the fused multiply-add of x, y, and z and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.FMA for more details.
func FMARat ¶ added in v0.2.0
FMARat computes the fused multiply-add of three rational values and returns the result as a new big.Rat. The inputs are not modified.
func GCDInt ¶
GCDInt computes the greatest common divisor of x and y and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.GCD for more details.
func GCDPolyInt ¶ added in v0.2.0
GCDPolyInt computes the greatest common divisor of x and y and returns the result as a new big.Int, and two new [big.Int]s that are the coefficients of the GCD polynomial. The inputs are unmodified.
See big.Int.GCD for more details.
func InvRat ¶
InvRat returns the inverse of the given rational value as a new big.Rat. The input value is not modified.
See big.Rat.Inv for more details.
func LogBaseFloat ¶ added in v0.2.1
LogBaseFloat computes the logarithm of a in base b and returns the result as a new big.Float. The input values are not modified.
func LogFloat ¶ added in v0.2.0
LogFloat computes the natural logarithm of x and returns the result as a new big.Float. The input value is not modified.
See github.com/ALTree/bigfloat.Log for more details.
func LshInt ¶
LshInt computes the left shift of x by y and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Lsh for more details.
func ModInt ¶
ModInt computes the modulus of two integers and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Mod for more details.
func ModInverseInt ¶
ModInverseInt computes the modular inverse of x modulo y and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.ModInverse for more details.
func ModSqrtInt ¶ added in v0.2.0
ModSqrtInt computes the modular square root of x modulo y and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.ModSqrt for more details.
func MulFloat ¶
MulFloat multiplies two float values and returns the result as a new big.Float. The input values are not modified.
See big.Float.Mul for more details.
func MulInt ¶
MulInt multiplies two integers and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Mul for more details.
func MulRat ¶
MulRat multiplies two rational values and returns the result as a new big.Rat. The input values are not modified.
See big.Rat.Mul for more details.
func NegFloat ¶
NegFloat returns the negation of the given float value as a new big.Float. The input value is not modified.
See big.Float.Neg for more details.
func NegInt ¶
NegInt computes the negation of x and returns the result as a new big.Int. The input is unmodified.
See big.Int.Neg for more details.
func NegRat ¶
NegRat returns the negation of the given rational value as a new big.Rat. The input value is not modified.
See big.Rat.Neg for more details.
func NewFloat ¶
NewFloat creates a new big.Float from the given float value. The input is not modified. If the input is a string, it is parsed using [*math/big.Float).SetString(x.] The function returns the new big.Float on success. On failure, it returns nil. The precision of the new big.Float depends on the input value precision.
func NewInt ¶
NewInt creates a new big.Int from the given integer value. The input is not modified. The function the new big.Int on success. On failure, it returns nil.
func NewRat ¶
NewRat creates a new big.Rat from the given rational value. The input is not modified. If the input is a string, it is parsed using [*math/big.Rat.SetString(x)]. The function returns the new big.Rat on success. On failure, it returns nil.
func NewRatFrac ¶
NewRatFrac creates a new big.Rat from the given rational values. The inputs are not modified.
func NotInt ¶
NotInt computes the bitwise NOT of x and returns the result as a new big.Int. The input is unmodified.
See big.Int.Not for more details.
func OrInt ¶
OrInt computes the bitwise OR of two integers and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Or for more details.
func PowFloat ¶ added in v0.2.0
PowFloat computes x^y and returns the result as a new big.Float. The input values are not modified.
See github.com/ALTree/bigfloat.Pow for more details.
func QuoFloat ¶ added in v0.2.0
QuoFloat divides two float values and returns the result as a new big.Float. The input values are not modified.
See big.Float.Quo for more details.
func QuoInt ¶
QuoInt divides two integers and returns the quotient as a new big.Int. The inputs are unmodified.
See big.Int.Quo for more details.
func QuoRat ¶
QuoRat divides two rational values and returns the result as a new big.Rat. The input values are not modified.
See big.Rat.Quo for more details.
func QuoRemInt ¶
QuoRemInt divides two integers and returns the quotient and remainder as two new [big.Int]s. The inputs are unmodified.
See big.Int.QuoRem for more details.
func RandInt ¶
RandInt generates a random integer in the range [0, x) and returns it as a new big.Int. The input x is unmodified.
See big.Int.Rand for more details.
func RemInt ¶
RemInt computes the modulus of two integers and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Rem for more details.
func RshInt ¶
RshInt computes the right shift of x by y and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Rsh for more details.
func SetFloat ¶
SetFloat sets the value of the given big.Float to the given float value. The input float value is not modified. If the input is a string, it is parsed using [*math/big.Float).SetString(x.] If the big.Int is nil, a new one is created. Otherwise, the existing one is modified. The function returns the modified big.Float on success. On failure, it returns nil and the state of the big.Float is undefined. The precision of the modified big.Float depends on the input value precision.
func SetInt ¶
SetInt sets the value of the given big.Int to the given integer value. The input integer value is not modified. If the input is a string, it is parsed using big.Int.SetString(x, 0). If the input is a []byte, it is parsed using big.Int.SetBytes(x).
If the big.Int is nil, a new one is created. Otherwise, the existing one is modified. The function returns the modified big.Int on success. On failure, it returns nil and the state of the big.Int is undefined.
func SetMantExpFloat ¶
SetMantExpFloat sets the mantissa and exponent of the given float value and returns the result as a new big.Float. The input value is not modified.
See big.Float.SetMantExp for more details.
func SetModeFloat ¶
func SetModeFloat[T floatNums](x T, mode big.RoundingMode) *big.Float
SetModeFloat sets the rounding mode of the given float value and returns the result as a new big.Float. The input value is not modified.
See big.Float.SetMode for more details.
func SetPrecFloat ¶
SetPrecFloat sets the precision of the given float value and returns the result as a new big.Float. The input value is not modified.
See big.Float.SetPrec for more details.
func SetRat ¶
SetRat sets the value of the given big.Rat to the given rational value. The input rational value is not modified. If the input is a string, it is parsed using [*math/big.Rat.SetString(x)]. If the input is a float, and it can not be converted to a rational big.Rat, it returns nil. The function returns the modified big.Rat on success. On failure, it returns nil and the state of the big.Rat is undefined.
func SetRatFrac ¶
SetRatFrac sets the value of the given big.Rat to the given rational values. The inputs are not modified.
func SqrtFloat ¶
SqrtFloat returns the square root of the given float value as a new big.Float. The input value is not modified.
See big.Float.Sqrt for more details.
func SubFloat ¶
SubFloat subtracts two float values and returns the result as a new big.Float. The input values are not modified.
See big.Float.Sub for more details.
func SubInt ¶
SubInt subtracts two integers and returns the result as a new big.Int. The inputs are unmodified.
See big.Int.Sub for more details.
func SubRat ¶
SubRat subtracts two rational values and returns the result as a new big.Rat. The input values are not modified.
See big.Rat.Sub for more details.
Types ¶
This section is empty.