Documentation
¶
Overview ¶
Package big implements arbitrary-precision arithmetic (big numbers). The following numeric types are supported:
Int signed integers Rat rational numbers Float floating-point numbers
The zero value for an Int, Rat, or Float correspond to 0. Thus, new values can be declared in the usual ways and denote 0 without further initialization:
var x Int // &x is an *Int of value 0
var r = &Rat{} // r is a *Rat of value 0
y := new(Float) // y is a *Float of value 0
Alternatively, new values can be allocated and initialized with factory functions of the form:
func NewT(v V) *T
For instance, NewInt(x) returns an *Int set to the value of the int64 argument x, NewRat(a, b) returns a *Rat set to the fraction a/b where a and b are int64 values, and NewFloat(f) returns a *Float initialized to the float64 argument f. More flexibility is provided with explicit setters, for instance:
var z1 Int z1.SetUint64(123) // z1 := 123 z2 := new(Rat).SetFloat64(1.25) // z2 := 5/4 z3 := new(Float).SetInt(z1) // z3 := 123.0
Setters, numeric operations and predicates are represented as methods of the form:
func (z *T) SetV(v V) *T // z = v func (z *T) Unary(x *T) *T // z = unary x func (z *T) Binary(x, y *T) *T // z = x binary y func (x *T) Pred() P // p = pred(x)
with T one of Int, Rat, or Float. For unary and binary operations, the result is the receiver (usually named z in that case; see below); if it is one of the operands x or y it may be safely overwritten (and its memory reused).
Arithmetic expressions are typically written as a sequence of individual method calls, with each call corresponding to an operation. The receiver denotes the result and the method arguments are the operation's operands. For instance, given three *Int values a, b and c, the invocation
c.Add(a, b)
computes the sum a + b and stores the result in c, overwriting whatever value was held in c before. Unless specified otherwise, operations permit aliasing of parameters, so it is perfectly ok to write
sum.Add(sum, x)
to accumulate values x in a sum.
(By always passing in a result value via the receiver, memory use can be much better controlled. Instead of having to allocate new memory for each result, an operation can reuse the space allocated for the result value, and overwrite that value with the new result in the process.)
Notational convention: Incoming method parameters (including the receiver) are named consistently in the API to clarify their use. Incoming operands are usually named x, y, a, b, and so on, but never z. A parameter specifying the result is named z (typically the receiver).
For instance, the arguments for (*Int).Add are named x and y, and because the receiver specifies the result destination, it is called z:
func (z *Int) Add(x, y *Int) *Int
Methods of this form typically return the incoming receiver as well, to enable simple call chaining.
Methods which don't require a result value to be passed in (for instance, Int.Sign), simply return the result. In this case, the receiver is typically the first operand, named x:
func (x *Int) Sign() int
Various methods support conversions between strings and corresponding numeric values, and vice versa: *Int, *Rat, and *Float values implement the Stringer interface for a (default) string representation of the value, but also provide SetString methods to initialize a value from a string in a variety of supported formats (see the respective SetString documentation).
Finally, *Int, *Rat, and *Float satisfy the fmt package's Scanner interface for scanning and (except for *Rat) the Formatter interface for formatted printing.
Example (EConvergents) ¶
This example demonstrates how to use big.Rat to compute the first 15 terms in the sequence of rational convergents for the constant e (base of natural logarithm).
package main
import (
"fmt"
"math/big"
)
// Use the classic continued fraction for e
//
// e = [1; 0, 1, 1, 2, 1, 1, ... 2n, 1, 1, ...]
//
// i.e., for the nth term, use
//
// 1 if n mod 3 != 1
// (n-1)/3 * 2 if n mod 3 == 1
func recur(n, lim int64) *big.Rat {
term := new(big.Rat)
if n%3 != 1 {
term.SetInt64(1)
} else {
term.SetInt64((n - 1) / 3 * 2)
}
if n > lim {
return term
}
// Directly initialize frac as the fractional
// inverse of the result of recur.
frac := new(big.Rat).Inv(recur(n+1, lim))
return term.Add(term, frac)
}
// This example demonstrates how to use big.Rat to compute the
// first 15 terms in the sequence of rational convergents for
// the constant e (base of natural logarithm).
func main() {
for i := 1; i <= 15; i++ {
r := recur(0, int64(i))
// Print r both as a fraction and as a floating-point number.
// Since big.Rat implements fmt.Formatter, we can use %-13s to
// get a left-aligned string representation of the fraction.
fmt.Printf("%-13s = %s\n", r, r.FloatString(8))
}
}
Output: 2/1 = 2.00000000 3/1 = 3.00000000 8/3 = 2.66666667 11/4 = 2.75000000 19/7 = 2.71428571 87/32 = 2.71875000 106/39 = 2.71794872 193/71 = 2.71830986 1264/465 = 2.71827957 1457/536 = 2.71828358 2721/1001 = 2.71828172 23225/8544 = 2.71828184 25946/9545 = 2.71828182 49171/18089 = 2.71828183 517656/190435 = 2.71828183
Example (Fibonacci) ¶
This example demonstrates how to use big.Int to compute the smallest Fibonacci number with 100 decimal digits and to test whether it is prime.
package main
import (
"fmt"
"math/big"
)
func main() {
// Initialize two big ints with the first two numbers in the sequence.
a := big.NewInt(0)
b := big.NewInt(1)
// Initialize limit as 10^99, the smallest integer with 100 digits.
var limit big.Int
limit.Exp(big.NewInt(10), big.NewInt(99), nil)
// Loop while a is smaller than 1e100.
for a.Cmp(&limit) < 0 {
// Compute the next Fibonacci number, storing it in a.
a.Add(a, b)
// Swap a and b so that b is the next number in the sequence.
a, b = b, a
}
fmt.Println(a) // 100-digit Fibonacci number
// Test a for primality.
// (ProbablyPrimes' argument sets the number of Miller-Rabin
// rounds to be performed. 20 is a good value.)
fmt.Println(a.ProbablyPrime(20))
}
Output: 1344719667586153181419716641724567886890850696275767987106294472017884974410332069524504824747437757 false
Example (Sqrt2) ¶
This example shows how to use big.Float to compute the square root of 2 with a precision of 200 bits, and how to print the result as a decimal number.
package main
import (
"fmt"
"math"
"math/big"
)
func main() {
// We'll do computations with 200 bits of precision in the mantissa.
const prec = 200
// Compute the square root of 2 using Newton's Method. We start with
// an initial estimate for sqrt(2), and then iterate:
// x_{n+1} = 1/2 * ( x_n + (2.0 / x_n) )
// Since Newton's Method doubles the number of correct digits at each
// iteration, we need at least log_2(prec) steps.
steps := int(math.Log2(prec))
// Initialize values we need for the computation.
two := new(big.Float).SetPrec(prec).SetInt64(2)
half := new(big.Float).SetPrec(prec).SetFloat64(0.5)
// Use 1 as the initial estimate.
x := new(big.Float).SetPrec(prec).SetInt64(1)
// We use t as a temporary variable. There's no need to set its precision
// since big.Float values with unset (== 0) precision automatically assume
// the largest precision of the arguments when used as the result (receiver)
// of a big.Float operation.
t := new(big.Float)
// Iterate.
for i := 0; i <= steps; i++ {
t.Quo(two, x) // t = 2.0 / x_n
t.Add(x, t) // t = x_n + (2.0 / x_n)
x.Mul(half, t) // x_{n+1} = 0.5 * t
}
// We can use the usual fmt.Printf verbs since big.Float implements fmt.Formatter
fmt.Printf("sqrt(2) = %.50f\n", x)
// Print the error between 2 and x*x.
t.Mul(x, x) // t = x*x
fmt.Printf("error = %e\n", t.Sub(two, t))
}
Output: sqrt(2) = 1.41421356237309504880168872420969807856967187537695 error = 0.000000e+00
Index ¶
- Constants
- func Jacobi(x, y *Int) int
- type Accuracy
- type ErrNaN
- type Float
- func (z *Float) Abs(x *Float) *Float
- func (x *Float) Acc() Accuracy
- func (z *Float) Add(x, y *Float) *Float
- func (x *Float) Append(buf []byte, fmt byte, prec int) []byte
- func (x *Float) Cmp(y *Float) int
- func (z *Float) Copy(x *Float) *Float
- func (x *Float) Float32() (float32, Accuracy)
- func (x *Float) Float64() (float64, Accuracy)
- func (x *Float) Format(s fmt.State, format rune)
- func (z *Float) GobDecode(buf []byte) error
- func (x *Float) GobEncode() ([]byte, error)
- func (x *Float) Int(z *Int) (*Int, Accuracy)
- func (x *Float) Int64() (int64, Accuracy)
- func (x *Float) IsInf() bool
- func (x *Float) IsInt() bool
- func (x *Float) MantExp(mant *Float) (exp int)
- func (x *Float) MarshalText() (text []byte, err error)
- func (x *Float) MinPrec() uint
- func (x *Float) Mode() RoundingMode
- func (z *Float) Mul(x, y *Float) *Float
- func (z *Float) Neg(x *Float) *Float
- func (z *Float) Parse(s string, base int) (f *Float, b int, err error)
- func (x *Float) Prec() uint
- func (z *Float) Quo(x, y *Float) *Float
- func (x *Float) Rat(z *Rat) (*Rat, Accuracy)
- func (z *Float) Scan(s fmt.ScanState, ch rune) error
- func (z *Float) Set(x *Float) *Float
- func (z *Float) SetFloat64(x float64) *Float
- func (z *Float) SetInf(signbit bool) *Float
- func (z *Float) SetInt(x *Int) *Float
- func (z *Float) SetInt64(x int64) *Float
- func (z *Float) SetMantExp(mant *Float, exp int) *Float
- func (z *Float) SetMode(mode RoundingMode) *Float
- func (z *Float) SetPrec(prec uint) *Float
- func (z *Float) SetRat(x *Rat) *Float
- func (z *Float) SetString(s string) (*Float, bool)
- func (z *Float) SetUint64(x uint64) *Float
- func (x *Float) Sign() int
- func (x *Float) Signbit() bool
- func (z *Float) Sqrt(x *Float) *Float
- func (x *Float) String() string
- func (z *Float) Sub(x, y *Float) *Float
- func (x *Float) Text(format byte, prec int) string
- func (x *Float) Uint64() (uint64, Accuracy)
- func (z *Float) UnmarshalText(text []byte) error
- type Int
- func (z *Int) Abs(x *Int) *Int
- func (z *Int) Add(x, y *Int) *Int
- func (z *Int) And(x, y *Int) *Int
- func (z *Int) AndNot(x, y *Int) *Int
- func (x *Int) Append(buf []byte, base int) []byte
- func (z *Int) Binomial(n, k int64) *Int
- func (x *Int) Bit(i int) uint
- func (x *Int) BitLen() int
- func (x *Int) Bits() []Word
- func (x *Int) Bytes() []byte
- func (x *Int) Cmp(y *Int) (r int)
- func (x *Int) CmpAbs(y *Int) int
- func (z *Int) Div(x, y *Int) *Int
- func (z *Int) DivMod(x, y, m *Int) (*Int, *Int)
- func (z *Int) Exp(x, y, m *Int) *Int
- func (x *Int) Format(s fmt.State, ch rune)
- func (z *Int) GCD(x, y, a, b *Int) *Int
- func (z *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 (z *Int) Lsh(x *Int, n uint) *Int
- func (x *Int) MarshalJSON() ([]byte, error)
- func (x *Int) MarshalText() (text []byte, err error)
- func (z *Int) Mod(x, y *Int) *Int
- func (z *Int) ModInverse(g, n *Int) *Int
- func (z *Int) ModSqrt(x, p *Int) *Int
- func (z *Int) Mul(x, y *Int) *Int
- func (z *Int) MulRange(a, b int64) *Int
- func (z *Int) Neg(x *Int) *Int
- func (z *Int) Not(x *Int) *Int
- func (z *Int) Or(x, y *Int) *Int
- func (x *Int) ProbablyPrime(n int) bool
- func (z *Int) Quo(x, y *Int) *Int
- func (z *Int) QuoRem(x, y, r *Int) (*Int, *Int)
- func (z *Int) Rand(rnd *rand.Rand, n *Int) *Int
- func (z *Int) Rem(x, y *Int) *Int
- func (z *Int) Rsh(x *Int, n uint) *Int
- func (z *Int) Scan(s fmt.ScanState, ch rune) error
- func (z *Int) Set(x *Int) *Int
- func (z *Int) SetBit(x *Int, i int, b uint) *Int
- func (z *Int) SetBits(abs []Word) *Int
- func (z *Int) SetBytes(buf []byte) *Int
- func (z *Int) SetInt64(x int64) *Int
- func (z *Int) SetString(s string, base int) (*Int, bool)
- func (z *Int) SetUint64(x uint64) *Int
- func (x *Int) Sign() int
- func (z *Int) Sqrt(x *Int) *Int
- func (x *Int) String() string
- func (z *Int) Sub(x, y *Int) *Int
- func (x *Int) Text(base int) string
- func (x *Int) TrailingZeroBits() uint
- func (x *Int) Uint64() uint64
- func (z *Int) UnmarshalJSON(text []byte) error
- func (z *Int) UnmarshalText(text []byte) error
- func (z *Int) Xor(x, y *Int) *Int
- type Rat
- func (z *Rat) Abs(x *Rat) *Rat
- func (z *Rat) Add(x, y *Rat) *Rat
- func (x *Rat) Cmp(y *Rat) int
- func (x *Rat) Denom() *Int
- func (x *Rat) Float32() (f float32, exact bool)
- func (x *Rat) Float64() (f float64, exact bool)
- func (x *Rat) FloatString(prec int) string
- func (z *Rat) GobDecode(buf []byte) error
- func (x *Rat) GobEncode() ([]byte, error)
- func (z *Rat) Inv(x *Rat) *Rat
- func (x *Rat) IsInt() bool
- func (x *Rat) MarshalText() (text []byte, err error)
- func (z *Rat) Mul(x, y *Rat) *Rat
- func (z *Rat) Neg(x *Rat) *Rat
- func (x *Rat) Num() *Int
- func (z *Rat) Quo(x, y *Rat) *Rat
- func (x *Rat) RatString() string
- func (z *Rat) Scan(s fmt.ScanState, ch rune) error
- func (z *Rat) Set(x *Rat) *Rat
- func (z *Rat) SetFloat64(f float64) *Rat
- func (z *Rat) SetFrac(a, b *Int) *Rat
- func (z *Rat) SetFrac64(a, b int64) *Rat
- func (z *Rat) SetInt(x *Int) *Rat
- func (z *Rat) SetInt64(x int64) *Rat
- func (z *Rat) SetString(s string) (*Rat, bool)
- func (z *Rat) SetUint64(x uint64) *Rat
- func (x *Rat) Sign() int
- func (x *Rat) String() string
- func (z *Rat) Sub(x, y *Rat) *Rat
- func (z *Rat) UnmarshalText(text []byte) error
- type RoundingMode
- type Word
Examples ¶
Constants ¶
const ( MaxExp = math.MaxInt32 // largest supported exponent MinExp = math.MinInt32 // smallest supported exponent MaxPrec = math.MaxUint32 // largest (theoretically) supported precision; likely memory-limited )
Exponent and precision limits.
const MaxBase = 10 + ('z' - 'a' + 1) + ('Z' - 'A' + 1)
MaxBase is the largest number base accepted for string conversions.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Accuracy ¶ added in go1.5
type Accuracy int8
Accuracy describes the rounding error produced by the most recent operation that generated a Float value, relative to the exact value.
Constants describing the Accuracy of a Float.
type ErrNaN ¶ added in go1.5
type ErrNaN struct {
// contains filtered or unexported fields
}
An ErrNaN panic is raised by a Float operation that would lead to a NaN under IEEE-754 rules. An ErrNaN implements the error interface.
type Float ¶ added in go1.5
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.
Example (Shift) ¶
package main
import (
"fmt"
"math/big"
)
func main() {
// Implement Float "shift" by modifying the (binary) exponents directly.
for s := -5; s <= 5; s++ {
x := big.NewFloat(0.5)
x.SetMantExp(x, x.MantExp(nil)+s) // shift x by s
fmt.Println(x)
}
}
Output: 0.015625 0.03125 0.0625 0.125 0.25 0.5 1 2 4 8 16
func NewFloat ¶ added in go1.5
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 ParseFloat ¶ added in go1.5
ParseFloat is like f.Parse(s, base) with f set to the given precision and rounding mode.
func (*Float) Abs ¶ added in go1.5
Abs sets z to the (possibly rounded) value |x| (the absolute value of x) and returns z.
func (*Float) Acc ¶ added in go1.5
Acc returns the accuracy of x produced by the most recent operation.
func (*Float) Add ¶ added in go1.5
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.
Example ¶
package main
import (
"fmt"
"math/big"
)
func main() {
// Operate on numbers of different precision.
var x, y, z big.Float
x.SetInt64(1000) // x is automatically set to 64bit precision
y.SetFloat64(2.718281828) // y is automatically set to 53bit precision
z.SetPrec(32)
z.Add(&x, &y)
fmt.Printf("x = %.10g (%s, prec = %d, acc = %s)\n", &x, x.Text('p', 0), x.Prec(), x.Acc())
fmt.Printf("y = %.10g (%s, prec = %d, acc = %s)\n", &y, y.Text('p', 0), y.Prec(), y.Acc())
fmt.Printf("z = %.10g (%s, prec = %d, acc = %s)\n", &z, z.Text('p', 0), z.Prec(), z.Acc())
}
Output: x = 1000 (0x.fap+10, prec = 64, acc = Exact) y = 2.718281828 (0x.adf85458248cd8p+2, prec = 53, acc = Exact) z = 1002.718282 (0x.faadf854p+10, prec = 32, acc = Below)
func (*Float) Append ¶ added in go1.5
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 ¶ added in go1.5
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
Example ¶
package main
import (
"fmt"
"math"
"math/big"
)
func main() {
inf := math.Inf(1)
zero := 0.0
operands := []float64{-inf, -1.2, -zero, 0, +1.2, +inf}
fmt.Println(" x y cmp")
fmt.Println("---------------")
for _, x64 := range operands {
x := big.NewFloat(x64)
for _, y64 := range operands {
y := big.NewFloat(y64)
fmt.Printf("%4g %4g %3d\n", x, y, x.Cmp(y))
}
fmt.Println()
}
}
Output: x y cmp --------------- -Inf -Inf 0 -Inf -1.2 -1 -Inf -0 -1 -Inf 0 -1 -Inf 1.2 -1 -Inf +Inf -1 -1.2 -Inf 1 -1.2 -1.2 0 -1.2 -0 -1 -1.2 0 -1 -1.2 1.2 -1 -1.2 +Inf -1 -0 -Inf 1 -0 -1.2 1 -0 -0 0 -0 0 0 -0 1.2 -1 -0 +Inf -1 0 -Inf 1 0 -1.2 1 0 -0 0 0 0 0 0 1.2 -1 0 +Inf -1 1.2 -Inf 1 1.2 -1.2 1 1.2 -0 1 1.2 0 1 1.2 1.2 0 1.2 +Inf -1 +Inf -Inf 1 +Inf -1.2 1 +Inf -0 1 +Inf 0 1 +Inf 1.2 1 +Inf +Inf 0
func (*Float) Copy ¶ added in go1.5
Copy sets z to x, with the same precision, rounding mode, and accuracy as x, and returns z. x is not changed even if z and x are the same.
func (*Float) Float32 ¶ added in go1.5
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 ¶ added in go1.5
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 ¶ added in go1.5
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 ¶ added in go1.7
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 ¶ added in go1.7
GobEncode implements the gob.GobEncoder interface. The Float value and all its attributes (precision, rounding mode, accuracy) are marshaled.
func (*Float) Int ¶ added in go1.5
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 (*Float) Int64 ¶ added in go1.5
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) IsInt ¶ added in go1.5
IsInt reports whether x is an integer. ±Inf values are not integers.
func (*Float) MantExp ¶ added in go1.5
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 ¶ added in go1.6
MarshalText implements the encoding.TextMarshaler interface. Only the Float value is marshaled (in full precision), other attributes such as precision or accuracy are ignored.