Documentation
¶
Index ¶
- func Jacobi(x, y Int) int
- type Float
- func (x Float) Abs() Float
- func (x Float) Acc() big.Accuracy
- func (x Float) Add(y Float) Float
- func (x Float) Append(buf []byte, fmt byte, prec int) []byte
- func (x Float) BigFloat() *big.Float
- func (x Float) Cmp(y Float) int
- func (x *Float) Copy(y Float) *Float
- func (x Float) Float32() (float32, big.Accuracy)
- func (x Float) Float64() (float64, big.Accuracy)
- func (x *Float) Format(s fmt.State, format rune)
- func (x *Float) GobDecode(buf []byte) error
- func (x *Float) GobEncode() ([]byte, error)
- func (x Float) Int() (Int, big.Accuracy)
- func (x Float) Int64() (int64, big.Accuracy)
- func (x Float) IsInf() bool
- func (x Float) IsInt() bool
- func (x Float) MantExp(mant Float) int
- func (x *Float) MarshalText() ([]byte, error)
- func (x *Float) MinPrec() uint
- func (x *Float) Mode() big.RoundingMode
- func (x Float) Mul(y Float) Float
- func (x Float) Neg() Float
- func (x Float) Parse(s string, base int) (Float, int, error)
- func (x Float) Quo(y Float) Float
- func (x Float) Rat(z *big.Rat) (*big.Rat, big.Accuracy)
- func (x *Float) Scan(dbValue interface{}) error
- func (x *Float) Set(y *Float) *Float
- func (x *Float) SetFloat64(y float64) *Float
- func (x *Float) SetInf(signbit bool) *Float
- func (x *Float) SetInt(y *big.Int) *Float
- func (x *Float) SetInt64(y int64) *Float
- func (x Float) SetMantExp(mant Float, exp int) Float
- func (x *Float) SetString(s string) (*Float, bool)
- func (x *Float) SetUint64(y uint64) *Float
- func (x Float) Sign() int
- func (x Float) Signbit() bool
- func (x *Float) String() string
- func (x Float) Sub(y Float) Float
- func (x Float) Uint64() (uint64, big.Accuracy)
- func (x Float) Value() (driver.Value, error)
- type Int
- func (x Int) Abs() Int
- func (x Int) Add(y Int) Int
- func (x Int) And(y Int) Int
- func (x Int) AndNot(y Int) Int
- func (x Int) Append(buf []byte, base int) []byte
- func (x Int) BigInt() *big.Int
- func (n Int) Binomial(k int64) Int
- func (x Int) Bit(i int) uint
- func (x Int) BitLen() int
- func (x *Int) Bits() []big.Word
- func (x Int) Bytes() []byte
- func (x Int) Cmp(y Int) int
- func (x Int) CmpAbs(y Int) int
- func (x Int) Div(y Int) Int
- func (x Int) DivMod(y Int) (Int, Int)
- func (x Int) Exp(y, m Int) Int
- func (x Int) FillBytes(buf []byte) []byte
- func (x Int) Floater(decimals int) string
- func (x *Int) Format(s fmt.State, ch rune)
- func (z Int) GCD(x, y, a, b Int) Int
- func (x *Int) GobDecode(buf []byte) error
- func (x *Int) GobEncode() ([]byte, error)
- func (x Int) Int64() int64
- func (x Int) IsInt64() bool
- func (x Int) IsUint64() bool
- func (x Int) Lsh(n uint) Int
- func (x *Int) MarshalJSON() ([]byte, error)
- func (x *Int) MarshalText() ([]byte, error)
- func (x Int) Mod(y Int) Int
- func (x Int) Mul(y Int) Int
- func (a Int) MulRange(b int64) Int
- func (x Int) Neg() Int
- func (x Int) Not() Int
- func (x Int) Or(y Int) Int
- func (x Int) Pow(y Int) Int
- func (x Int) Quo(y Int) Int
- func (x Int) QuoRem(y Int) (Int, Int)
- func (x *Int) Rand(rnd *rand.Rand, n *Int) *Int
- func (x Int) Rem(y Int) Int
- func (x Int) Rsh(n uint) Int
- func (x *Int) Scan(dbValue interface{}) error
- func (x *Int) Set(y Int) *Int
- func (x *Int) SetBit(i int, b uint) *Int
- func (x *Int) SetBits(abs []big.Word) *Int
- func (x *Int) SetBytes(buf []byte) *Int
- func (x *Int) SetFloat(y Float, decimals int) *Int
- func (x *Int) SetInt64(y int64) *Int
- func (x *Int) SetString(s string, base int) (*Int, bool)
- func (x *Int) SetStringFloat(s string, decimals int) (*Int, error)
- func (x *Int) SetUint64(y uint64) *Int
- func (x Int) Sign() int
- func (x Int) Sqrt() Int
- func (x Int) String() string
- func (x Int) StringFloat(decimals int) string
- func (x Int) Sub(y Int) Int
- func (x Int) Text(base int) string
- func (x Int) TrailingZeroBits() uint
- func (x Int) Uint64() uint64
- func (x *Int) UnmarshalJSON(text []byte) error
- func (x *Int) UnmarshalText(text []byte) error
- func (x Int) Value() (driver.Value, error)
- func (x Int) Xor(y Int) Int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Float ¶
type Float struct {
// contains filtered or unexported fields
}
A nonzero finite Float represents a multi-precision floating point number
sign × mantissa × 2**exponent
with 0.5 <= mantissa < 1.0, and MinExp <= exponent <= MaxExp. A Float may also be zero (+0, -0) or infinite (+Inf, -Inf). All Floats are ordered, and the ordering of two Floats x and y is defined by x.Cmp(y).
Each Float value also has a precision, rounding mode, and accuracy. The precision is the maximum number of mantissa bits available to represent the value. The rounding mode specifies how a result should be rounded to fit into the mantissa bits, and accuracy describes the rounding error with respect to the exact result.
Unless specified otherwise, all operations (including setters) that specify a *Float variable for the result (usually via the receiver with the exception of MantExp), round the numeric result according to the precision and rounding mode of the result variable.
If the provided result precision is 0 (see below), it is set to the precision of the argument with the largest precision value before any rounding takes place, and the rounding mode remains unchanged. Thus, uninitialized Floats provided as result arguments will have their precision set to a reasonable value determined by the operands, and their mode is the zero value for RoundingMode (ToNearestEven).
By setting the desired precision to 24 or 53 and using matching rounding mode (typically ToNearestEven), Float operations produce the same results as the corresponding float32 or float64 IEEE-754 arithmetic for operands that correspond to normal (i.e., not denormal) float32 or float64 numbers. Exponent underflow and overflow lead to a 0 or an Infinity for different values than IEEE-754 because Float exponents have a much larger range.
The zero (uninitialized) value for a Float is ready to use and represents the number +0.0 exactly, with precision 0 and rounding mode ToNearestEven.
Operations always take pointer arguments (*Float) rather than Float values, and each unique Float value requires its own unique *Float pointer. To "copy" a Float value, an existing (or newly allocated) Float must be set to a new value using the Float.Set method; shallow copies of Floats are not supported and may lead to errors.
func NewFloatFromBigFloat ¶
NewFloatFromBigFloat allocates a new Float sets to x.
func NewFloatFromString ¶
NewIntFromString allocates and returns new Float and a boolean indicating of success.
func (Float) Acc ¶
Acc returns the accuracy of x produced by the most recent operation, unless explicitly documented otherwise by that operation.
func (Float) Add ¶
Add returns the rounded sum x+y. If x's precision is 0, it is changed to the larger of x's or y's precision before the operation. Rounding is performed according to x's precision and rounding mode; and x's accuracy reports the result error relative to the exact (not rounded) result. Add panics with ErrNaN if x and y are infinities with opposite signs. The value of z is undefined in that case.
func (Float) Append ¶
Append appends to buf the string form of the floating-point number x, as generated by x.Text, and returns the extended buffer.
func (Float) Cmp ¶
Cmp compares x and y and returns:
-1 if x < y 0 if x == y (incl. -0 == 0, -Inf == -Inf, and +Inf == +Inf) +1 if x > y
func (*Float) Copy ¶
Copy sets x to y, with the same precision, rounding mode, and accuracy as x, and returns x. y is not changed even if x and y are the same.
func (Float) Float32 ¶
Float32 returns the float32 value nearest to x. If x is too small to be represented by a float32 (|x| < math.SmallestNonzeroFloat32), the result is (0, Below) or (-0, Above), respectively, depending on the sign of x. If x is too large to be represented by a float32 (|x| > math.MaxFloat32), the result is (+Inf, Above) or (-Inf, Below), depending on the sign of x.
func (Float) Float64 ¶
Float64 returns the float64 value nearest to x. If x is too small to be represented by a float64 (|x| < math.SmallestNonzeroFloat64), the result is (0, Below) or (-0, Above), respectively, depending on the sign of x. If x is too large to be represented by a float64 (|x| > math.MaxFloat64), the result is (+Inf, Above) or (-Inf, Below), depending on the sign of x.
func (*Float) Format ¶
Format implements fmt.Formatter. It accepts all the regular formats for floating-point numbers ('b', 'e', 'E', 'f', 'F', 'g', 'G', 'x') as well as 'p' and 'v'. See (*Float).Text for the interpretation of 'p'. The 'v' format is handled like 'g'. Format also supports specification of the minimum precision in digits, the output field width, as well as the format flags '+' and ' ' for sign control, '0' for space or zero padding, and '-' for left or right justification. See the fmt package for details.
func (*Float) GobDecode ¶
GobDecode implements the gob.GobDecoder interface. The result is rounded per the precision and rounding mode of z unless z's precision is 0, in which case z is set exactly to the decoded value.
func (*Float) GobEncode ¶
GobEncode implements the gob.GobEncoder interface. The Float value and all its attributes (precision, rounding mode, accuracy) are marshaled.
func (Float) Int ¶
Int returns the result of truncating x towards zero; or nil if x is an infinity. The result is Exact if x.IsInt(); otherwise it is Below for x > 0, and Above for x < 0.
func (Float) Int64 ¶
Int64 returns the integer resulting from truncating x towards zero. If math.MinInt64 <= x <= math.MaxInt64, the result is Exact if x is an integer, and Above (x < 0) or Below (x > 0) otherwise. The result is (math.MinInt64, Above) for x < math.MinInt64, and (math.MaxInt64, Below) for x > math.MaxInt64.
func (Float) MantExp ¶
MantExp breaks x into its mantissa and exponent components and returns the exponent. If a non-nil mant argument is provided its value is set to the mantissa of x, with the same precision and rounding mode as x. The components satisfy x == mant × 2**exp, with 0.5 <= |mant| < 1.0. Calling MantExp with a nil argument is an efficient way to get the exponent of the receiver.
Special cases are:
( ±0).MantExp(mant) = 0, with mant set to ±0 (±Inf).MantExp(mant) = 0, with mant set to ±Inf
x and mant may be the same in which case x is set to its mantissa value.
func (*Float) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. Only the Float value is marshaled (in full precision), other attributes such as precision or accuracy are ignored.
func (*Float) MinPrec ¶
MinPrec returns the minimum precision required to represent x exactly (i.e., the smallest prec before x.SetPrec(prec) would start rounding x). The result is 0 for |x| == 0 and |x| == Inf.
func (Float) Mul ¶
Mul returns the rounded product x*y. Precision, rounding, and accuracy reporting are as for Add. Mul panics with ErrNaN if one operand is zero and the other operand an infinity. The value of z is undefined in that case.
func (Float) Parse ¶
Parse parses s which must contain a text representation of a floating- point number with a mantissa in the given conversion base (the exponent is always a decimal number), or a string representing an infinite value. check math/big.Float.Parse for more inforamtions.
func (Float) Quo ¶
Quo returns the rounded quotient x/y. Precision, rounding, and accuracy reporting are as for Add. Quo panics with ErrNaN if both operands are zero or infinities. The value of z is undefined in that case.
func (Float) Rat ¶
Rat returns the rational number corresponding to x; or nil if x is an infinity. The result is Exact if x is not an Inf. If a non-nil *Rat argument z is provided, Rat stores the result in z instead of allocating a new Rat.
func (*Float) Set ¶
Set sets x to the (possibly rounded) value of y and returns x. If x's precision is 0, it is changed to the precision of y before setting x (and rounding will have no effect). Rounding is performed according to x's precision and rounding mode; and x's accuracy reports the result error relative to the exact (not rounded) result.
func (*Float) SetFloat64 ¶
SetFloat64 sets x to the (possibly rounded) value of y and returns x. If x's precision is 0, it is changed to 53 (and rounding will have no effect). SetFloat64 panics with ErrNaN if x is a NaN.
func (*Float) SetInf ¶
SetInf sets x to the infinite Float -Inf if signbit is set, or +Inf if signbit is not set, and returns x. The precision of x is unchanged and the result is always Exact.
func (*Float) SetInt ¶
SetInt sets x to the (possibly rounded) value of y and returns x. If x's precision is 0, it is changed to the larger of x.BitLen() or 64 (and rounding will have no effect).
func (*Float) SetInt64 ¶
SetInt64 sets x to the (possibly rounded) value of y and returns x. If x's precision is 0, it is changed to 64 (and rounding will have no effect).
func (Float) SetMantExp ¶
SetMantExp returns mant × 2**exp and returns new Float. The result has the same precision and rounding mode as mant. SetMantExp is an inverse of MantExp but does not require 0.5 <= |mant| < 1.0. Specifically, for a given x of type *Float, SetMantExp relates to MantExp as follows:
mant := new(Float) new(Float).SetMantExp(mant, x.MantExp(mant)).Cmp(x) == 0
Special cases are:
x.SetMantExp( ±0, exp) = ±0 x.SetMantExp(±Inf, exp) = ±Inf
x and mant may be the same in which case x's exponent is set to exp.
func (*Float) SetString ¶
SetString sets x to the value of s and returns x and a boolean indicating success. s must be a floating-point number of the same format as accepted by Parse, with base argument 0. The entire string (not just a prefix) must be valid for success. If the operation failed, the value of x is undefined but the returned value is nil.
func (*Float) SetUint64 ¶
SetUint64 sets x to the (possibly rounded) value of y and returns x. If x's precision is 0, it is changed to 64 (and rounding will have no effect).
func (Float) Sub ¶
Sub returns the rounded difference x-y. Precision, rounding, and accuracy reporting are as for Add. Sub panics with ErrNaN if x and y are infinities with equal signs. The value of z is undefined in that case.
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.
Operations always take pointer arguments (*Int) rather than Int values, and each unique Int value requires its own unique *Int pointer. To "copy" an Int value, an existing (or newly allocated) Int must be set to a new value using the Int.Set method; shallow copies of Ints are not supported and may lead to errors.
func NewIntFromBigInt ¶
NewIntFromBigInt allocates and returns new Int with value of x.
func NewIntFromFloat ¶
NewIntFromFloat returns new Int set to int part of x which multiplied by 10**decimals
func NewIntFromString ¶
NewIntFromString allocates and returns new Int and a boolean indicating of success.
func NewIntFromStringFloat ¶
NewIntFromStringFloat allocates and returns a Int with value of int part of s which multiplied by 10**decimals
func (Int) BigInt ¶
BigInt returns underlying bigInt it's a copy of BigInt so it's safe to modify or edit.
func (Int) Bit ¶
Bit returns the value of the i'th bit of x. That is, it returns (x>>i)&1. The bit index i must be >= 0.
func (Int) BitLen ¶
BitLen returns the length of the absolute value of x in bits. The bit length of 0 is 0.
func (*Int) Bits ¶
Bits provides raw (unchecked but fast) access to x by returning its absolute value as a little-endian Word slice. The result and x share the same underlying array. Bits is intended to support implementation of missing low-level Int functionality outside this package; it should be avoided otherwise.
func (Int) Bytes ¶
Bytes returns the absolute value of x as a big-endian byte slice.
To use a fixed length slice, or a preallocated one, use FillBytes.
func (Int) CmpAbs ¶
CmpAbs compares the absolute values of x and y and returns:
-1 if |x| < |y| 0 if |x| == |y| +1 if |x| > |y|
func (Int) Div ¶
Div returns the quotient x/y for y != 0. If y == 0, a division-by-zero run-time panic occurs. Div implements Euclidean division (unlike Go); see DivMod for more details.
func (Int) DivMod ¶
DivMod returns the quotient x div y and z to the modulus x mod y for more informations, go to big.Int
func (Int) Exp ¶
Exp returns x**y mod |m| (i.e. the sign of m is ignored). If m == nil or m == 0, x = x**y unless y <= 0 then x = 1. If m != 0, y < 0, and y and m are not relatively prime, x is unchanged and nil is returned.
Modular exponentiation of inputs of a particular size is not a cryptographically constant-time operation.
func (Int) FillBytes ¶
FillBytes sets buf to the absolute value of x, storing it as a zero-extended big-endian byte slice, and returns buf.
If the absolute value of x doesn't fit in buf, FillBytes will panic.
func (Int) Floater ¶
Floater returns strings representation of x in format of float. for example if you a number 101 which it has 1 decimal, you can convert it to float string, `x.StringFloat(1) == "10.1"` it is like to StringFloat but using strings instead casting to big float
func (*Int) Format ¶
Format implements fmt.Formatter. It accepts the formats 'b' (binary), 'o' (octal with 0 prefix), 'O' (octal with 0o prefix), 'd' (decimal), 'x' (lowercase hexadecimal), and 'X' (uppercase hexadecimal). Also supported are the full suite of package fmt's format flags for integral types, including '+' and ' ' for sign control, '#' for leading zero in octal and for hexadecimal, a leading "0x" or "0X" for "%#x" and "%#X" respectively, specification of minimum digits precision, output field width, space or zero padding, and '-' for left or right justification.
func (Int) GCD ¶
GCD sets x to the greatest common divisor of a and b and returns z. for more informations, check big.Int GCD method.
func (Int) Int64 ¶
Int64 returns the int64 representation of x. If x cannot be represented in an int64, the result is undefined.
func (*Int) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Int) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Int) Mod ¶
Mod returns the modulus x%y for y != 0. If y == 0, a division-by-zero run-time panic occurs. Mod implements Euclidean modulus (unlike Go); see DivMod for more details.
func (Int) MulRange ¶
MulRange returns the product of all integers in the range [a, b] inclusively. If a > b (empty range), the result is 1.
func (Int) Quo ¶
Quo returns the quotient x/y for y != 0. If y == 0, a division-by-zero run-time panic occurs. Quo implements truncated division (like Go); see QuoRem for more details.
func (Int) QuoRem ¶
QuoRem return the quotient x/y and the remainder x%y for more informations, check big.Int QuoRem method
func (*Int) Rand ¶
Rand sets x to a pseudo-random number in [0, n) and returns x.
As this uses the math/rand package, it must not be used for security-sensitive work. Use crypto/rand.Int instead.
func (Int) Rem ¶
Rem returns the remainder x%y for y != 0. If y == 0, a division-by-zero run-time panic occurs. Rem implements truncated modulus (like Go); see QuoRem for more details.
func (*Int) SetBit ¶
SetBit set i'th bit to b (0 or 1). That is, if b is 1 SetBit sets x = y | (1 << i); if b is 0 SetBit sets x = y &^ (1 << i). If b is not 0 or 1, SetBit will panic.
func (*Int) SetBits ¶
SetBits provides raw (unchecked but fast) access to z by setting its value to abs, interpreted as a little-endian Word slice, and returning z. The result and abs share the same underlying array. SetBits is intended to support implementation of missing low-level Int functionality outside this package; it should be avoided otherwise.
func (*Int) SetBytes ¶
SetBytes interprets buf as the bytes of a big-endian unsigned integer, sets x to that value, and returns x.
func (*Int) SetString ¶
SetString sets x to the value of s, interpreted in the given base, and returns x and a boolean indicating success. The entire string (not just a prefix) must be valid for success.
The base argument must be 0 or a value between 2 and MaxBase. For base 0, the number prefix determines the actual base: A prefix of “0b” or “0B” selects base 2, “0”, “0o” or “0O” selects base 8, and “0x” or “0X” selects base 16. Otherwise, the selected base is 10 and no prefix is accepted.
For bases <= 36, lower and upper case letters are considered the same: The letters 'a' to 'z' and 'A' to 'Z' represent digit values 10 to 35. For bases > 36, the upper case letters 'A' to 'Z' represent the digit values 36 to 61.
For base 0, an underscore character “_” may appear between a base prefix and an adjacent digit, and between successive digits; such underscores do not change the value of the number. Incorrect placement of underscores is reported as an error if there are no other errors. If base != 0, underscores are not recognized and act like any other character that is not a valid digit.
func (*Int) SetStringFloat ¶
SetStringFloat sets x to int part s which multplied by 10**decimals and an error
func (Int) Sqrt ¶
Sqrt returns ⌊√x⌋, the largest integer such that z² ≤ x,. It panics if x is negative.
func (Int) StringFloat ¶
StringFloat returns strings representation of x in format of float. for example if you a number 101 which it has 1 decimal, you can convert it to float string, `x.StringFloat(1) == "10.1"`
func (Int) Text ¶
Text returns the string representation of x in the given base. Base must be between 2 and 62, inclusive. The result uses the lower-case letters 'a' to 'z' for digit values 10 to 35, and the upper-case letters 'A' to 'Z' for digit values 36 to 61. No prefix (such as "0x") is added to the string. If x is a nil pointer it returns "<nil>".
func (Int) TrailingZeroBits ¶
TrailingZeroBits returns the number of consecutive least significant zero bits of |x|.
func (Int) Uint64 ¶
Uint64 returns the uint64 representation of x. If x cannot be represented in a uint64, the result is undefined.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Int) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.