Functions
Abs
method
#
Abs sets z to |x| (the absolute value of x) and returns z.
func (z *Int) Abs(x *Int) *Int
Abs
method
#
Abs sets z to |x| (the absolute value of x) and returns z.
func (z *Rat) Abs(x *Rat) *Rat
Abs
method
#
Abs sets z to the (possibly rounded) value |x| (the absolute value of x)
and returns z.
func (z *Float) Abs(x *Float) *Float
Acc
method
#
Acc returns the accuracy of x produced by the most recent
operation, unless explicitly documented otherwise by that
operation.
func (x *Float) Acc() Accuracy
Add
method
#
Add sets z to the rounded sum x+y and returns z. If z'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 z's precision and rounding mode; and
z'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 (z *Float) Add(x *Float, y *Float) *Float
Add
method
#
Add sets z to the sum x+y and returns z.
func (z *Rat) Add(x *Rat, y *Rat) *Rat
Add
method
#
Add sets z to the sum x+y and returns z.
func (z *Int) Add(x *Int, y *Int) *Int
And
method
#
And sets z = x & y and returns z.
func (z *Int) And(x *Int, y *Int) *Int
AndNot
method
#
AndNot sets z = x &^ y and returns z.
func (z *Int) AndNot(x *Int, y *Int) *Int
Append
method
#
Append appends to buf the string form of the floating-point number x,
as generated by x.Text, and returns the extended buffer.
func (x *Float) Append(buf []byte, fmt byte, prec int) []byte
Append
method
#
Append appends the string representation of x, as generated by
x.Text(base), to buf and returns the extended buffer.
func (x *Int) Append(buf []byte, base int) []byte
AppendText
method
#
AppendText implements the [encoding.TextAppender] interface.
func (x *Rat) AppendText(b []byte) ([]byte, error)
AppendText
method
#
AppendText implements the [encoding.TextAppender] interface.
Only the [Float] value is marshaled (in full precision), other
attributes such as precision or accuracy are ignored.
func (x *Float) AppendText(b []byte) ([]byte, error)
AppendText
method
#
AppendText implements the [encoding.TextAppender] interface.
func (x *Int) AppendText(b []byte) (text []byte, err error)
Binomial
method
#
Binomial sets z to the binomial coefficient C(n, k) and returns z.
func (z *Int) Binomial(n int64, k int64) *Int
Bit
method
#
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 (x *Int) Bit(i int) uint
BitLen
method
#
BitLen returns the length of the absolute value of x in bits.
The bit length of 0 is 0.
func (x *Int) BitLen() int
Bits
method
#
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 (x *Int) Bits() []Word
Bytes
method
#
Bytes returns the absolute value of x as a big-endian byte slice.
To use a fixed length slice, or a preallocated one, use [Int.FillBytes].
func (x *Int) Bytes() []byte
Cmp
method
#
Cmp compares x and y and returns:
- -1 if x < y;
- 0 if x == y;
- +1 if x > y.
func (x *Rat) Cmp(y *Rat) int
Cmp
method
#
Cmp compares x and y and returns:
- -1 if x < y;
- 0 if x == y;
- +1 if x > y.
func (x *Int) Cmp(y *Int) (r int)
Cmp
method
#
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 (x *Float) Cmp(y *Float) int
CmpAbs
method
#
CmpAbs compares the absolute values of x and y and returns:
- -1 if |x| < |y|;
- 0 if |x| == |y|;
- +1 if |x| > |y|.
func (x *Int) CmpAbs(y *Int) int
Copy
method
#
Copy sets z to x, with the same precision, rounding mode, and accuracy as x.
Copy returns z. If x and z are identical, Copy is a no-op.
func (z *Float) Copy(x *Float) *Float
Denom
method
#
Denom returns the denominator of x; it is always > 0.
The result is a reference to x's denominator, unless
x is an uninitialized (zero value) [Rat], in which case
the result is a new [Int] of value 1. (To initialize x,
any operation that sets x will do, including x.Set(x).)
If the result is a reference to x's denominator it
may change if a new value is assigned to x, and vice versa.
func (x *Rat) Denom() *Int
Div
method
#
Div sets z to the quotient x/y for y != 0 and returns z.
If y == 0, a division-by-zero run-time panic occurs.
Div implements Euclidean division (unlike Go); see [Int.DivMod] for more details.
func (z *Int) Div(x *Int, y *Int) *Int
DivMod
method
#
DivMod sets z to the quotient x div y and m to the modulus x mod y
and returns the pair (z, m) for y != 0.
If y == 0, a division-by-zero run-time panic occurs.
DivMod implements Euclidean division and modulus (unlike Go):
q = x div y such that
m = x - y*q with 0 <= m < |y|
(See Raymond T. Boute, “The Euclidean definition of the functions
div and mod”. ACM Transactions on Programming Languages and
Systems (TOPLAS), 14(2):127-144, New York, NY, USA, 4/1992.
ACM press.)
See [Int.QuoRem] for T-division and modulus (like Go).
func (z *Int) DivMod(x *Int, y *Int, m *Int) (*Int, *Int)
Error
method
#
func (err ErrNaN) Error() string
Exp
method
#
Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z.
If m == nil or m == 0, z = x**y unless y <= 0 then z = 1. If m != 0, y < 0,
and x and m are not relatively prime, z is unchanged and nil is returned.
Modular exponentiation of inputs of a particular size is not a
cryptographically constant-time operation.
func (z *Int) Exp(x *Int, y *Int, m *Int) *Int
FillBytes
method
#
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 (x *Int) FillBytes(buf []byte) []byte
Float32
method
#
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 (x *Float) Float32() (float32, Accuracy)
Float32
method
#
Float32 returns the nearest float32 value for x and a bool indicating
whether f represents x exactly. If the magnitude of x is too large to
be represented by a float32, f is an infinity and exact is false.
The sign of f always matches the sign of x, even if f == 0.
func (x *Rat) Float32() (f float32, exact bool)
Float64
method
#
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 (x *Float) Float64() (float64, Accuracy)
Float64
method
#
Float64 returns the nearest float64 value for x and a bool indicating
whether f represents x exactly. If the magnitude of x is too large to
be represented by a float64, f is an infinity and exact is false.
The sign of f always matches the sign of x, even if f == 0.
func (x *Rat) Float64() (f float64, exact bool)
Float64
method
#
Float64 returns the float64 value nearest x,
and an indication of any rounding that occurred.
func (x *Int) Float64() (float64, Accuracy)
FloatPrec
method
#
FloatPrec returns the number n of non-repeating digits immediately
following the decimal point of the decimal representation of x.
The boolean result indicates whether a decimal representation of x
with that many fractional digits is exact or rounded.
Examples:
x n exact decimal representation n fractional digits
0 0 true 0
1 0 true 1
1/2 1 true 0.5
1/3 0 false 0 (0.333... rounded)
1/4 2 true 0.25
1/6 1 false 0.2 (0.166... rounded)
func (x *Rat) FloatPrec() (n int, exact bool)
FloatString
method
#
FloatString returns a string representation of x in decimal form with prec
digits of precision after the radix point. The last digit is rounded to
nearest, with halves rounded away from zero.
func (x *Rat) FloatString(prec int) string
Format
method
#
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 (x *Int) Format(s fmt.State, ch rune)
Format
method
#
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 (x *Float) Format(s fmt.State, format rune)
GCD
method
#
GCD sets z to the greatest common divisor of a and b and returns z.
If x or y are not nil, GCD sets their value such that z = a*x + b*y.
a and b may be positive, zero or negative. (Before Go 1.14 both had
to be > 0.) Regardless of the signs of a and b, z is always >= 0.
If a == b == 0, GCD sets z = x = y = 0.
If a == 0 and b != 0, GCD sets z = |b|, x = 0, y = sign(b) * 1.
If a != 0 and b == 0, GCD sets z = |a|, x = sign(a) * 1, y = 0.
func (z *Int) GCD(x *Int, y *Int, a *Int, b *Int) *Int
GobDecode
method
#
GobDecode implements the [encoding/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 (z *Float) GobDecode(buf []byte) error
GobDecode
method
#
GobDecode implements the [encoding/gob.GobDecoder] interface.
func (z *Rat) GobDecode(buf []byte) error
GobDecode
method
#
GobDecode implements the [encoding/gob.GobDecoder] interface.
func (z *Int) GobDecode(buf []byte) error
GobEncode
method
#
GobEncode implements the [encoding/gob.GobEncoder] interface.
func (x *Rat) GobEncode() ([]byte, error)
GobEncode
method
#
GobEncode implements the [encoding/gob.GobEncoder] interface.
func (x *Int) GobEncode() ([]byte, error)
GobEncode
method
#
GobEncode implements the [encoding/gob.GobEncoder] interface.
The [Float] value and all its attributes (precision,
rounding mode, accuracy) are marshaled.
func (x *Float) GobEncode() ([]byte, error)
Int
method
#
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.
If a non-nil *[Int] argument z is provided, [Int] stores
the result in z instead of allocating a new [Int].
func (x *Float) Int(z *Int) (*Int, Accuracy)
Int64
method
#
Int64 returns the int64 representation of x.
If x cannot be represented in an int64, the result is undefined.
func (x *Int) Int64() int64
Int64
method
#
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 (x *Float) Int64() (int64, Accuracy)
Inv
method
#
Inv sets z to 1/x and returns z.
If x == 0, Inv panics.
func (z *Rat) Inv(x *Rat) *Rat
IsInf
method
#
IsInf reports whether x is +Inf or -Inf.
func (x *Float) IsInf() bool
IsInt
method
#
IsInt reports whether the denominator of x is 1.
func (x *Rat) IsInt() bool
IsInt
method
#
IsInt reports whether x is an integer.
±Inf values are not integers.
func (x *Float) IsInt() bool
IsInt64
method
#
IsInt64 reports whether x can be represented as an int64.
func (x *Int) IsInt64() bool
IsUint64
method
#
IsUint64 reports whether x can be represented as a uint64.
func (x *Int) IsUint64() bool
Jacobi
function
#
Jacobi returns the Jacobi symbol (x/y), either +1, -1, or 0.
The y argument must be an odd integer.
func Jacobi(x *Int, y *Int) int
Lsh
method
#
Lsh sets z = x << n and returns z.
func (z *Int) Lsh(x *Int, n uint) *Int
MantExp
method
#
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 (x *Float) MantExp(mant *Float) (exp int)
MarshalJSON
method
#
MarshalJSON implements the [encoding/json.Marshaler] interface.
func (x *Int) MarshalJSON() ([]byte, error)
MarshalText
method
#
MarshalText implements the [encoding.TextMarshaler] interface.
func (x *Rat) MarshalText() (text []byte, err error)
MarshalText
method
#
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 (x *Float) MarshalText() (text []byte, err error)
MarshalText
method
#
MarshalText implements the [encoding.TextMarshaler] interface.
func (x *Int) MarshalText() (text []byte, err error)
MinPrec
method
#
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 (x *Float) MinPrec() uint
Mod
method
#
Mod sets z to the modulus x%y for y != 0 and returns z.
If y == 0, a division-by-zero run-time panic occurs.
Mod implements Euclidean modulus (unlike Go); see [Int.DivMod] for more details.
func (z *Int) Mod(x *Int, y *Int) *Int
ModInverse
method
#
ModInverse sets z to the multiplicative inverse of g in the ring ℤ/nℤ
and returns z. If g and n are not relatively prime, g has no multiplicative
inverse in the ring ℤ/nℤ. In this case, z is unchanged and the return value
is nil. If n == 0, a division-by-zero run-time panic occurs.
func (z *Int) ModInverse(g *Int, n *Int) *Int
ModSqrt
method
#
ModSqrt sets z to a square root of x mod p if such a square root exists, and
returns z. The modulus p must be an odd prime. If x is not a square mod p,
ModSqrt leaves z unchanged and returns nil. This function panics if p is
not an odd integer, its behavior is undefined if p is odd but not prime.
func (z *Int) ModSqrt(x *Int, p *Int) *Int
Mode
method
#
Mode returns the rounding mode of x.
func (x *Float) Mode() RoundingMode
Mul
method
#
Mul sets z to the rounded product x*y and returns z.
Precision, rounding, and accuracy reporting are as for [Float.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 (z *Float) Mul(x *Float, y *Float) *Float
Mul
method
#
Mul sets z to the product x*y and returns z.
func (z *Int) Mul(x *Int, y *Int) *Int
Mul
method
#
Mul sets z to the product x*y and returns z.
func (z *Rat) Mul(x *Rat, y *Rat) *Rat
MulRange
method
#
MulRange sets z to the product of all integers
in the range [a, b] inclusively and returns z.
If a > b (empty range), the result is 1.
func (z *Int) MulRange(a int64, b int64) *Int
Neg
method
#
Neg sets z to the (possibly rounded) value of x with its sign negated,
and returns z.
func (z *Float) Neg(x *Float) *Float
Neg
method
#
Neg sets z to -x and returns z.
func (z *Rat) Neg(x *Rat) *Rat
Neg
method
#
Neg sets z to -x and returns z.
func (z *Int) Neg(x *Int) *Int
NewFloat
function
#
NewFloat allocates and returns a new [Float] set to x,
with precision 53 and rounding mode [ToNearestEven].
NewFloat panics with [ErrNaN] if x is a NaN.
func NewFloat(x float64) *Float
NewInt
function
#
NewInt allocates and returns a new [Int] set to x.
func NewInt(x int64) *Int
NewRat
function
#
NewRat creates a new [Rat] with numerator a and denominator b.
func NewRat(a int64, b int64) *Rat
Not
method
#
Not sets z = ^x and returns z.
func (z *Int) Not(x *Int) *Int
Num
method
#
Num returns the numerator of x; it may be <= 0.
The result is a reference to x's numerator; it
may change if a new value is assigned to x, and vice versa.
The sign of the numerator corresponds to the sign of x.
func (x *Rat) Num() *Int
Or
method
#
Or sets z = x | y and returns z.
func (z *Int) Or(x *Int, y *Int) *Int
Parse
method
#
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.
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, or the returned
digit count. Incorrect placement of underscores is reported as an
error if there are no other errors. If base != 0, underscores are
not recognized and thus terminate scanning like any other character
that is not a valid radix point or digit.
It sets z to the (possibly rounded) value of the corresponding floating-
point value, and returns z, the actual base b, and an error err, if any.
The entire string (not just a prefix) must be consumed for success.
If z's precision is 0, it is changed to 64 before rounding takes effect.
The number must be of the form:
number = [ sign ] ( float | "inf" | "Inf" ) .
sign = "+" | "-" .
float = ( mantissa | prefix pmantissa ) [ exponent ] .
prefix = "0" [ "b" | "B" | "o" | "O" | "x" | "X" ] .
mantissa = digits "." [ digits ] | digits | "." digits .
pmantissa = [ "_" ] digits "." [ digits ] | [ "_" ] digits | "." digits .
exponent = ( "e" | "E" | "p" | "P" ) [ sign ] digits .
digits = digit { [ "_" ] digit } .
digit = "0" ... "9" | "a" ... "z" | "A" ... "Z" .
The base argument must be 0, 2, 8, 10, or 16. Providing an invalid base
argument will lead to a run-time panic.
For base 0, the number prefix determines the actual base: A prefix of
“0b” or “0B” selects base 2, “0o” or “0O” selects base 8, and
“0x” or “0X” selects base 16. Otherwise, the actual base is 10 and
no prefix is accepted. The octal prefix "0" is not supported (a leading
"0" is simply considered a "0").
A "p" or "P" exponent indicates a base 2 (rather than base 10) exponent;
for instance, "0x1.fffffffffffffp1023" (using base 0) represents the
maximum float64 value. For hexadecimal mantissae, the exponent character
must be one of 'p' or 'P', if present (an "e" or "E" exponent indicator
cannot be distinguished from a mantissa digit).
The returned *Float f is nil and the value of z is valid but not
defined if an error is reported.
func (z *Float) Parse(s string, base int) (f *Float, b int, err error)
ParseFloat
function
#
ParseFloat is like f.Parse(s, base) with f set to the given precision
and rounding mode.
func ParseFloat(s string, base int, prec uint, mode RoundingMode) (f *Float, b int, err error)
Prec
method
#
Prec returns the mantissa precision of x in bits.
The result may be 0 for |x| == 0 and |x| == Inf.
func (x *Float) Prec() uint
ProbablyPrime
method
#
ProbablyPrime reports whether x is probably prime,
applying the Miller-Rabin test with n pseudorandomly chosen bases
as well as a Baillie-PSW test.
If x is prime, ProbablyPrime returns true.
If x is chosen randomly and not prime, ProbablyPrime probably returns false.
The probability of returning true for a randomly chosen non-prime is at most ¼ⁿ.
ProbablyPrime is 100% accurate for inputs less than 2⁶⁴.
See Menezes et al., Handbook of Applied Cryptography, 1997, pp. 145-149,
and FIPS 186-4 Appendix F for further discussion of the error probabilities.
ProbablyPrime is not suitable for judging primes that an adversary may
have crafted to fool the test.
As of Go 1.8, ProbablyPrime(0) is allowed and applies only a Baillie-PSW test.
Before Go 1.8, ProbablyPrime applied only the Miller-Rabin tests, and ProbablyPrime(0) panicked.
func (x *Int) ProbablyPrime(n int) bool
Quo
method
#
Quo sets z to the quotient x/y for y != 0 and returns z.
If y == 0, a division-by-zero run-time panic occurs.
Quo implements truncated division (like Go); see [Int.QuoRem] for more details.
func (z *Int) Quo(x *Int, y *Int) *Int
Quo
method
#
Quo sets z to the rounded quotient x/y and returns z.
Precision, rounding, and accuracy reporting are as for [Float.Add].
Quo panics with [ErrNaN] if both operands are zero or infinities.
The value of z is undefined in that case.
func (z *Float) Quo(x *Float, y *Float) *Float
Quo
method
#
Quo sets z to the quotient x/y and returns z.
If y == 0, Quo panics.
func (z *Rat) Quo(x *Rat, y *Rat) *Rat
QuoRem
method
#
QuoRem sets z to the quotient x/y and r to the remainder x%y
and returns the pair (z, r) for y != 0.
If y == 0, a division-by-zero run-time panic occurs.
QuoRem implements T-division and modulus (like Go):
q = x/y with the result truncated to zero
r = x - y*q
(See Daan Leijen, “Division and Modulus for Computer Scientists”.)
See [Int.DivMod] for Euclidean division and modulus (unlike Go).
func (z *Int) QuoRem(x *Int, y *Int, r *Int) (*Int, *Int)
Rand
method
#
Rand sets z to a pseudo-random number in [0, n) and returns z.
As this uses the [math/rand] package, it must not be used for
security-sensitive work. Use [crypto/rand.Int] instead.
func (z *Int) Rand(rnd *rand.Rand, n *Int) *Int
Rat
method
#
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 (x *Float) Rat(z *Rat) (*Rat, Accuracy)
RatString
method
#
RatString returns a string representation of x in the form "a/b" if b != 1,
and in the form "a" if b == 1.
func (x *Rat) RatString() string
ReadByte
method
#
func (r byteReader) ReadByte() (byte, error)
Rem
method
#
Rem sets z to the remainder x%y for y != 0 and returns z.
If y == 0, a division-by-zero run-time panic occurs.
Rem implements truncated modulus (like Go); see [Int.QuoRem] for more details.
func (z *Int) Rem(x *Int, y *Int) *Int
Rsh
method
#
Rsh sets z = x >> n and returns z.
func (z *Int) Rsh(x *Int, n uint) *Int
Scan
method
#
Scan is a support routine for [fmt.Scanner]; it sets z to the value of
the scanned number. It accepts formats whose verbs are supported by
[fmt.Scan] for floating point values, which are:
'b' (binary), 'e', 'E', 'f', 'F', 'g' and 'G'.
Scan doesn't handle ±Inf.
func (z *Float) Scan(s fmt.ScanState, ch rune) error
Scan
method
#
Scan is a support routine for fmt.Scanner. It accepts the formats
'e', 'E', 'f', 'F', 'g', 'G', and 'v'. All formats are equivalent.
func (z *Rat) Scan(s fmt.ScanState, ch rune) error
Scan
method
#
Scan is a support routine for [fmt.Scanner]; it sets z to the value of
the scanned number. It accepts the formats 'b' (binary), 'o' (octal),
'd' (decimal), 'x' (lowercase hexadecimal), and 'X' (uppercase hexadecimal).
func (z *Int) Scan(s fmt.ScanState, ch rune) error
Set
method
#
Set sets z to x and returns z.
func (z *Int) Set(x *Int) *Int
Set
method
#
Set sets z to x (by making a copy of x) and returns z.
func (z *Rat) Set(x *Rat) *Rat
Set
method
#
Set sets z to the (possibly rounded) value of x and returns z.
If z's precision is 0, it is changed to the precision of x
before setting z (and rounding will have no effect).
Rounding is performed according to z's precision and rounding
mode; and z's accuracy reports the result error relative to the
exact (not rounded) result.
func (z *Float) Set(x *Float) *Float
SetBit
method
#
SetBit sets z to x, with x's i'th bit set to b (0 or 1).
That is,
- if b is 1, SetBit sets z = x | (1 << i);
- if b is 0, SetBit sets z = x &^ (1 << i);
- if b is not 0 or 1, SetBit will panic.
func (z *Int) SetBit(x *Int, i int, b uint) *Int
SetBits
method
#
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 (z *Int) SetBits(abs []Word) *Int
SetBytes
method
#
SetBytes interprets buf as the bytes of a big-endian unsigned
integer, sets z to that value, and returns z.
func (z *Int) SetBytes(buf []byte) *Int
SetFloat64
method
#
SetFloat64 sets z to exactly f and returns z.
If f is not finite, SetFloat returns nil.
func (z *Rat) SetFloat64(f float64) *Rat
SetFloat64
method
#
SetFloat64 sets z to the (possibly rounded) value of x and returns z.
If z'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 (z *Float) SetFloat64(x float64) *Float
SetFrac
method
#
SetFrac sets z to a/b and returns z.
If b == 0, SetFrac panics.
func (z *Rat) SetFrac(a *Int, b *Int) *Rat
SetFrac64
method
#
SetFrac64 sets z to a/b and returns z.
If b == 0, SetFrac64 panics.
func (z *Rat) SetFrac64(a int64, b int64) *Rat
SetInf
method
#
SetInf sets z to the infinite Float -Inf if signbit is
set, or +Inf if signbit is not set, and returns z. The
precision of z is unchanged and the result is always
[Exact].
func (z *Float) SetInf(signbit bool) *Float
SetInt
method
#
SetInt sets z to x (by making a copy of x) and returns z.
func (z *Rat) SetInt(x *Int) *Rat
SetInt
method
#
SetInt sets z to the (possibly rounded) value of x and returns z.
If z's precision is 0, it is changed to the larger of x.BitLen()
or 64 (and rounding will have no effect).
func (z *Float) SetInt(x *Int) *Float
SetInt64
method
#
SetInt64 sets z to the (possibly rounded) value of x and returns z.
If z's precision is 0, it is changed to 64 (and rounding will have
no effect).
func (z *Float) SetInt64(x int64) *Float
SetInt64
method
#
SetInt64 sets z to x and returns z.
func (z *Int) SetInt64(x int64) *Int
SetInt64
method
#
SetInt64 sets z to x and returns z.
func (z *Rat) SetInt64(x int64) *Rat
SetMantExp
method
#
SetMantExp sets z to mant × 2**exp and returns z.
The result z has the same precision and rounding mode
as mant. SetMantExp is an inverse of [Float.MantExp] but does
not require 0.5 <= |mant| < 1.0. Specifically, for a
given x of type *[Float], SetMantExp relates to [Float.MantExp]
as follows:
mant := new(Float)
new(Float).SetMantExp(mant, x.MantExp(mant)).Cmp(x) == 0
Special cases are:
z.SetMantExp( ±0, exp) = ±0
z.SetMantExp(±Inf, exp) = ±Inf
z and mant may be the same in which case z's exponent
is set to exp.
func (z *Float) SetMantExp(mant *Float, exp int) *Float
SetMode
method
#
SetMode sets z's rounding mode to mode and returns an exact z.
z remains unchanged otherwise.
z.SetMode(z.Mode()) is a cheap way to set z's accuracy to [Exact].
func (z *Float) SetMode(mode RoundingMode) *Float
SetPrec
method
#
SetPrec sets z's precision to prec and returns the (possibly) rounded
value of z. Rounding occurs according to z's rounding mode if the mantissa
cannot be represented in prec bits without loss of precision.
SetPrec(0) maps all finite values to ±0; infinite values remain unchanged.
If prec > [MaxPrec], it is set to [MaxPrec].
func (z *Float) SetPrec(prec uint) *Float
SetRat
method
#
SetRat sets z to the (possibly rounded) value of x and returns z.
If z's precision is 0, it is changed to the largest of a.BitLen(),
b.BitLen(), or 64; with x = a/b.
func (z *Float) SetRat(x *Rat) *Float
SetString
method
#
SetString sets z to the value of s and returns z and a boolean indicating
success. s can be given as a (possibly signed) fraction "a/b", or as a
floating-point number optionally followed by an exponent.
If a fraction is provided, both the dividend and the divisor may be a
decimal integer or independently use a prefix of “0b”, “0” or “0o”,
or “0x” (or their upper-case variants) to denote a binary, octal, or
hexadecimal integer, respectively. The divisor may not be signed.
If a floating-point number is provided, it may be in decimal form or
use any of the same prefixes as above but for “0” to denote a non-decimal
mantissa. A leading “0” is considered a decimal leading 0; it does not
indicate octal representation in this case.
An optional base-10 “e” or base-2 “p” (or their upper-case variants)
exponent may be provided as well, except for hexadecimal floats which
only accept an (optional) “p” exponent (because an “e” or “E” cannot
be distinguished from a mantissa digit). If the exponent's absolute value
is too large, the operation may fail.
The entire string, not just a prefix, must be valid for success. If the
operation failed, the value of z is undefined but the returned value is nil.
func (z *Rat) SetString(s string) (*Rat, bool)
SetString
method
#
SetString sets z to the value of s, interpreted in the given base,
and returns z and a boolean indicating success. The entire string
(not just a prefix) must be valid for success. If SetString fails,
the value of z is undefined but the returned value is nil.
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 (z *Int) SetString(s string, base int) (*Int, bool)
SetString
method
#
SetString sets z to the value of s and returns z and a boolean indicating
success. s must be a floating-point number of the same format as accepted
by [Float.Parse], with base argument 0. The entire string (not just a prefix) must
be valid for success. If the operation failed, the value of z is undefined
but the returned value is nil.
func (z *Float) SetString(s string) (*Float, bool)
SetUint64
method
#
SetUint64 sets z to the (possibly rounded) value of x and returns z.
If z's precision is 0, it is changed to 64 (and rounding will have
no effect).
func (z *Float) SetUint64(x uint64) *Float
SetUint64
method
#
SetUint64 sets z to x and returns z.
func (z *Rat) SetUint64(x uint64) *Rat
SetUint64
method
#
SetUint64 sets z to x and returns z.
func (z *Int) SetUint64(x uint64) *Int
Sign
method
#
Sign returns:
- -1 if x < 0;
- 0 if x == 0;
- +1 if x > 0.
func (x *Int) Sign() int
Sign
method
#
Sign returns:
- -1 if x < 0;
- 0 if x == 0;
- +1 if x > 0.
func (x *Rat) Sign() int
Sign
method
#
Sign returns:
- -1 if x < 0;
- 0 if x is ±0;
- +1 if x > 0.
func (x *Float) Sign() int
Signbit
method
#
Signbit reports whether x is negative or negative zero.
func (x *Float) Signbit() bool
Sqrt
method
#
Sqrt sets z to ⌊√x⌋, the largest integer such that z² ≤ x, and returns z.
It panics if x is negative.
func (z *Int) Sqrt(x *Int) *Int
Sqrt
method
#
Sqrt sets z to the rounded square root of x, and returns it.
If z's precision is 0, it is changed to x's precision before the
operation. Rounding is performed according to z's precision and
rounding mode, but z's accuracy is not computed. Specifically, the
result of z.Acc() is undefined.
The function panics if z < 0. The value of z is undefined in that
case.
func (z *Float) Sqrt(x *Float) *Float
String
method
#
func (x *decimal) String() string
String
method
#
func (z nat) String() string
String
method
#
String formats x like x.Text('g', 10).
(String must be called explicitly, [Float.Format] does not support %s verb.)
func (x *Float) String() string
String
method
#
func (i RoundingMode) String() string
String
method
#
func (i Accuracy) String() string
String
method
#
String returns the decimal representation of x as generated by
x.Text(10).
func (x *Int) String() string
String
method
#
String returns a string representation of x in the form "a/b" (even if b == 1).
func (x *Rat) String() string
Sub
method
#
Sub sets z to the difference x-y and returns z.
func (z *Rat) Sub(x *Rat, y *Rat) *Rat
Sub
method
#
Sub sets z to the rounded difference x-y and returns z.
Precision, rounding, and accuracy reporting are as for [Float.Add].
Sub panics with [ErrNaN] if x and y are infinities with equal
signs. The value of z is undefined in that case.
func (z *Float) Sub(x *Float, y *Float) *Float
Sub
method
#
Sub sets z to the difference x-y and returns z.
func (z *Int) Sub(x *Int, y *Int) *Int
Text
method
#
Text converts the floating-point number x to a string according
to the given format and precision prec. The format is one of:
'e' -d.dddde±dd, decimal exponent, at least two (possibly 0) exponent digits
'E' -d.ddddE±dd, decimal exponent, at least two (possibly 0) exponent digits
'f' -ddddd.dddd, no exponent
'g' like 'e' for large exponents, like 'f' otherwise
'G' like 'E' for large exponents, like 'f' otherwise
'x' -0xd.dddddp±dd, hexadecimal mantissa, decimal power of two exponent
'p' -0x.dddp±dd, hexadecimal mantissa, decimal power of two exponent (non-standard)
'b' -ddddddp±dd, decimal mantissa, decimal power of two exponent (non-standard)
For the power-of-two exponent formats, the mantissa is printed in normalized form:
'x' hexadecimal mantissa in [1, 2), or 0
'p' hexadecimal mantissa in [½, 1), or 0
'b' decimal integer mantissa using x.Prec() bits, or 0
Note that the 'x' form is the one used by most other languages and libraries.
If format is a different character, Text returns a "%" followed by the
unrecognized format character.
The precision prec controls the number of digits (excluding the exponent)
printed by the 'e', 'E', 'f', 'g', 'G', and 'x' formats.
For 'e', 'E', 'f', and 'x', it is the number of digits after the decimal point.
For 'g' and 'G' it is the total number of digits. A negative precision selects
the smallest number of decimal digits necessary to identify the value x uniquely
using x.Prec() mantissa bits.
The prec value is ignored for the 'b' and 'p' formats.
func (x *Float) Text(format byte, prec int) string
Text
method
#
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 "".
func (x *Int) Text(base int) string
TrailingZeroBits
method
#
TrailingZeroBits returns the number of consecutive least significant zero
bits of |x|.
func (x *Int) TrailingZeroBits() uint
Uint64
method
#
Uint64 returns the uint64 representation of x.
If x cannot be represented in a uint64, the result is undefined.
func (x *Int) Uint64() uint64
Uint64
method
#
Uint64 returns the unsigned integer resulting from truncating x
towards zero. If 0 <= x <= [math.MaxUint64], the result is [Exact]
if x is an integer and [Below] otherwise.
The result is (0, [Above]) for x < 0, and ([math.MaxUint64], [Below])
for x > [math.MaxUint64].
func (x *Float) Uint64() (uint64, Accuracy)
UnmarshalJSON
method
#
UnmarshalJSON implements the [encoding/json.Unmarshaler] interface.
func (z *Int) UnmarshalJSON(text []byte) error
UnmarshalText
method
#
UnmarshalText implements the [encoding.TextUnmarshaler] interface.
The result is rounded per the precision and rounding mode of z.
If z's precision is 0, it is changed to 64 before rounding takes
effect.
func (z *Float) UnmarshalText(text []byte) error
UnmarshalText
method
#
UnmarshalText implements the [encoding.TextUnmarshaler] interface.
func (z *Int) UnmarshalText(text []byte) error
UnmarshalText
method
#
UnmarshalText implements the [encoding.TextUnmarshaler] interface.
func (z *Rat) UnmarshalText(text []byte) error
UnreadByte
method
#
func (r byteReader) UnreadByte() error
Xor
method
#
Xor sets z = x ^ y and returns z.
func (z *Int) Xor(x *Int, y *Int) *Int
_
function
#
func _()
_
function
#
func _()
add
method
#
func (z nat) add(x nat, y nat) nat
addAt
function
#
addAt implements z += x<<(_W*i); z must be long enough.
(we don't use nat.add because we need z to stay the same
slice, and we don't need to normalize z after each addition)
func addAt(z nat, x nat, i int)
addMulVVW
function
#
func addMulVVW(z []Word, x []Word, y Word) (c Word)
addMulVVW
function
#
addMulVVW should be an internal detail,
but widely used packages access it using linkname.
Notable members of the hall of shame include:
- github.com/remyoudompheng/bigfft
Do not remove or change the type signature.
See go.dev/issue/67401.
go:linkname addMulVVW
go:noescape
func addMulVVW(z []Word, x []Word, y Word) (c Word)
addMulVVW_g
function
#
func addMulVVW_g(z []Word, x []Word, y Word) (c Word)
addVV
function
#
func addVV(z []Word, x []Word, y []Word) (c Word)
addVV
function
#
addVV should be an internal detail,
but widely used packages access it using linkname.
Notable members of the hall of shame include:
- github.com/remyoudompheng/bigfft
Do not remove or change the type signature.
See go.dev/issue/67401.
go:linkname addVV
go:noescape
func addVV(z []Word, x []Word, y []Word) (c Word)
addVV_check
function
#
func addVV_check(z []Word, x []Word, y []Word) (c Word)
addVV_g
function
#
The resulting carry c is either 0 or 1.
func addVV_g(z []Word, x []Word, y []Word) (c Word)
addVV_novec
function
#
func addVV_novec(z []Word, x []Word, y []Word) (c Word)
addVV_vec
function
#
func addVV_vec(z []Word, x []Word, y []Word) (c Word)
addVW
function
#
addVW should be an internal detail,
but widely used packages access it using linkname.
Notable members of the hall of shame include:
- github.com/remyoudompheng/bigfft
Do not remove or change the type signature.
See go.dev/issue/67401.
go:linkname addVW
go:noescape
func addVW(z []Word, x []Word, y Word) (c Word)
addVW
function
#
func addVW(z []Word, x []Word, y Word) (c Word)
addVW_g
function
#
The resulting carry c is either 0 or 1.
func addVW_g(z []Word, x []Word, y Word) (c Word)
addVWlarge
function
#
addVWlarge is addVW, but intended for large z.
The only difference is that we check on every iteration
whether we are done with carries,
and if so, switch to a much faster copy instead.
This is only a good idea for large z,
because the overhead of the check and the function call
outweigh the benefits when z is small.
func addVWlarge(z []Word, x []Word, y Word) (c Word)
alias
function
#
alias reports whether x and y share the same base array.
Note: alias assumes that the capacity of underlying arrays
is never changed for nat values; i.e. that there are
no 3-operand slice expressions in this code (or worse,
reflect-based operations to the same effect).
func alias(x nat, y nat) bool
and
method
#
func (z nat) and(x nat, y nat) nat
andNot
method
#
func (z nat) andNot(x nat, y nat) nat
appendZeros
function
#
appendZeros appends n 0 digits to buf and returns buf.
func appendZeros(buf []byte, n int) []byte
at
method
#
at returns the i'th mantissa digit, starting with the most significant digit at 0.
func (d *decimal) at(i int) byte
basicMul
function
#
basicMul multiplies x and y and leaves the result in z.
The (non-normalized) result is placed in z[0 : len(x) + len(y)].
func basicMul(z nat, x nat, y nat)
basicSqr
function
#
basicSqr sets z = x*x and is asymptotically faster than basicMul
by about a factor of 2, but slower for small arguments due to overhead.
Requirements: len(x) > 0, len(z) == 2*len(x)
The (non-normalized) result is placed in z.
func basicSqr(z nat, x nat)
bigEndianWord
function
#
bigEndianWord returns the contents of buf interpreted as a big-endian encoded Word value.
func bigEndianWord(buf []byte) Word
bit
method
#
bit returns the value of the i'th bit, with lsb == bit 0.
func (x nat) bit(i uint) uint
bitLen
method
#
bitLen returns the length of x in bits.
Unlike most methods, it works even if x is not normalized.
func (x nat) bitLen() int
bytes
method
#
bytes writes the value of z into buf using big-endian encoding.
The value of z is encoded in the slice buf[i:]. If the value of z
cannot be represented in buf, bytes panics. The number i of unused
bytes at the beginning of buf is returned as result.
func (z nat) bytes(buf []byte) (i int)
cmp
method
#
func (x nat) cmp(y nat) (r int)
convertWords
method
#
Convert words of q to base b digits in s. If q is large, it is recursively "split in half"
by nat/nat division using tabulated divisors. Otherwise, it is converted iteratively using
repeated nat/Word division.
The iterative method processes n Words by n divW() calls, each of which visits every Word in the
incrementally shortened q for a total of n + (n-1) + (n-2) ... + 2 + 1, or n(n+1)/2 divW()'s.
Recursive conversion divides q by its approximate square root, yielding two parts, each half
the size of q. Using the iterative method on both halves means 2 * (n/2)(n/2 + 1)/2 divW()'s
plus the expensive long div(). Asymptotically, the ratio is favorable at 1/2 the divW()'s, and
is made better by splitting the subblocks recursively. Best is to split blocks until one more
split would take longer (because of the nat/nat div()) than the twice as many divW()'s of the
iterative approach. This threshold is represented by leafSize. Benchmarking of leafSize in the
range 2..64 shows that values of 8 and 16 work well, with a 4x speedup at medium lengths and
~30x for 20000 digits. Use nat_test.go's BenchmarkLeafSize tests to optimize leafSize for
specific hardware.
func (q nat) convertWords(s []byte, b Word, ndigits int, bb Word, table []divisor)
div
method
#
div returns q, r such that q = ⌊u/v⌋ and r = u%v = u - q·v.
It uses z and z2 as the storage for q and r.
func (z nat) div(z2 nat, u nat, v nat) (q nat, r nat)
divBasic
method
#
divBasic implements long division as described above.
It overwrites q with ⌊u/v⌋ and overwrites u with the remainder r.
q must be large enough to hold ⌊u/v⌋.
func (q nat) divBasic(u nat, v nat)
divLarge
method
#
div returns q, r such that q = ⌊uIn/vIn⌋ and r = uIn%vIn = uIn - q·vIn.
It uses z and u as the storage for q and r.
The caller must ensure that len(vIn) ≥ 2 (use divW otherwise)
and that len(uIn) ≥ len(vIn) (the answer is 0, uIn otherwise).
func (z nat) divLarge(u nat, uIn nat, vIn nat) (q nat, r nat)
divRecursive
method
#
divRecursive implements recursive division as described above.
It overwrites z with ⌊u/v⌋ and overwrites u with the remainder r.
z must be large enough to hold ⌊u/v⌋.
This function is just for allocating and freeing temporaries
around divRecursiveStep, the real implementation.
func (z nat) divRecursive(u nat, v nat)
divRecursiveStep
method
#
divRecursiveStep is the actual implementation of recursive division.
It adds ⌊u/v⌋ to z and overwrites u with the remainder r.
z must be large enough to hold ⌊u/v⌋.
It uses temps[depth] (allocating if needed) as a temporary live across
the recursive call. It also uses tmp, but not live across the recursion.
func (z nat) divRecursiveStep(u nat, v nat, depth int, tmp *nat, temps []*nat)
divW
method
#
divW returns q, r such that q = ⌊x/y⌋ and r = x%y = x - q·y.
It uses z as the storage for q.
Note that y is a single digit (Word), not a big number.
func (z nat) divW(x nat, y Word) (q nat, r Word)
divWVW
function
#
divWVW overwrites z with ⌊x/y⌋, returning the remainder r.
The caller must ensure that len(z) = len(x).
func divWVW(z []Word, xn Word, x []Word, y Word) (r Word)
divWW
function
#
q = ( x1 << _W + x0 - r)/y. m = floor(( _B^2 - 1 ) / d - _B). Requiring x1
func divWW(x1 Word, x0 Word, y Word, m Word) (q Word, r Word)
divisors
function
#
construct table of powers of bb*leafSize to use in subdivisions.
func divisors(m int, b Word, ndigits int, bb Word) []divisor
euclidUpdate
function
#
euclidUpdate performs a single step of the Euclidean GCD algorithm
if extended is true, it also updates the cosequence Ua, Ub.
func euclidUpdate(A *Int, B *Int, Ua *Int, Ub *Int, q *Int, r *Int, s *Int, t *Int, extended bool)
exp
method
#
func (z *Int) exp(x *Int, y *Int, m *Int, slow bool) *Int
expNN
method
#
If m != 0 (i.e., len(m) != 0), expNN sets z to x**y mod m;
otherwise it sets z to x**y. The result is the value of z.
func (z nat) expNN(x nat, y nat, m nat, slow bool) nat
expNNMontgomery
method
#
expNNMontgomery calculates x**y mod m using a fixed, 4-bit window.
Uses Montgomery representation.
func (z nat) expNNMontgomery(x nat, y nat, m nat) nat
expNNMontgomeryEven
method
#
expNNMontgomeryEven calculates x**y mod m where m = m1 × m2 for m1 = 2ⁿ and m2 odd.
It uses two recursive calls to expNN for x**y mod m1 and x**y mod m2
and then uses the Chinese Remainder Theorem to combine the results.
The recursive call using m1 will use expNNWindowed,
while the recursive call using m2 will use expNNMontgomery.
For more details, see Ç. K. Koç, “Montgomery Reduction with Even Modulus”,
IEE Proceedings: Computers and Digital Techniques, 141(5) 314-316, September 1994.
http://www.people.vcu.edu/~jwang3/CMSC691/j34monex.pdf
func (z nat) expNNMontgomeryEven(x nat, y nat, m nat) nat
expNNWindowed
method
#
expNNWindowed calculates x**y mod m using a fixed, 4-bit window,
where m = 2**logM.
func (z nat) expNNWindowed(x nat, y nat, logM uint) nat
expSlow
method
#
func (z *Int) expSlow(x *Int, y *Int, m *Int) *Int
expWW
method
#
expWW computes x**y
func (z nat) expWW(x Word, y Word) nat
fmtB
method
#
fmtB appends the string of x in the format mantissa "p" exponent
with a decimal mantissa and a binary exponent, or "0" if x is zero,
and returns the extended buffer.
The mantissa is normalized such that is uses x.Prec() bits in binary
representation.
The sign of x is ignored, and x must not be an Inf.
(The caller handles Inf before invoking fmtB.)
func (x *Float) fmtB(buf []byte) []byte
fmtE
function
#
%e: d.ddddde±dd
func fmtE(buf []byte, fmt byte, prec int, d decimal) []byte
fmtF
function
#
%f: ddddddd.ddddd
func fmtF(buf []byte, prec int, d decimal) []byte
fmtP
method
#
fmtP appends the string of x in the format "0x." mantissa "p" exponent
with a hexadecimal mantissa and a binary exponent, or "0" if x is zero,
and returns the extended buffer.
The mantissa is normalized such that 0.5 <= 0.mantissa < 1.0.
The sign of x is ignored, and x must not be an Inf.
(The caller handles Inf before invoking fmtP.)
func (x *Float) fmtP(buf []byte) []byte
fmtX
method
#
fmtX appends the string of x in the format "0x1." mantissa "p" exponent
with a hexadecimal mantissa and a binary exponent, or "0x0p0" if x is zero,
and returns the extended buffer.
A non-zero mantissa is normalized such that 1.0 <= mantissa < 2.0.
The sign of x is ignored, and x must not be an Inf.
(The caller handles Inf before invoking fmtX.)
func (x *Float) fmtX(buf []byte, prec int) []byte
fnorm
function
#
fnorm normalizes mantissa m by shifting it to the left
such that the msb of the most-significant word (msw) is 1.
It returns the shift amount. It assumes that len(m) != 0.
func fnorm(m nat) int64
getNat
function
#
getNat returns a *nat of len n. The contents may not be zero.
The pool holds *nat to avoid allocation when converting to interface{}.
func getNat(n int) *nat
greaterThan
function
#
greaterThan reports whether the two digit numbers x1 x2 > y1 y2.
TODO(rsc): In contradiction to most of this file, x1 is the high
digit and x2 is the low digit. This should be fixed.
func greaterThan(x1 Word, x2 Word, y1 Word, y2 Word) bool
init
method
#
Init initializes x to the decimal representation of m << shift (for
shift >= 0), or m >> -shift (for shift < 0).
func (x *decimal) init(m nat, shift int)
isPow2
method
#
isPow2 returns i, true when x == 2**i and 0, false otherwise.
func (x nat) isPow2() (uint, bool)
itoa
method
#
itoa is like utoa but it prepends a '-' if neg && x != 0.
func (x nat) itoa(neg bool, base int) []byte
karatsuba
function
#
karatsuba multiplies x and y and leaves the result in z.
Both x and y must have the same length n and n must be a
power of 2. The result vector z must have len(z) >= 6*n.
The (non-normalized) result is placed in z[0 : 2*n].
func karatsuba(z nat, x nat, y nat)
karatsubaAdd
function
#
Fast version of z[0:n+n>>1].add(z[0:n+n>>1], x[0:n]) w/o bounds checks.
Factored out for readability - do not use outside karatsuba.
func karatsubaAdd(z nat, x nat, n int)
karatsubaLen
function
#
karatsubaLen computes an approximation to the maximum k <= n such that
k = p<= 0. Thus, the
result is the largest number that can be divided repeatedly by 2 before
becoming about the value of threshold.
func karatsubaLen(n int, threshold int) int
karatsubaSqr
function
#
karatsubaSqr squares x and leaves the result in z.
len(x) must be a power of 2 and len(z) >= 6*len(x).
The (non-normalized) result is placed in z[0 : 2*len(x)].
The algorithm and the layout of z are the same as for karatsuba.
func karatsubaSqr(z nat, x nat)
karatsubaSub
function
#
Like karatsubaAdd, but does subtract.
func karatsubaSub(z nat, x nat, n int)
lehmerGCD
method
#
lehmerGCD sets z to the greatest common divisor of a and b,
which both must be != 0, and returns z.
If x or y are not nil, their values are set such that z = a*x + b*y.
See Knuth, The Art of Computer Programming, Vol. 2, Section 4.5.2, Algorithm L.
This implementation uses the improved condition by Collins requiring only one
quotient and avoiding the possibility of single Word overflow.
See Jebelean, "Improving the multiprecision Euclidean algorithm",
Design and Implementation of Symbolic Computation Systems, pp 45-58.
The cosequences are updated according to Algorithm 10.45 from
Cohen et al. "Handbook of Elliptic and Hyperelliptic Curve Cryptography" pp 192.
func (z *Int) lehmerGCD(x *Int, y *Int, a *Int, b *Int) *Int
lehmerSimulate
function
#
lehmerSimulate attempts to simulate several Euclidean update steps
using the leading digits of A and B. It returns u0, u1, v0, v1
such that A and B can be updated as:
A = u0*A + v0*B
B = u1*A + v1*B
Requirements: A >= B and len(B.abs) >= 2
Since we are calculating with full words to avoid overflow,
we use 'even' to track the sign of the cosequences.
For even iterations: u0, v1 >= 0 && u1, v0 <= 0
For odd iterations: u0, v1 <= 0 && u1, v0 >= 0
func lehmerSimulate(A *Int, B *Int) (u0 Word, u1 Word, v0 Word, v1 Word, even bool)
lehmerUpdate
function
#
lehmerUpdate updates the inputs A and B such that:
A = u0*A + v0*B
B = u1*A + v1*B
where the signs of u0, u1, v0, v1 are given by even
For even == true: u0, v1 >= 0 && u1, v0 <= 0
For even == false: u0, v1 <= 0 && u1, v0 >= 0
q, r, s, t are temporary variables to avoid allocations in the multiplication.
func lehmerUpdate(A *Int, B *Int, q *Int, r *Int, s *Int, t *Int, u0 Word, u1 Word, v0 Word, v1 Word, even bool)
low32
function
#
low32 returns the least significant 32 bits of x.
func low32(x nat) uint32
low64
function
#
low64 returns the least significant 64 bits of x.
func low64(x nat) uint64
make
method
#
func (z nat) make(n int) nat
makeAcc
function
#
func makeAcc(above bool) Accuracy
marshal
method
#
marshal implements [Rat.String] returning a slice of bytes.
It appends the string representation of x in the form "a/b" (even if b == 1) to buf,
and returns the extended buffer.
func (x *Rat) marshal(buf []byte) []byte
maxPow
function
#
maxPow returns (b**n, n) such that b**n is the largest power b**n <= _M.
For instance maxPow(10) == (1e19, 19) for 19 decimal digits in a 64bit Word.
In other words, at most n digits in base b fit into a Word.
TODO(gri) replace this with a table, generated at build time.
func maxPow(b Word) (p Word, n int)
modInverse
method
#
func (z nat) modInverse(g nat, n nat) nat
modSqrt3Mod4Prime
method
#
modSqrt3Mod4 uses the identity
(a^((p+1)/4))^2 mod p
== u^(p+1) mod p
== u^2 mod p
to calculate the square root of any quadratic residue mod p quickly for 3
mod 4 primes.
func (z *Int) modSqrt3Mod4Prime(x *Int, p *Int) *Int
modSqrt5Mod8Prime
method
#
modSqrt5Mod8Prime uses Atkin's observation that 2 is not a square mod p
alpha == (2*a)^((p-5)/8) mod p
beta == 2*a*alpha^2 mod p is a square root of -1
b == a*alpha*(beta-1) mod p is a square root of a
to calculate the square root of any quadratic residue mod p quickly for 5
mod 8 primes.
func (z *Int) modSqrt5Mod8Prime(x *Int, p *Int) *Int
modSqrtTonelliShanks
method
#
modSqrtTonelliShanks uses the Tonelli-Shanks algorithm to find the square
root of a quadratic residue modulo any prime.
func (z *Int) modSqrtTonelliShanks(x *Int, p *Int) *Int
modW
method
#
modW returns x % d.
func (x nat) modW(d Word) (r Word)
montgomery
method
#
montgomery computes z mod m = x*y*2**(-n*_W) mod m,
assuming k = -1/m mod 2**_W.
z is used for storing the result which is returned;
z must not alias x, y or m.
See Gueron, "Efficient Software Implementations of Modular Exponentiation".
https://eprint.iacr.org/2011/239.pdf
In the terminology of that paper, this is an "Almost Montgomery Multiplication":
x and y are required to satisfy 0 <= z < 2**(n*_W) and then the result
z is guaranteed to satisfy 0 <= z < 2**(n*_W), but it may not be < m.
func (z nat) montgomery(x nat, y nat, m nat, k Word, n int) nat
msb32
function
#
msb32 returns the 32 most significant bits of x.
func msb32(x nat) uint32
msb64
function
#
msb64 returns the 64 most significant bits of x.
func msb64(x nat) uint64
mul
method
#
func (z nat) mul(x nat, y nat) nat
mulAddVWW
function
#
mulAddVWW should be an internal detail,
but widely used packages access it using linkname.
Notable members of the hall of shame include:
- github.com/remyoudompheng/bigfft
Do not remove or change the type signature.
See go.dev/issue/67401.
go:linkname mulAddVWW
go:noescape
func mulAddVWW(z []Word, x []Word, y Word, r Word) (c Word)
mulAddVWW
function
#
func mulAddVWW(z []Word, x []Word, y Word, r Word) (c Word)
mulAddVWW_g
function
#
func mulAddVWW_g(z []Word, x []Word, y Word, r Word) (c Word)
mulAddWW
method
#
func (z nat) mulAddWW(x nat, y Word, r Word) nat
mulAddWWW_g
function
#
z1<<_W + z0 = x*y + c
func mulAddWWW_g(x Word, y Word, c Word) (z1 Word, z0 Word)
mulDenom
function
#
mulDenom sets z to the denominator product x*y (by taking into
account that 0 values for x or y must be interpreted as 1) and
returns z.
func mulDenom(z nat, x nat, y nat) nat
mulRange
method
#
mulRange computes the product of all the unsigned integers in the
range [a, b] inclusively. If a > b (empty range), the result is 1.
func (z nat) mulRange(a uint64, b uint64) nat
mulWW
function
#
z1<<_W + z0 = x*y
func mulWW(x Word, y Word) (z1 Word, z0 Word)
newFloat
function
#
newFloat returns a new *Float with space for twice the given
precision.
func newFloat(prec2 uint32) *Float
nlz
function
#
nlz returns the number of leading zeros in x.
Wraps bits.LeadingZeros call for convenience.
func nlz(x Word) uint
norm
method
#
func (z nat) norm() nat
norm
method
#
func (z *Rat) norm() *Rat
or
method
#
func (z nat) or(x nat, y nat) nat
ord
method
#
ord classifies x and returns:
-2 if -Inf == x
-1 if -Inf < x < 0
0 if x == 0 (signed or unsigned)
+1 if 0 < x < +Inf
+2 if x == +Inf
func (x *Float) ord() int
pow
function
#
pow returns x**n for n > 0, and 1 otherwise.
func pow(x Word, n int) (p Word)
pow5
method
#
pow5 sets z to 5**n and returns z.
n must not be negative.
func (z *Float) pow5(n uint64) *Float
probablyPrimeLucas
method
#
probablyPrimeLucas reports whether n passes the "almost extra strong" Lucas probable prime test,
using Baillie-OEIS parameter selection. This corresponds to "AESLPSP" on Jacobsen's tables (link below).
The combination of this test and a Miller-Rabin/Fermat test with base 2 gives a Baillie-PSW test.
References:
Baillie and Wagstaff, "Lucas Pseudoprimes", Mathematics of Computation 35(152),
October 1980, pp. 1391-1417, especially page 1401.
https://www.ams.org/journals/mcom/1980-35-152/S0025-5718-1980-0583518-6/S0025-5718-1980-0583518-6.pdf
Grantham, "Frobenius Pseudoprimes", Mathematics of Computation 70(234),
March 2000, pp. 873-891.
https://www.ams.org/journals/mcom/2001-70-234/S0025-5718-00-01197-2/S0025-5718-00-01197-2.pdf
Baillie, "Extra strong Lucas pseudoprimes", OEIS A217719, https://oeis.org/A217719.
Jacobsen, "Pseudoprime Statistics, Tables, and Data", http://ntheory.org/pseudoprimes.html.
Nicely, "The Baillie-PSW Primality Test", https://web.archive.org/web/20191121062007/http://www.trnicely.net/misc/bpsw.html.
(Note that Nicely's definition of the "extra strong" test gives the wrong Jacobi condition,
as pointed out by Jacobsen.)
Crandall and Pomerance, Prime Numbers: A Computational Perspective, 2nd ed.
Springer, 2005.
func (n nat) probablyPrimeLucas() bool
probablyPrimeMillerRabin
method
#
probablyPrimeMillerRabin reports whether n passes reps rounds of the
Miller-Rabin primality test, using pseudo-randomly chosen bases.
If force2 is true, one of the rounds is forced to use base 2.
See Handbook of Applied Cryptography, p. 139, Algorithm 4.24.
The number n is known to be non-zero.
func (n nat) probablyPrimeMillerRabin(reps int, force2 bool) bool
putNat
function
#
func putNat(x *nat)
quotToFloat32
function
#
quotToFloat32 returns the non-negative float32 value
nearest to the quotient a/b, using round-to-even in
halfway cases. It does not mutate its arguments.
Preconditions: b is non-zero; a and b have no common factors.
func quotToFloat32(a nat, b nat) (f float32, exact bool)
quotToFloat64
function
#
quotToFloat64 returns the non-negative float64 value
nearest to the quotient a/b, using round-to-even in
halfway cases. It does not mutate its arguments.
Preconditions: b is non-zero; a and b have no common factors.
func quotToFloat64(a nat, b nat) (f float64, exact bool)
random
method
#
random creates a random integer in [0..limit), using the space in z if
possible. n is the bit length of limit.
func (z nat) random(rand *rand.Rand, limit nat, n int) nat
ratTok
function
#
func ratTok(ch rune) bool
reciprocalWord
function
#
reciprocalWord return the reciprocal of the divisor. rec = floor(( _B^2 - 1 ) / u - _B). u = d1 << nlz(d1).
func reciprocalWord(d1 Word) Word
rem
method
#
rem returns r such that r = u%v.
It uses z as the storage for r.
func (z nat) rem(u nat, v nat) (r nat)
round
method
#
round rounds z according to z.mode to z.prec bits and sets z.acc accordingly.
sbit must be 0 or 1 and summarizes any "sticky bit" information one might
have before calling round. z's mantissa must be normalized (with the msb set)
or empty.
CAUTION: The rounding modes [ToNegativeInf], [ToPositiveInf] are affected by the
sign of z. For correct rounding, the sign of z must be set correctly before
calling round.
func (z *Float) round(sbit uint)
round
method
#
round sets x to (at most) n mantissa digits by rounding it
to the nearest even value with n (or fever) mantissa digits.
If n < 0, x remains unchanged.
func (x *decimal) round(n int)
roundDown
method
#
func (x *decimal) roundDown(n int)
roundShortest
function
#
func roundShortest(d *decimal, x *Float)
roundUp
method
#
func (x *decimal) roundUp(n int)
same
function
#
func same(x nat, y nat) bool
scaleDenom
method
#
scaleDenom sets z to the product x*f.
If f == 0 (zero value of denominator), z is set to (a copy of) x.
func (z *Int) scaleDenom(x *Int, f nat)
scan
method
#
scan sets z to the integer value corresponding to the longest possible prefix
read from r representing a signed integer number in a given conversion base.
It returns z, the actual conversion base used, and an error, if any. In the
error case, the value of z is undefined but the returned value is nil. The
syntax follows the syntax of integer literals in Go.
The base argument must be 0 or a value from 2 through MaxBase. If the base
is 0, the string prefix determines the actual conversion base. A prefix of
“0b” or “0B” selects base 2; a “0”, “0o”, or “0O” prefix selects
base 8, and a “0x” or “0X” prefix selects base 16. Otherwise the selected
base is 10.
func (z *Int) scan(r io.ByteScanner, base int) (*Int, int, error)
scan
method
#
scan is like Parse but reads the longest possible prefix representing a valid
floating point number from an io.ByteScanner rather than a string. It serves
as the implementation of Parse. It does not recognize ±Inf and does not expect
EOF at the end.
func (z *Float) scan(r io.ByteScanner, base int) (f *Float, b int, err error)
scan
method
#
scan scans the number corresponding to the longest possible prefix
from r representing an unsigned number in a given conversion base.
scan returns the corresponding natural number res, the actual base b,
a digit count, and a read or syntax error err, if any.
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, or the returned
digit count. Incorrect placement of underscores is reported as an
error if there are no other errors. If base != 0, underscores are
not recognized and thus terminate scanning like any other character
that is not a valid radix point or digit.
number = mantissa | prefix pmantissa .
prefix = "0" [ "b" | "B" | "o" | "O" | "x" | "X" ] .
mantissa = digits "." [ digits ] | digits | "." digits .
pmantissa = [ "_" ] digits "." [ digits ] | [ "_" ] digits | "." digits .
digits = digit { [ "_" ] digit } .
digit = "0" ... "9" | "a" ... "z" | "A" ... "Z" .
Unless fracOk is set, the base argument must be 0 or a value between
2 and MaxBase. If fracOk is set, the base argument must be one of
0, 2, 8, 10, or 16. Providing an invalid base argument leads to a run-
time panic.
For base 0, the number prefix determines the actual base: A prefix of
“0b” or “0B” selects base 2, “0o” or “0O” selects base 8, and
“0x” or “0X” selects base 16. If fracOk is false, a “0” prefix
(immediately followed by digits) selects base 8 as well. Otherwise,
the selected base is 10 and no prefix is accepted.
If fracOk is set, a period followed by a fractional part is permitted.
The result value is computed as if there were no period present; and
the count value is used to determine the fractional part.
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.
A result digit count > 0 corresponds to the number of (non-prefix) digits
parsed. A digit count <= 0 indicates the presence of a period (if fracOk
is set, only), and -count is the number of fractional digits found.
In this case, the actual value of the scanned number is res * b**count.
func (z nat) scan(r io.ByteScanner, base int, fracOk bool) (res nat, b int, count int, err error)
scanExponent
function
#
scanExponent scans the longest possible prefix of r representing a base 10
(“e”, “E”) or a base 2 (“p”, “P”) exponent, if any. It returns the
exponent, the exponent base (10 or 2), or a read or syntax error, if any.
If sepOk is set, an underscore character “_” may appear between successive
exponent digits; such underscores do not change the value of the exponent.
Incorrect placement of underscores is reported as an error if there are no
other errors. If sepOk is not set, underscores are not recognized and thus
terminate scanning like any other character that is not a valid digit.
exponent = ( "e" | "E" | "p" | "P" ) [ sign ] digits .
sign = "+" | "-" .
digits = digit { [ '_' ] digit } .
digit = "0" ... "9" .
A base 2 exponent is only permitted if base2ok is set.
func scanExponent(r io.ByteScanner, base2ok bool, sepOk bool) (exp int64, base int, err error)
scanSign
function
#
func scanSign(r io.ByteScanner) (neg bool, err error)
set
method
#
func (z nat) set(x nat) nat
setBit
method
#
func (z nat) setBit(x nat, i uint, b uint) nat
setBits64
method
#
func (z *Float) setBits64(neg bool, x uint64) *Float
setBytes
method
#
setBytes interprets buf as the bytes of a big-endian unsigned
integer, sets z to that value, and returns z.
func (z nat) setBytes(buf []byte) nat
setExpAndRound
method
#
func (z *Float) setExpAndRound(exp int64, sbit uint)
setFromScanner
method
#
setFromScanner implements SetString given an io.ByteScanner.
For documentation see comments of SetString.
func (z *Int) setFromScanner(r io.ByteScanner, base int) (*Int, bool)
setUint64
method
#
func (z nat) setUint64(x uint64) nat
setWord
method
#
func (z nat) setWord(x Word) nat
shl
method
#
z = x << s
func (z nat) shl(x nat, s uint) nat
shlVU
function
#
func shlVU(z []Word, x []Word, s uint) (c Word)
shlVU
function
#
shlVU should be an internal detail,
but widely used packages access it using linkname.
Notable members of the hall of shame include:
- github.com/remyoudompheng/bigfft
Do not remove or change the type signature.
See go.dev/issue/67401.
go:linkname shlVU
go:noescape
func shlVU(z []Word, x []Word, s uint) (c Word)
shlVU_g
function
#
func shlVU_g(z []Word, x []Word, s uint) (c Word)
shouldRoundUp
function
#
shouldRoundUp reports if x should be rounded up
if shortened to n digits. n must be a valid index
for x.mant.
func shouldRoundUp(x *decimal, n int) bool
shr
function
#
shr implements x >> s, for s <= maxShift.
func shr(x *decimal, s uint)
shr
method
#
z = x >> s
func (z nat) shr(x nat, s uint) nat
shrVU
function
#
func shrVU(z []Word, x []Word, s uint) (c Word)
shrVU
function
#
go:noescape
func shrVU(z []Word, x []Word, s uint) (c Word)
shrVU_g
function
#
func shrVU_g(z []Word, x []Word, s uint) (c Word)
sqr
method
#
z = x*x
func (z nat) sqr(x nat) nat
sqrt
method
#
sqrt sets z = ⌊√x⌋
func (z nat) sqrt(x nat) nat
sqrtInverse
method
#
Compute √x (to z.prec precision) by solving
1/t² - x = 0
for t (using Newton's method), and then inverting.
func (z *Float) sqrtInverse(x *Float)
sticky
method
#
sticky returns 1 if there's a 1 bit within the
i least significant bits, otherwise it returns 0.
func (x nat) sticky(i uint) uint
sub
method
#
func (z nat) sub(x nat, y nat) nat
subMod2N
method
#
subMod2N returns z = (x - y) mod 2ⁿ.
func (z nat) subMod2N(x nat, y nat, n uint) nat
subVV
function
#
subVV should be an internal detail,
but widely used packages access it using linkname.
Notable members of the hall of shame include:
- github.com/remyoudompheng/bigfft
Do not remove or change the type signature.
See go.dev/issue/67401.
go:linkname subVV
go:noescape
func subVV(z []Word, x []Word, y []Word) (c Word)
subVV
function
#
func subVV(z []Word, x []Word, y []Word) (c Word)
subVV_check
function
#
func subVV_check(z []Word, x []Word, y []Word) (c Word)
subVV_g
function
#
The resulting carry c is either 0 or 1.
func subVV_g(z []Word, x []Word, y []Word) (c Word)
subVV_novec
function
#
func subVV_novec(z []Word, x []Word, y []Word) (c Word)
subVV_vec
function
#
func subVV_vec(z []Word, x []Word, y []Word) (c Word)
subVW
function
#
func subVW(z []Word, x []Word, y Word) (c Word)
subVW
function
#
subVW should be an internal detail,
but widely used packages access it using linkname.
Notable members of the hall of shame include:
- github.com/remyoudompheng/bigfft
Do not remove or change the type signature.
See go.dev/issue/67401.
go:linkname subVW
go:noescape
func subVW(z []Word, x []Word, y Word) (c Word)
subVW_g
function
#
func subVW_g(z []Word, x []Word, y Word) (c Word)
subVWlarge
function
#
subVWlarge is to subVW as addVWlarge is to addVW.
func subVWlarge(z []Word, x []Word, y Word) (c Word)
three
function
#
func three() *Float
trailingZeroBits
method
#
trailingZeroBits returns the number of consecutive least significant zero
bits of x.
func (x nat) trailingZeroBits() uint
trim
function
#
trim cuts off any trailing zeros from x's mantissa;
they are meaningless for the value of x.
func trim(x *decimal)
trunc
method
#
trunc returns z = x mod 2ⁿ.
func (z nat) trunc(x nat, n uint) nat
uadd
method
#
z = x + y, ignoring signs of x and y for the addition
but using the sign of z for rounding the result.
x and y must have a non-empty mantissa and valid exponent.
func (z *Float) uadd(x *Float, y *Float)
ucmp
method
#
ucmp returns -1, 0, or +1, depending on whether
|x| < |y|, |x| == |y|, or |x| > |y|.
x and y must have a non-empty mantissa and valid exponent.
func (x *Float) ucmp(y *Float) int
umax32
function
#
func umax32(x uint32, y uint32) uint32
umul
method
#
z = x * y, ignoring signs of x and y for the multiplication
but using the sign of z for rounding the result.
x and y must have a non-empty mantissa and valid exponent.
func (z *Float) umul(x *Float, y *Float)
uquo
method
#
z = x / y, ignoring signs of x and y for the division
but using the sign of z for rounding the result.
x and y must have a non-empty mantissa and valid exponent.
func (z *Float) uquo(x *Float, y *Float)
usub
method
#
z = x - y for |x| > |y|, ignoring signs of x and y for the subtraction
but using the sign of z for rounding the result.
x and y must have a non-empty mantissa and valid exponent.
func (z *Float) usub(x *Float, y *Float)
utoa
method
#
utoa converts x to an ASCII representation in the given base;
base must be between 2 and MaxBase, inclusive.
func (x nat) utoa(base int) []byte
validate
method
#
debugging support
func (x *Float) validate()
validate0
method
#
func (x *Float) validate0() string
validateBinaryOperands
function
#
func validateBinaryOperands(x *Float, y *Float)
writeMultiple
function
#
write count copies of text to s.
func writeMultiple(s fmt.State, text string, count int)
xor
method
#
func (z nat) xor(x nat, y nat) nat