You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

3238 lines
110 KiB

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#375EAB">
<title>big - The Go Programming Language</title>
<link type="text/css" rel="stylesheet" href="../../../lib/godoc/style.css">
<link rel="stylesheet" href="../../../lib/godoc/jquery.treeview.css">
<script type="text/javascript">window.initFuncs = [];</script>
</head>
<body>
<div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
...
</div><!-- #lowframe -->
<div id="topbar" class="wide"><div class="container">
<div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
<div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
<a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
<form method="GET" action="http://localhost:6060/search">
<div id="menu">
<a href="http://localhost:6060/doc/">Documents</a>
<a href="http://localhost:6060/pkg/">Packages</a>
<a href="http://localhost:6060/project/">The Project</a>
<a href="http://localhost:6060/help/">Help</a>
<a href="http://localhost:6060/blog/">Blog</a>
<input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
</div>
</form>
</div></div>
<div id="page" class="wide">
<div class="container">
<h1>Package big</h1>
<div id="nav"></div>
<!--
Copyright 2009 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<!--
Note: Static (i.e., not template-generated) href and id
attributes start with "pkg-" to make it impossible for
them to conflict with generated attributes (some of which
correspond to Go identifiers).
-->
<script type='text/javascript'>
document.ANALYSIS_DATA = null;
document.CALLGRAPH = null;
</script>
<div id="short-nav">
<dl>
<dd><code>import "math/big"</code></dd>
</dl>
<dl>
<dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
<dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
<dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd>
</dl>
</div>
<!-- The package's Name is printed as title by the top-level template -->
<div id="pkg-overview" class="toggleVisible">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
</div>
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
<p>
Package big implements arbitrary-precision arithmetic (big numbers).
The following numeric types are supported:
</p>
<pre>Int signed integers
Rat rational numbers
Float floating-point numbers
</pre>
<p>
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:
</p>
<pre>var x Int // &amp;x is an *Int of value 0
var r = &amp;Rat{} // r is a *Rat of value 0
y := new(Float) // y is a *Float of value 0
</pre>
<p>
Alternatively, new values can be allocated and initialized with factory
functions of the form:
</p>
<pre>func NewT(v V) *T
</pre>
<p>
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:
</p>
<pre>var z1 Int
z1.SetUint64(123) // z1 := 123
z2 := new(Rat).SetFloat64(1.2) // z2 := 6/5
z3 := new(Float).SetInt(z1) // z3 := 123.0
</pre>
<p>
Setters, numeric operations and predicates are represented as methods of
the form:
</p>
<pre>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)
</pre>
<p>
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).
</p>
<p>
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&#39;s operands.
For instance, given three *Int values a, b and c, the invocation
</p>
<pre>c.Add(a, b)
</pre>
<p>
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
</p>
<pre>sum.Add(sum, x)
</pre>
<p>
to accumulate values x in a sum.
</p>
<p>
(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.)
</p>
<p>
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).
</p>
<p>
For instance, the arguments for (*Int).Add are named x and y, and because
the receiver specifies the result destination, it is called z:
</p>
<pre>func (z *Int) Add(x, y *Int) *Int
</pre>
<p>
Methods of this form typically return the incoming receiver as well, to
enable simple call chaining.
</p>
<p>
Methods which don&#39;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:
</p>
<pre>func (x *Int) Sign() int
</pre>
<p>
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).
</p>
<p>
Finally, *Int, *Rat, and *Float satisfy the fmt package&#39;s Scanner interface
for scanning and (except for *Rat) the Formatter interface for formatted
printing.
</p>
</div>
</div>
<div id="example__eConvergents" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example (EConvergents)</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example (EConvergents)</span></p>
<p>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).
</p>
<p>Code:</p>
<pre class="code">package big_test
import (
&#34;fmt&#34;
&#34;math/big&#34;
)
<span class="comment">// Use the classic continued fraction for e</span>
<span class="comment">// e = [1; 0, 1, 1, 2, 1, 1, ... 2n, 1, 1, ...]</span>
<span class="comment">// i.e., for the nth term, use</span>
<span class="comment">// 1 if n mod 3 != 1</span>
<span class="comment">// (n-1)/3 * 2 if n mod 3 == 1</span>
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 &gt; lim {
return term
}
<span class="comment">// Directly initialize frac as the fractional</span>
<span class="comment">// inverse of the result of recur.</span>
frac := new(big.Rat).Inv(recur(n+1, lim))
return term.Add(term, frac)
}
<span class="comment">// This example demonstrates how to use big.Rat to compute the</span>
<span class="comment">// first 15 terms in the sequence of rational convergents for</span>
<span class="comment">// the constant e (base of natural logarithm).</span>
func Example_eConvergents() {
for i := 1; i &lt;= 15; i++ {
r := recur(0, int64(i))
<span class="comment">// Print r both as a fraction and as a floating-point number.</span>
<span class="comment">// Since big.Rat implements fmt.Formatter, we can use %-13s to</span>
<span class="comment">// get a left-aligned string representation of the fraction.</span>
fmt.Printf(&#34;%-13s = %s\n&#34;, r, r.FloatString(8))
}
<span class="comment">// Output:</span>
<span class="comment">// 2/1 = 2.00000000</span>
<span class="comment">// 3/1 = 3.00000000</span>
<span class="comment">// 8/3 = 2.66666667</span>
<span class="comment">// 11/4 = 2.75000000</span>
<span class="comment">// 19/7 = 2.71428571</span>
<span class="comment">// 87/32 = 2.71875000</span>
<span class="comment">// 106/39 = 2.71794872</span>
<span class="comment">// 193/71 = 2.71830986</span>
<span class="comment">// 1264/465 = 2.71827957</span>
<span class="comment">// 1457/536 = 2.71828358</span>
<span class="comment">// 2721/1001 = 2.71828172</span>
<span class="comment">// 23225/8544 = 2.71828184</span>
<span class="comment">// 25946/9545 = 2.71828182</span>
<span class="comment">// 49171/18089 = 2.71828183</span>
<span class="comment">// 517656/190435 = 2.71828183</span>
}
</pre>
</div>
</div>
<div id="example__fibonacci" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example (Fibonacci)</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example (Fibonacci)</span></p>
<p>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.
</p>
<p>Code:</p>
<pre class="code"><span class="comment">// Initialize two big ints with the first two numbers in the sequence.</span>
a := big.NewInt(0)
b := big.NewInt(1)
<span class="comment">// Initialize limit as 10^99, the smallest integer with 100 digits.</span>
var limit big.Int
limit.Exp(big.NewInt(10), big.NewInt(99), nil)
<span class="comment">// Loop while a is smaller than 1e100.</span>
for a.Cmp(&amp;limit) &lt; 0 {
<span class="comment">// Compute the next Fibonacci number, storing it in a.</span>
a.Add(a, b)
<span class="comment">// Swap a and b so that b is the next number in the sequence.</span>
a, b = b, a
}
fmt.Println(a) <span class="comment">// 100-digit Fibonacci number</span>
<span class="comment">// Test a for primality.</span>
<span class="comment">// (ProbablyPrimes&#39; argument sets the number of Miller-Rabin</span>
<span class="comment">// rounds to be performed. 20 is a good value.)</span>
fmt.Println(a.ProbablyPrime(20))
<span class="comment"></pre>
<p>Output:</p>
<pre class="output">1344719667586153181419716641724567886890850696275767987106294472017884974410332069524504824747437757
false
</pre>
</div>
</div>
<div id="example__sqrt2" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example (Sqrt2)</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example (Sqrt2)</span></p>
<p>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.
</p>
<p>Code:</p>
<pre class="code"><span class="comment">// We&#39;ll do computations with 200 bits of precision in the mantissa.</span>
const prec = 200
<span class="comment">// Compute the square root of 2 using Newton&#39;s Method. We start with</span>
<span class="comment">// an initial estimate for sqrt(2), and then iterate:</span>
<span class="comment">// x_{n+1} = 1/2 * ( x_n + (2.0 / x_n) )</span>
<span class="comment">// Since Newton&#39;s Method doubles the number of correct digits at each</span>
<span class="comment">// iteration, we need at least log_2(prec) steps.</span>
steps := int(math.Log2(prec))
<span class="comment">// Initialize values we need for the computation.</span>
two := new(big.Float).SetPrec(prec).SetInt64(2)
half := new(big.Float).SetPrec(prec).SetFloat64(0.5)
<span class="comment">// Use 1 as the initial estimate.</span>
x := new(big.Float).SetPrec(prec).SetInt64(1)
<span class="comment">// We use t as a temporary variable. There&#39;s no need to set its precision</span>
<span class="comment">// since big.Float values with unset (== 0) precision automatically assume</span>
<span class="comment">// the largest precision of the arguments when used as the result (receiver)</span>
<span class="comment">// of a big.Float operation.</span>
t := new(big.Float)
<span class="comment">// Iterate.</span>
for i := 0; i &lt;= steps; i++ {
t.Quo(two, x) <span class="comment">// t = 2.0 / x_n</span>
t.Add(x, t) <span class="comment">// t = x_n + (2.0 / x_n)</span>
x.Mul(half, t) <span class="comment">// x_{n+1} = 0.5 * t</span>
}
<span class="comment">// We can use the usual fmt.Printf verbs since big.Float implements fmt.Formatter</span>
fmt.Printf(&#34;sqrt(2) = %.50f\n&#34;, x)
<span class="comment">// Print the error between 2 and x*x.</span>
t.Mul(x, x) <span class="comment">// t = x*x</span>
fmt.Printf(&#34;error = %e\n&#34;, t.Sub(two, t))
<span class="comment"></pre>
<p>Output:</p>
<pre class="output">sqrt(2) = 1.41421356237309504880168872420969807856967187537695
error = 0.000000e+00
</pre>
</div>
</div>
<div id="pkg-index" class="toggleVisible">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
</div>
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
<div id="manual-nav">
<dl>
<dd><a href="index.html#pkg-constants">Constants</a></dd>
<dd><a href="index.html#Jacobi">func Jacobi(x, y *Int) int</a></dd>
<dd><a href="index.html#Accuracy">type Accuracy</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Accuracy.String">func (i Accuracy) String() string</a></dd>
<dd><a href="index.html#ErrNaN">type ErrNaN</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#ErrNaN.Error">func (err ErrNaN) Error() string</a></dd>
<dd><a href="index.html#Float">type Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NewFloat">func NewFloat(x float64) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#ParseFloat">func ParseFloat(s string, base int, prec uint, mode RoundingMode) (f *Float, b int, err error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Abs">func (z *Float) Abs(x *Float) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Acc">func (x *Float) Acc() Accuracy</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Add">func (z *Float) Add(x, y *Float) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Append">func (x *Float) Append(buf []byte, fmt byte, prec int) []byte</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Cmp">func (x *Float) Cmp(y *Float) int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Copy">func (z *Float) Copy(x *Float) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Float32">func (x *Float) Float32() (float32, Accuracy)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Float64">func (x *Float) Float64() (float64, Accuracy)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Format">func (x *Float) Format(s fmt.State, format rune)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Int">func (x *Float) Int(z *Int) (*Int, Accuracy)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Int64">func (x *Float) Int64() (int64, Accuracy)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.IsInf">func (x *Float) IsInf() bool</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.IsInt">func (x *Float) IsInt() bool</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.MantExp">func (x *Float) MantExp(mant *Float) (exp int)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.MarshalText">func (x *Float) MarshalText() (text []byte, err error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.MinPrec">func (x *Float) MinPrec() uint</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Mode">func (x *Float) Mode() RoundingMode</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Mul">func (z *Float) Mul(x, y *Float) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Neg">func (z *Float) Neg(x *Float) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Parse">func (z *Float) Parse(s string, base int) (f *Float, b int, err error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Prec">func (x *Float) Prec() uint</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Quo">func (z *Float) Quo(x, y *Float) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Rat">func (x *Float) Rat(z *Rat) (*Rat, Accuracy)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Set">func (z *Float) Set(x *Float) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.SetFloat64">func (z *Float) SetFloat64(x float64) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.SetInf">func (z *Float) SetInf(signbit bool) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.SetInt">func (z *Float) SetInt(x *Int) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.SetInt64">func (z *Float) SetInt64(x int64) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.SetMantExp">func (z *Float) SetMantExp(mant *Float, exp int) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.SetMode">func (z *Float) SetMode(mode RoundingMode) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.SetPrec">func (z *Float) SetPrec(prec uint) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.SetRat">func (z *Float) SetRat(x *Rat) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.SetString">func (z *Float) SetString(s string) (*Float, bool)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.SetUint64">func (z *Float) SetUint64(x uint64) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Sign">func (x *Float) Sign() int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Signbit">func (x *Float) Signbit() bool</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.String">func (x *Float) String() string</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Sub">func (z *Float) Sub(x, y *Float) *Float</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Text">func (x *Float) Text(format byte, prec int) string</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.Uint64">func (x *Float) Uint64() (uint64, Accuracy)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Float.UnmarshalText">func (z *Float) UnmarshalText(text []byte) error</a></dd>
<dd><a href="index.html#Int">type Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NewInt">func NewInt(x int64) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Abs">func (z *Int) Abs(x *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Add">func (z *Int) Add(x, y *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.And">func (z *Int) And(x, y *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.AndNot">func (z *Int) AndNot(x, y *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Append">func (x *Int) Append(buf []byte, base int) []byte</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Binomial">func (z *Int) Binomial(n, k int64) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Bit">func (x *Int) Bit(i int) uint</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.BitLen">func (x *Int) BitLen() int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Bits">func (x *Int) Bits() []Word</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Bytes">func (x *Int) Bytes() []byte</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Cmp">func (x *Int) Cmp(y *Int) (r int)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Div">func (z *Int) Div(x, y *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.DivMod">func (z *Int) DivMod(x, y, m *Int) (*Int, *Int)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Exp">func (z *Int) Exp(x, y, m *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Format">func (x *Int) Format(s fmt.State, ch rune)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.GCD">func (z *Int) GCD(x, y, a, b *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.GobDecode">func (z *Int) GobDecode(buf []byte) error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.GobEncode">func (x *Int) GobEncode() ([]byte, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Int64">func (x *Int) Int64() int64</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Lsh">func (z *Int) Lsh(x *Int, n uint) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.MarshalJSON">func (x *Int) MarshalJSON() ([]byte, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.MarshalText">func (x *Int) MarshalText() (text []byte, err error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Mod">func (z *Int) Mod(x, y *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.ModInverse">func (z *Int) ModInverse(g, n *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.ModSqrt">func (z *Int) ModSqrt(x, p *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Mul">func (z *Int) Mul(x, y *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.MulRange">func (z *Int) MulRange(a, b int64) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Neg">func (z *Int) Neg(x *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Not">func (z *Int) Not(x *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Or">func (z *Int) Or(x, y *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.ProbablyPrime">func (x *Int) ProbablyPrime(n int) bool</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Quo">func (z *Int) Quo(x, y *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.QuoRem">func (z *Int) QuoRem(x, y, r *Int) (*Int, *Int)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Rand">func (z *Int) Rand(rnd *rand.Rand, n *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Rem">func (z *Int) Rem(x, y *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Rsh">func (z *Int) Rsh(x *Int, n uint) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Scan">func (z *Int) Scan(s fmt.ScanState, ch rune) error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Set">func (z *Int) Set(x *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.SetBit">func (z *Int) SetBit(x *Int, i int, b uint) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.SetBits">func (z *Int) SetBits(abs []Word) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.SetBytes">func (z *Int) SetBytes(buf []byte) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.SetInt64">func (z *Int) SetInt64(x int64) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.SetString">func (z *Int) SetString(s string, base int) (*Int, bool)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.SetUint64">func (z *Int) SetUint64(x uint64) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Sign">func (x *Int) Sign() int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.String">func (x *Int) String() string</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Sub">func (z *Int) Sub(x, y *Int) *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Text">func (x *Int) Text(base int) string</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Uint64">func (x *Int) Uint64() uint64</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.UnmarshalJSON">func (z *Int) UnmarshalJSON(text []byte) error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.UnmarshalText">func (z *Int) UnmarshalText(text []byte) error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Int.Xor">func (z *Int) Xor(x, y *Int) *Int</a></dd>
<dd><a href="index.html#Rat">type Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NewRat">func NewRat(a, b int64) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Abs">func (z *Rat) Abs(x *Rat) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Add">func (z *Rat) Add(x, y *Rat) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Cmp">func (x *Rat) Cmp(y *Rat) int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Denom">func (x *Rat) Denom() *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Float32">func (x *Rat) Float32() (f float32, exact bool)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Float64">func (x *Rat) Float64() (f float64, exact bool)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.FloatString">func (x *Rat) FloatString(prec int) string</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.GobDecode">func (z *Rat) GobDecode(buf []byte) error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.GobEncode">func (x *Rat) GobEncode() ([]byte, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Inv">func (z *Rat) Inv(x *Rat) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.IsInt">func (x *Rat) IsInt() bool</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.MarshalText">func (x *Rat) MarshalText() (text []byte, err error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Mul">func (z *Rat) Mul(x, y *Rat) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Neg">func (z *Rat) Neg(x *Rat) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Num">func (x *Rat) Num() *Int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Quo">func (z *Rat) Quo(x, y *Rat) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.RatString">func (x *Rat) RatString() string</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Scan">func (z *Rat) Scan(s fmt.ScanState, ch rune) error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Set">func (z *Rat) Set(x *Rat) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.SetFloat64">func (z *Rat) SetFloat64(f float64) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.SetFrac">func (z *Rat) SetFrac(a, b *Int) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.SetFrac64">func (z *Rat) SetFrac64(a, b int64) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.SetInt">func (z *Rat) SetInt(x *Int) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.SetInt64">func (z *Rat) SetInt64(x int64) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.SetString">func (z *Rat) SetString(s string) (*Rat, bool)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Sign">func (x *Rat) Sign() int</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.String">func (x *Rat) String() string</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.Sub">func (z *Rat) Sub(x, y *Rat) *Rat</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rat.UnmarshalText">func (z *Rat) UnmarshalText(text []byte) error</a></dd>
<dd><a href="index.html#RoundingMode">type RoundingMode</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#RoundingMode.String">func (i RoundingMode) String() string</a></dd>
<dd><a href="index.html#Word">type Word</a></dd>
<dd><a href="index.html#pkg-note-BUG">Bugs</a></dd>
</dl>
</div><!-- #manual-nav -->
<div id="pkg-examples">
<h4>Examples</h4>
<dl>
<dd><a class="exampleLink" href="index.html#example_Float_Add">Float.Add</a></dd>
<dd><a class="exampleLink" href="index.html#example_Float_Cmp">Float.Cmp</a></dd>
<dd><a class="exampleLink" href="index.html#example_Int_Scan">Int.Scan</a></dd>
<dd><a class="exampleLink" href="index.html#example_Int_SetString">Int.SetString</a></dd>
<dd><a class="exampleLink" href="index.html#example_Rat_Scan">Rat.Scan</a></dd>
<dd><a class="exampleLink" href="index.html#example_Rat_SetString">Rat.SetString</a></dd>
<dd><a class="exampleLink" href="index.html#example_RoundingMode">RoundingMode</a></dd>
<dd><a class="exampleLink" href="index.html#example__eConvergents">Package (EConvergents)</a></dd>
<dd><a class="exampleLink" href="index.html#example__fibonacci">Package (Fibonacci)</a></dd>
<dd><a class="exampleLink" href="index.html#example__sqrt2">Package (Sqrt2)</a></dd>
</dl>
</div>
<h4>Package files</h4>
<p>
<span style="font-size:90%">
<a href="http://localhost:6060/src/math/big/accuracy_string.go">accuracy_string.go</a>
<a href="http://localhost:6060/src/math/big/arith.go">arith.go</a>
<a href="http://localhost:6060/src/math/big/arith_decl.go">arith_decl.go</a>
<a href="http://localhost:6060/src/math/big/decimal.go">decimal.go</a>
<a href="http://localhost:6060/src/math/big/doc.go">doc.go</a>
<a href="http://localhost:6060/src/math/big/float.go">float.go</a>
<a href="http://localhost:6060/src/math/big/floatconv.go">floatconv.go</a>
<a href="http://localhost:6060/src/math/big/floatmarsh.go">floatmarsh.go</a>
<a href="http://localhost:6060/src/math/big/ftoa.go">ftoa.go</a>
<a href="http://localhost:6060/src/math/big/int.go">int.go</a>
<a href="http://localhost:6060/src/math/big/intconv.go">intconv.go</a>
<a href="http://localhost:6060/src/math/big/intmarsh.go">intmarsh.go</a>
<a href="http://localhost:6060/src/math/big/nat.go">nat.go</a>
<a href="http://localhost:6060/src/math/big/natconv.go">natconv.go</a>
<a href="http://localhost:6060/src/math/big/rat.go">rat.go</a>
<a href="http://localhost:6060/src/math/big/ratconv.go">ratconv.go</a>
<a href="http://localhost:6060/src/math/big/ratmarsh.go">ratmarsh.go</a>
<a href="http://localhost:6060/src/math/big/roundingmode_string.go">roundingmode_string.go</a>
</span>
</p>
</div><!-- .expanded -->
</div><!-- #pkg-index -->
<div id="pkg-callgraph" class="toggle" style="display: none">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
</div> <!-- .expanded -->
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
<p>
In the call graph viewer below, each node
is a function belonging to this package
and its children are the functions it
calls&mdash;perhaps dynamically.
</p>
<p>
The root nodes are the entry points of the
package: functions that may be called from
outside the package.
There may be non-exported or anonymous
functions among them if they are called
dynamically from another package.
</p>
<p>
Click a node to visit that function's source code.
From there you can visit its callers by
clicking its declaring <code>func</code>
token.
</p>
<p>
Functions may be omitted if they were
determined to be unreachable in the
particular programs or tests that were
analyzed.
</p>
<!-- Zero means show all package entry points. -->
<ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
</div>
</div> <!-- #pkg-callgraph -->
<h2 id="pkg-constants">Constants</h2>
<pre>const (
<span id="MaxExp">MaxExp</span> = <a href="../index.html">math</a>.<a href="../index.html#MaxInt32">MaxInt32</a> <span class="comment">// largest supported exponent</span>
<span id="MinExp">MinExp</span> = <a href="../index.html">math</a>.<a href="../index.html#MinInt32">MinInt32</a> <span class="comment">// smallest supported exponent</span>
<span id="MaxPrec">MaxPrec</span> = <a href="../index.html">math</a>.<a href="../index.html#MaxUint32">MaxUint32</a> <span class="comment">// largest (theoretically) supported precision; likely memory-limited</span>
)</pre>
<p>
Exponent and precision limits.
</p>
<pre>const <span id="MaxBase">MaxBase</span> = &#39;z&#39; - &#39;a&#39; + 10 + 1</pre>
<p>
MaxBase is the largest number base accepted for string conversions.
</p>
<h2 id="Jacobi">func <a href="http://localhost:6060/src/math/big/int.go?s=13910:13936#L583">Jacobi</a></h2>
<pre>func Jacobi(x, y *<a href="index.html#Int">Int</a>) <a href="../../builtin/index.html#int">int</a></pre>
<p>
Jacobi returns the Jacobi symbol (x/y), either +1, -1, or 0.
The y argument must be an odd integer.
</p>
<h2 id="Accuracy">type <a href="http://localhost:6060/src/math/big/float.go?s=5519:5537#L131">Accuracy</a></h2>
<pre>type Accuracy <a href="../../builtin/index.html#int8">int8</a></pre>
<p>
Accuracy describes the rounding error produced by the most recent
operation that generated a Float value, relative to the exact value.
</p>
<pre>const (
<span id="Below">Below</span> <a href="index.html#Accuracy">Accuracy</a> = -1
<span id="Exact">Exact</span> <a href="index.html#Accuracy">Accuracy</a> = 0
<span id="Above">Above</span> <a href="index.html#Accuracy">Accuracy</a> = +1
)</pre>
<p>
Constants describing the Accuracy of a Float.
</p>
<h3 id="Accuracy.String">func (Accuracy) <a href="http://localhost:6060/src/math/big/accuracy_string.go?s=171:204#L1">String</a></h3>
<pre>func (i <a href="index.html#Accuracy">Accuracy</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
<h2 id="ErrNaN">type <a href="http://localhost:6060/src/math/big/float.go?s=2893:2927#L60">ErrNaN</a></h2>
<pre>type ErrNaN struct {
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<p>
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.
</p>
<h3 id="ErrNaN.Error">func (ErrNaN) <a href="http://localhost:6060/src/math/big/float.go?s=2929:2961#L64">Error</a></h3>
<pre>func (err <a href="index.html#ErrNaN">ErrNaN</a>) Error() <a href="../../builtin/index.html#string">string</a></pre>
<h2 id="Float">type <a href="http://localhost:6060/src/math/big/float.go?s=2637:2749#L48">Float</a></h2>
<pre>type Float struct {
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<p>
A nonzero finite Float represents a multi-precision floating point number
</p>
<pre>sign × mantissa × 2**exponent
</pre>
<p>
with 0.5 &lt;= mantissa &lt; 1.0, and MinExp &lt;= exponent &lt;= 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).
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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).
</p>
<p>
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.
</p>
<p>
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.
</p>
<h3 id="NewFloat">func <a href="http://localhost:6060/src/math/big/float.go?s=3139:3170#L71">NewFloat</a></h3>
<pre>func NewFloat(x <a href="../../builtin/index.html#float64">float64</a>) *<a href="index.html#Float">Float</a></pre>
<p>
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.
</p>
<h3 id="ParseFloat">func <a href="http://localhost:6060/src/math/big/floatconv.go?s=6934:7028#L263">ParseFloat</a></h3>
<pre>func ParseFloat(s <a href="../../builtin/index.html#string">string</a>, base <a href="../../builtin/index.html#int">int</a>, prec <a href="../../builtin/index.html#uint">uint</a>, mode <a href="index.html#RoundingMode">RoundingMode</a>) (f *<a href="index.html#Float">Float</a>, b <a href="../../builtin/index.html#int">int</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
ParseFloat is like f.Parse(s, base) with f set to the given precision
and rounding mode.
</p>
<h3 id="Float.Abs">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=29473:29509#L1163">Abs</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) Abs(x *<a href="index.html#Float">Float</a>) *<a href="index.html#Float">Float</a></pre>
<p>
Abs sets z to the (possibly rounded) value |x| (the absolute value of x)
and returns z.
</p>
<h3 id="Float.Acc">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=7444:7474#L211">Acc</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Acc() <a href="index.html#Accuracy">Accuracy</a></pre>
<p>
Acc returns the accuracy of x produced by the most recent operation.
</p>
<h3 id="Float.Add">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=36950:36989#L1409">Add</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) Add(x, y *<a href="index.html#Float">Float</a>) *<a href="index.html#Float">Float</a></pre>
<p>
Add sets z to the rounded sum x+y and returns z. If z&#39;s precision is 0,
it is changed to the larger of x&#39;s or y&#39;s precision before the operation.
Rounding is performed according to z&#39;s precision and rounding mode; and
z&#39;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.
</p>
<p>
BUG(gri) When rounding ToNegativeInf, the sign of Float values rounded to 0 is incorrect.
</p>
<div id="example_Float_Add" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
<p>Code:</p>
<pre class="code"><span class="comment">// Operating on numbers of different precision.</span>
var x, y, z big.Float
x.SetInt64(1000) <span class="comment">// x is automatically set to 64bit precision</span>
y.SetFloat64(2.718281828) <span class="comment">// y is automatically set to 53bit precision</span>
z.SetPrec(32)
z.Add(&amp;x, &amp;y)
fmt.Printf(&#34;x = %.10g (%s, prec = %d, acc = %s)\n&#34;, &amp;x, x.Text(&#39;p&#39;, 0), x.Prec(), x.Acc())
fmt.Printf(&#34;y = %.10g (%s, prec = %d, acc = %s)\n&#34;, &amp;y, y.Text(&#39;p&#39;, 0), y.Prec(), y.Acc())
fmt.Printf(&#34;z = %.10g (%s, prec = %d, acc = %s)\n&#34;, &amp;z, z.Text(&#39;p&#39;, 0), z.Prec(), z.Acc())
<span class="comment"></pre>
<p>Output:</p>
<pre class="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)
</pre>
</div>
</div>
<h3 id="Float.Append">func (*Float) <a href="http://localhost:6060/src/math/big/ftoa.go?s=2225:2286#L46">Append</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Append(buf []<a href="../../builtin/index.html#byte">byte</a>, fmt <a href="../../builtin/index.html#byte">byte</a>, prec <a href="../../builtin/index.html#int">int</a>) []<a href="../../builtin/index.html#byte">byte</a></pre>
<p>
Append appends to buf the string form of the floating-point number x,
as generated by x.Text, and returns the extended buffer.
</p>
<h3 id="Float.Cmp">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=41304:41337#L1627">Cmp</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Cmp(y *<a href="index.html#Float">Float</a>) <a href="../../builtin/index.html#int">int</a></pre>
<p>
Cmp compares x and y and returns:
</p>
<pre>-1 if x &lt; y
0 if x == y (incl. -0 == 0, -Inf == -Inf, and +Inf == +Inf)
+1 if x &gt; y
</pre>
<div id="example_Float_Cmp" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
<p>Code:</p>
<pre class="code">inf := math.Inf(1)
zero := 0.0
operands := []float64{-inf, -1.2, -zero, 0, +1.2, +inf}
fmt.Println(&#34; x y cmp&#34;)
fmt.Println(&#34;---------------&#34;)
for _, x64 := range operands {
x := big.NewFloat(x64)
for _, y64 := range operands {
y := big.NewFloat(y64)
fmt.Printf(&#34;%4g %4g %3d\n&#34;, x, y, x.Cmp(y))
}
fmt.Println()
}
<span class="comment"></pre>
<p>Output:</p>
<pre class="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
</pre>
</div>
</div>
<h3 id="Float.Copy">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=18453:18490#L685">Copy</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) Copy(x *<a href="index.html#Float">Float</a>) *<a href="index.html#Float">Float</a></pre>
<p>
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.
</p>
<h3 id="Float.Float32">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=21859:21904#L848">Float32</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Float32() (<a href="../../builtin/index.html#float32">float32</a>, <a href="index.html#Accuracy">Accuracy</a>)</pre>
<p>
Float32 returns the float32 value nearest to x. If x is too small to be
represented by a float32 (|x| &lt; 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| &gt; math.MaxFloat32),
the result is (+Inf, Above) or (-Inf, Below), depending on the sign of x.
</p>
<h3 id="Float.Float64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=24713:24758#L955">Float64</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Float64() (<a href="../../builtin/index.html#float64">float64</a>, <a href="index.html#Accuracy">Accuracy</a>)</pre>
<p>
Float64 returns the float64 value nearest to x. If x is too small to be
represented by a float64 (|x| &lt; 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| &gt; math.MaxFloat64),
the result is (+Inf, Above) or (-Inf, Below), depending on the sign of x.
</p>
<h3 id="Float.Format">func (*Float) <a href="http://localhost:6060/src/math/big/ftoa.go?s=10329:10377#L376">Format</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Format(s <a href="../../fmt/index.html">fmt</a>.<a href="../../fmt/index.html#State">State</a>, format <a href="../../builtin/index.html#rune">rune</a>)</pre>
<p>
Format implements fmt.Formatter. It accepts all the regular
formats for floating-point numbers (&#39;e&#39;, &#39;E&#39;, &#39;f&#39;, &#39;F&#39;, &#39;g&#39;,
&#39;G&#39;) as well as &#39;b&#39;, &#39;p&#39;, and &#39;v&#39;. See (*Float).Text for the
interpretation of &#39;b&#39; and &#39;p&#39;. The &#39;v&#39; format is handled like
&#39;g&#39;.
Format also supports specification of the minimum precision
in digits, the output field width, as well as the format verbs
&#39;+&#39; and &#39; &#39; for sign control, &#39;0&#39; for space or zero padding,
and &#39;-&#39; for left or right justification. See the fmt package
for details.
</p>
<h3 id="Float.Int">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=27440:27484#L1063">Int</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Int(z *<a href="index.html#Int">Int</a>) (*<a href="index.html#Int">Int</a>, <a href="index.html#Accuracy">Accuracy</a>)</pre>
<p>
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 &gt; 0, and Above for x &lt; 0.
If a non-nil *Int argument z is provided, Int stores
the result in z instead of allocating a new Int.
</p>
<h3 id="Float.Int64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=20590:20631#L793">Int64</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Int64() (<a href="../../builtin/index.html#int64">int64</a>, <a href="index.html#Accuracy">Accuracy</a>)</pre>
<p>
Int64 returns the integer resulting from truncating x towards zero.
If math.MinInt64 &lt;= x &lt;= math.MaxInt64, the result is Exact if x is
an integer, and Above (x &lt; 0) or Below (x &gt; 0) otherwise.
The result is (math.MinInt64, Above) for x &lt; math.MinInt64,
and (math.MaxInt64, Below) for x &gt; math.MaxInt64.
</p>
<h3 id="Float.IsInf">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=9686:9714#L319">IsInf</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) IsInf() <a href="../../builtin/index.html#bool">bool</a></pre>
<p>
IsInf reports whether x is +Inf or -Inf.
</p>
<h3 id="Float.IsInt">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=9818:9846#L325">IsInt</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) IsInt() <a href="../../builtin/index.html#bool">bool</a></pre>
<p>
IsInt reports whether x is an integer.
±Inf values are not integers.
</p>
<h3 id="Float.MantExp">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=8319:8365#L249">MantExp</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) MantExp(mant *<a href="index.html#Float">Float</a>) (exp <a href="../../builtin/index.html#int">int</a>)</pre>
<p>
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 &lt;= |mant| &lt; 1.0.
Calling MantExp with a nil argument is an efficient way to
get the exponent of the receiver.
</p>
<p>
Special cases are:
</p>
<pre>( ±0).MantExp(mant) = 0, with mant set to ±0
(±Inf).MantExp(mant) = 0, with mant set to ±Inf
</pre>
<p>
x and mant may be the same in which case x is set to its
mantissa value.
</p>
<h3 id="Float.MarshalText">func (*Float) <a href="http://localhost:6060/src/math/big/floatmarsh.go?s=426:480#L4">MarshalText</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) MarshalText() (text []<a href="../../builtin/index.html#byte">byte</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
MarshalText implements the encoding.TextMarshaler interface.
Only the Float value is marshaled (in full precision), other
attributes such as precision or accuracy are ignored.
</p>
<h3 id="Float.MinPrec">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=7146:7176#L198">MinPrec</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) MinPrec() <a href="../../builtin/index.html#uint">uint</a></pre>
<p>
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.
</p>
<h3 id="Float.Mode">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=7316:7351#L206">Mode</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Mode() <a href="index.html#RoundingMode">RoundingMode</a></pre>
<p>
Mode returns the rounding mode of x.
</p>
<h3 id="Float.Mul">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=39536:39575#L1535">Mul</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) Mul(x, y *<a href="index.html#Float">Float</a>) *<a href="index.html#Float">Float</a></pre>
<p>
Mul sets z to the rounded product x*y and returns z.
Precision, rounding, and accuracy reporting are as for Add.
Mul panics with ErrNaN if one operand is zero and the other
operand an infinity. The value of z is undefined in that case.
</p>
<h3 id="Float.Neg">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=29642:29678#L1171">Neg</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) Neg(x *<a href="index.html#Float">Float</a>) *<a href="index.html#Float">Float</a></pre>
<p>
Neg sets z to the (possibly rounded) value of x with its sign negated,
and returns z.
</p>
<h3 id="Float.Parse">func (*Float) <a href="http://localhost:6060/src/math/big/floatconv.go?s=6238:6308#L235">Parse</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) Parse(s <a href="../../builtin/index.html#string">string</a>, base <a href="../../builtin/index.html#int">int</a>) (f *<a href="index.html#Float">Float</a>, b <a href="../../builtin/index.html#int">int</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
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.
</p>
<p>
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.
If z&#39;s precision is 0, it is changed to 64 before rounding takes effect.
The number must be of the form:
</p>
<pre> number = [ sign ] [ prefix ] mantissa [ exponent ] | infinity .
sign = &#34;+&#34; | &#34;-&#34; .
prefix = &#34;0&#34; ( &#34;x&#34; | &#34;X&#34; | &#34;b&#34; | &#34;B&#34; ) .
mantissa = digits | digits &#34;.&#34; [ digits ] | &#34;.&#34; digits .
exponent = ( &#34;E&#34; | &#34;e&#34; | &#34;p&#34; ) [ sign ] digits .
digits = digit { digit } .
digit = &#34;0&#34; ... &#34;9&#34; | &#34;a&#34; ... &#34;z&#34; | &#34;A&#34; ... &#34;Z&#34; .
infinity = [ sign ] ( &#34;inf&#34; | &#34;Inf&#34; ) .
</pre>
<p>
The base argument must be 0, 2, 10, or 16. Providing an invalid base
argument will lead to a run-time panic.
</p>
<p>
For base 0, the number prefix determines the actual base: A prefix of
&#34;0x&#34; or &#34;0X&#34; selects base 16, and a &#34;0b&#34; or &#34;0B&#34; prefix selects
base 2; otherwise, the actual base is 10 and no prefix is accepted.
The octal prefix &#34;0&#34; is not supported (a leading &#34;0&#34; is simply
considered a &#34;0&#34;).
</p>
<p>
A &#34;p&#34; exponent indicates a binary (rather then decimal) exponent;
for instance &#34;0x1.fffffffffffffp1023&#34; (using base 0) represents the
maximum float64 value. For hexadecimal mantissae, the exponent must
be binary, if present (an &#34;e&#34; or &#34;E&#34; exponent indicator cannot be
distinguished from a mantissa digit).
</p>
<p>
The returned *Float f is nil and the value of z is valid but not
defined if an error is reported.
</p>
<h3 id="Float.Prec">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=6895:6922#L191">Prec</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Prec() <a href="../../builtin/index.html#uint">uint</a></pre>
<p>
Prec returns the mantissa precision of x in bits.
The result may be 0 for |x| == 0 and |x| == Inf.
</p>
<h3 id="Float.Quo">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=40457:40496#L1580">Quo</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) Quo(x, y *<a href="index.html#Float">Float</a>) *<a href="index.html#Float">Float</a></pre>
<p>
Quo sets z to the rounded quotient x/y and returns z.
Precision, rounding, and accuracy reporting are as for Add.
Quo panics with ErrNaN if both operands are zero or infinities.
The value of z is undefined in that case.
</p>
<h3 id="Float.Rat">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=28539:28583#L1119">Rat</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Rat(z *<a href="index.html#Rat">Rat</a>) (*<a href="index.html#Rat">Rat</a>, <a href="index.html#Accuracy">Accuracy</a>)</pre>
<p>
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.
</p>
<h3 id="Float.Set">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=17991:18027#L661">Set</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) Set(x *<a href="index.html#Float">Float</a>) *<a href="index.html#Float">Float</a></pre>
<p>
Set sets z to the (possibly rounded) value of x and returns z.
If z&#39;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&#39;s precision and rounding
mode; and z&#39;s accuracy reports the result error relative to the
exact (not rounded) result.
</p>
<h3 id="Float.SetFloat64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=15354:15398#L559">SetFloat64</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) SetFloat64(x <a href="../../builtin/index.html#float64">float64</a>) *<a href="index.html#Float">Float</a></pre>
<p>
SetFloat64 sets z to the (possibly rounded) value of x and returns z.
If z&#39;s precision is 0, it is changed to 53 (and rounding will have
no effect). SetFloat64 panics with ErrNaN if x is a NaN.
</p>
<h3 id="Float.SetInf">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=17539:17582#L648">SetInf</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) SetInf(signbit <a href="../../builtin/index.html#bool">bool</a>) *<a href="index.html#Float">Float</a></pre>
<p>
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.
</p>
<h3 id="Float.SetInt">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=16530:16567#L607">SetInt</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) SetInt(x *<a href="index.html#Int">Int</a>) *<a href="index.html#Float">Float</a></pre>
<p>
SetInt sets z to the (possibly rounded) value of x and returns z.
If z&#39;s precision is 0, it is changed to the larger of x.BitLen()
or 64 (and rounding will have no effect).
</p>
<h3 id="Float.SetInt64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=14916:14956#L546">SetInt64</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) SetInt64(x <a href="../../builtin/index.html#int64">int64</a>) *<a href="index.html#Float">Float</a></pre>
<p>
SetInt64 sets z to the (possibly rounded) value of x and returns z.
If z&#39;s precision is 0, it is changed to 64 (and rounding will have
no effect).
</p>
<h3 id="Float.SetMantExp">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=9312:9367#L300">SetMantExp</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) SetMantExp(mant *<a href="index.html#Float">Float</a>, exp <a href="../../builtin/index.html#int">int</a>) *<a href="index.html#Float">Float</a></pre>
<p>
SetMantExp sets z to mant × 2**exp and and returns z.
The result z has the same precision and rounding mode
as mant. SetMantExp is an inverse of MantExp but does
not require 0.5 &lt;= |mant| &lt; 1.0. Specifically:
</p>
<pre>mant := new(Float)
new(Float).SetMantExp(mant, x.MantExp(mant)).Cmp(x) == 0
</pre>
<p>
Special cases are:
</p>
<pre>z.SetMantExp( ±0, exp) = ±0
z.SetMantExp(±Inf, exp) = ±Inf
</pre>
<p>
z and mant may be the same in which case z&#39;s exponent
is set to exp.
</p>
<h3 id="Float.SetMode">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=6695:6744#L183">SetMode</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) SetMode(mode <a href="index.html#RoundingMode">RoundingMode</a>) *<a href="index.html#Float">Float</a></pre>
<p>
SetMode sets z&#39;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&#39;s accuracy to Exact.
</p>
<h3 id="Float.SetPrec">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=6039:6080#L147">SetPrec</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) SetPrec(prec <a href="../../builtin/index.html#uint">uint</a>) *<a href="index.html#Float">Float</a></pre>
<p>
SetPrec sets z&#39;s precision to prec and returns the (possibly) rounded
value of z. Rounding occurs according to z&#39;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 &gt; MaxPrec, it is set to MaxPrec.
</p>
<h3 id="Float.SetRat">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=17135:17172#L631">SetRat</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) SetRat(x *<a href="index.html#Rat">Rat</a>) *<a href="index.html#Float">Float</a></pre>
<p>
SetRat sets z to the (possibly rounded) value of x and returns z.
If z&#39;s precision is 0, it is changed to the largest of a.BitLen(),
b.BitLen(), or 64; with x = a/b.
</p>
<h3 id="Float.SetString">func (*Float) <a href="http://localhost:6060/src/math/big/floatconv.go?s=461:511#L8">SetString</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) SetString(s <a href="../../builtin/index.html#string">string</a>) (*<a href="index.html#Float">Float</a>, <a href="../../builtin/index.html#bool">bool</a>)</pre>
<p>
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 Parse, with base argument 0.
</p>
<h3 id="Float.SetUint64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=14682:14724#L539">SetUint64</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) SetUint64(x <a href="../../builtin/index.html#uint64">uint64</a>) *<a href="index.html#Float">Float</a></pre>
<p>
SetUint64 sets z to the (possibly rounded) value of x and returns z.
If z&#39;s precision is 0, it is changed to 64 (and rounding will have
no effect).
</p>
<h3 id="Float.Sign">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=7569:7595#L221">Sign</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Sign() <a href="../../builtin/index.html#int">int</a></pre>
<p>
Sign returns:
</p>
<pre>-1 if x &lt; 0
0 if x is ±0
+1 if x &gt; 0
</pre>
<h3 id="Float.Signbit">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=9592:9622#L314">Signbit</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Signbit() <a href="../../builtin/index.html#bool">bool</a></pre>
<p>
Signbit returns true if x is negative or negative zero.
</p>
<h3 id="Float.String">func (*Float) <a href="http://localhost:6060/src/math/big/ftoa.go?s=2031:2062#L40">String</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
<p>
String formats x like x.Text(&#39;g&#39;, 10).
(String must be called explicitly, Float.Format does not support %s verb.)
</p>
<h3 id="Float.Sub">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=38237:38276#L1472">Sub</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) Sub(x, y *<a href="index.html#Float">Float</a>) *<a href="index.html#Float">Float</a></pre>
<p>
Sub sets z to the rounded difference x-y and returns z.
Precision, rounding, and accuracy reporting are as for Add.
Sub panics with ErrNaN if x and y are infinities with equal
signs. The value of z is undefined in that case.
</p>
<h3 id="Float.Text">func (*Float) <a href="http://localhost:6060/src/math/big/ftoa.go?s=1721:1771#L33">Text</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Text(format <a href="../../builtin/index.html#byte">byte</a>, prec <a href="../../builtin/index.html#int">int</a>) <a href="../../builtin/index.html#string">string</a></pre>
<p>
Text converts the floating-point number x to a string according
to the given format and precision prec. The format is one of:
</p>
<pre>&#39;e&#39; -d.dddde±dd, decimal exponent, at least two (possibly 0) exponent digits
&#39;E&#39; -d.ddddE±dd, decimal exponent, at least two (possibly 0) exponent digits
&#39;f&#39; -ddddd.dddd, no exponent
&#39;g&#39; like &#39;e&#39; for large exponents, like &#39;f&#39; otherwise
&#39;G&#39; like &#39;E&#39; for large exponents, like &#39;f&#39; otherwise
&#39;b&#39; -ddddddp±dd, binary exponent
&#39;p&#39; -0x.dddp±dd, binary exponent, hexadecimal mantissa
</pre>
<p>
For the binary exponent formats, the mantissa is printed in normalized form:
</p>
<pre>&#39;b&#39; decimal integer mantissa using x.Prec() bits, or -0
&#39;p&#39; hexadecimal fraction with 0.5 &lt;= 0.mantissa &lt; 1.0, or -0
</pre>
<p>
If format is a different character, Text returns a &#34;%&#34; followed by the
unrecognized format character.
</p>
<p>
The precision prec controls the number of digits (excluding the exponent)
printed by the &#39;e&#39;, &#39;E&#39;, &#39;f&#39;, &#39;g&#39;, and &#39;G&#39; formats. For &#39;e&#39;, &#39;E&#39;, and &#39;f&#39;
it is the number of digits after the decimal point. For &#39;g&#39; and &#39;G&#39; 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 &#39;b&#39; or &#39;p&#39; format.
</p>
<h3 id="Float.Uint64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=19650:19693#L748">Uint64</a></h3>
<pre>func (x *<a href="index.html#Float">Float</a>) Uint64() (<a href="../../builtin/index.html#uint64">uint64</a>, <a href="index.html#Accuracy">Accuracy</a>)</pre>
<p>
Uint64 returns the unsigned integer resulting from truncating x
towards zero. If 0 &lt;= x &lt;= math.MaxUint64, the result is Exact
if x is an integer and Below otherwise.
The result is (0, Above) for x &lt; 0, and (math.MaxUint64, Below)
for x &gt; math.MaxUint64.
</p>
<h3 id="Float.UnmarshalText">func (*Float) <a href="http://localhost:6060/src/math/big/floatmarsh.go?s=800:848#L16">UnmarshalText</a></h3>
<pre>func (z *<a href="index.html#Float">Float</a>) UnmarshalText(text []<a href="../../builtin/index.html#byte">byte</a>) <a href="../../builtin/index.html#error">error</a></pre>
<p>
UnmarshalText implements the encoding.TextUnmarshaler interface.
The result is rounded per the precision and rounding mode of z.
If z&#39;s precision is 0, it is changed to 64 before rounding takes
effect.
</p>
<h2 id="Int">type <a href="http://localhost:6060/src/math/big/int.go?s=388:468#L8">Int</a></h2>
<pre>type Int struct {
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<p>
An Int represents a signed multi-precision integer.
The zero value for an Int represents the value 0.
</p>
<h3 id="NewInt">func <a href="http://localhost:6060/src/math/big/int.go?s=1058:1083#L51">NewInt</a></h3>
<pre>func NewInt(x <a href="../../builtin/index.html#int64">int64</a>) *<a href="index.html#Int">Int</a></pre>
<p>
NewInt allocates and returns a new Int set to x.
</p>
<h3 id="Int.Abs">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=2124:2154#L85">Abs</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Abs(x *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Abs sets z to |x| (the absolute value of x) and returns z.
</p>
<h3 id="Int.Add">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=2381:2414#L99">Add</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Add(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Add sets z to the sum x+y and returns z.
</p>
<h3 id="Int.And">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=18689:18722#L789">And</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) And(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
And sets z = x &amp; y and returns z.
</p>
<h3 id="Int.AndNot">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=19370:19406#L819">AndNot</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) AndNot(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
AndNot sets z = x &amp;^ y and returns z.
</p>
<h3 id="Int.Append">func (*Int) <a href="http://localhost:6060/src/math/big/intconv.go?s=1046:1095#L24">Append</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) Append(buf []<a href="../../builtin/index.html#byte">byte</a>, base <a href="../../builtin/index.html#int">int</a>) []<a href="../../builtin/index.html#byte">byte</a></pre>
<p>
Append appends the string representation of x, as generated by
x.Text(base), to buf and returns the extended buffer.
</p>
<h3 id="Int.Binomial">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=4127:4166#L175">Binomial</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Binomial(n, k <a href="../../builtin/index.html#int64">int64</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Binomial sets z to the binomial coefficient of (n, k) and returns z.
</p>
<h3 id="Int.Bit">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=17801:17830#L749">Bit</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) Bit(i <a href="../../builtin/index.html#int">int</a>) <a href="../../builtin/index.html#uint">uint</a></pre>
<p>
Bit returns the value of the i&#39;th bit of x. That is, it
returns (x&gt;&gt;i)&amp;1. The bit index i must be &gt;= 0.
</p>
<h3 id="Int.BitLen">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=9739:9765#L391">BitLen</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) BitLen() <a href="../../builtin/index.html#int">int</a></pre>
<p>
BitLen returns the length of the absolute value of x in bits.
The bit length of 0 is 0.
</p>
<h3 id="Int.Bits">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=1572:1599#L69">Bits</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) Bits() []<a href="index.html#Word">Word</a></pre>
<p>
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.
</p>
<h3 id="Int.Bytes">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=9544:9572#L384">Bytes</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) Bytes() []<a href="../../builtin/index.html#byte">byte</a></pre>
<p>
Bytes returns the absolute value of x as a big-endian byte slice.
</p>
<h3 id="Int.Cmp">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=7472:7505#L298">Cmp</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) Cmp(y *<a href="index.html#Int">Int</a>) (r <a href="../../builtin/index.html#int">int</a>)</pre>
<p>
Cmp compares x and y and returns:
</p>
<pre>-1 if x &lt; y
0 if x == y
+1 if x &gt; y
</pre>
<h3 id="Int.Div">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=5888:5921#L225">Div</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Div(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
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 DivMod for more details.
</p>
<h3 id="Int.DivMod">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=7093:7140#L274">DivMod</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) DivMod(x, y, m *<a href="index.html#Int">Int</a>) (*<a href="index.html#Int">Int</a>, *<a href="index.html#Int">Int</a>)</pre>
<p>
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.
</p>
<p>
DivMod implements Euclidean division and modulus (unlike Go):
</p>
<pre>q = x div y such that
m = x - y*q with 0 &lt;= m &lt; |y|
</pre>
<p>
(See Raymond T. Boute, &ldquo;The Euclidean definition of the functions
div and mod&rdquo;. ACM Transactions on Programming Languages and
Systems (TOPLAS), 14(2):127-144, New York, NY, USA, 4/1992.
ACM press.)
See QuoRem for T-division and modulus (like Go).
</p>
<h3 id="Int.Exp">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=9982:10018#L398">Exp</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Exp(x, y, m *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z.
If y &lt;= 0, the result is 1 mod |m|; if m == nil or m == 0, z = x**y.
See Knuth, volume 2, section 4.6.3.
</p>
<h3 id="Int.Format">func (*Int) <a href="http://localhost:6060/src/math/big/intconv.go?s=2004:2046#L56">Format</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) Format(s <a href="../../fmt/index.html">fmt</a>.<a href="../../fmt/index.html#State">State</a>, ch <a href="../../builtin/index.html#rune">rune</a>)</pre>
<p>
Format is a support routine for fmt.Formatter. It accepts
the formats &#39;b&#39; (binary), &#39;o&#39; (octal), &#39;d&#39; (decimal), &#39;x&#39;
(lowercase hexadecimal), and &#39;X&#39; (uppercase hexadecimal).
Also supported are the full suite of package fmt&#39;s format
verbs for integral types, including &#39;+&#39;, &#39;-&#39;, and &#39; &#39;
for sign control, &#39;#&#39; for leading zero in octal and for
hexadecimal, a leading &#34;0x&#34; or &#34;0X&#34; for &#34;%#x&#34; and &#34;%#X&#34;
respectively, specification of minimum digits precision,
output field width, space or zero padding, and left or
right justification.
</p>
<h3 id="Int.GCD">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=10689:10728#L425">GCD</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) GCD(x, y, a, b *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
GCD sets z to the greatest common divisor of a and b, which both must
be &gt; 0, and returns z.
If x and y are not nil, GCD sets x and y such that z = a*x + b*y.
If either a or b is &lt;= 0, GCD sets z = x = y = 0.
</p>
<h3 id="Int.GobDecode">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=782:823#L20">GobDecode</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) GobDecode(buf []<a href="../../builtin/index.html#byte">byte</a>) <a href="../../builtin/index.html#error">error</a></pre>
<p>
GobDecode implements the gob.GobDecoder interface.
</p>
<h3 id="Int.GobEncode">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=398:439#L5">GobEncode</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) GobEncode() ([]<a href="../../builtin/index.html#byte">byte</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
GobEncode implements the gob.GobEncoder interface.
</p>
<h3 id="Int.Int64">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=8193:8220#L339">Int64</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) Int64() <a href="../../builtin/index.html#int64">int64</a></pre>
<p>
Int64 returns the int64 representation of x.
If x cannot be represented in an int64, the result is undefined.
</p>
<h3 id="Int.Lsh">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=17199:17237#L725">Lsh</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Lsh(x *<a href="index.html#Int">Int</a>, n <a href="../../builtin/index.html#uint">uint</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Lsh sets z = x &lt;&lt; n and returns z.
</p>
<h3 id="Int.MarshalJSON">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=1859:1902#L57">MarshalJSON</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) MarshalJSON() ([]<a href="../../builtin/index.html#byte">byte</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
MarshalJSON implements the json.Marshaler interface.
</p>
<h3 id="Int.MarshalText">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=1172:1224#L36">MarshalText</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) MarshalText() (text []<a href="../../builtin/index.html#byte">byte</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
MarshalText implements the encoding.TextMarshaler interface.
</p>
<h3 id="Int.Mod">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=6287:6320#L242">Mod</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Mod(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
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 DivMod for more details.
</p>
<h3 id="Int.ModInverse">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=13518:13558#L569">ModInverse</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) ModInverse(g, n *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
ModInverse sets z to the multiplicative inverse of g in the ring ℤ/nℤ
and returns z. If g and n are not relatively prime, the result is undefined.
</p>
<h3 id="Int.ModSqrt">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=16674:16711#L703">ModSqrt</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) ModSqrt(x, p *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
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.
</p>
<h3 id="Int.Mul">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=3332:3365#L141">Mul</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Mul(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Mul sets z to the product x*y and returns z.
</p>
<h3 id="Int.MulRange">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=3711:3750#L154">MulRange</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) MulRange(a, b <a href="../../builtin/index.html#int64">int64</a>) *<a href="index.html#Int">Int</a></pre>
<p>
MulRange sets z to the product of all integers
in the range [a, b] inclusively and returns z.
If a &gt; b (empty range), the result is 1.
</p>
<h3 id="Int.Neg">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=2230:2260#L92">Neg</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Neg(x *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Neg sets z to -x and returns z.
</p>
<h3 id="Int.Not">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=21631:21661#L912">Not</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Not(x *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Not sets z = ^x and returns z.
</p>
<h3 id="Int.Or">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=20184:20216#L852">Or</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Or(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Or sets z = x | y and returns z.
</p>
<h3 id="Int.ProbablyPrime">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=12954:12993#L549">ProbablyPrime</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) ProbablyPrime(n <a href="../../builtin/index.html#int">int</a>) <a href="../../builtin/index.html#bool">bool</a></pre>
<p>
ProbablyPrime performs n Miller-Rabin tests to check whether x is prime.
If x is prime, it returns true.
If x is not prime, it returns false with probability at least 1 - ¼ⁿ.
</p>
<p>
It is not suitable for judging primes that an adversary may have crafted
to fool this test.
</p>
<h3 id="Int.Quo">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=4573:4606#L189">Quo</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Quo(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
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 QuoRem for more details.
</p>
<h3 id="Int.QuoRem">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=5489:5536#L216">QuoRem</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) QuoRem(x, y, r *<a href="index.html#Int">Int</a>) (*<a href="index.html#Int">Int</a>, *<a href="index.html#Int">Int</a>)</pre>
<p>
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.
</p>
<p>
QuoRem implements T-division and modulus (like Go):
</p>
<pre>q = x/y with the result truncated to zero
r = x - y*q
</pre>
<p>
(See Daan Leijen, &ldquo;Division and Modulus for Computer Scientists&rdquo;.)
See DivMod for Euclidean division and modulus (unlike Go).
</p>
<h3 id="Int.Rand">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=13166:13213#L557">Rand</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Rand(rnd *<a href="../rand/index.html">rand</a>.<a href="../rand/index.html#Rand">Rand</a>, n *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Rand sets z to a pseudo-random number in [0, n) and returns z.
</p>
<h3 id="Int.Rem">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=4915:4948#L198">Rem</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Rem(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
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 QuoRem for more details.
</p>
<h3 id="Int.Rsh">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=17335:17373#L732">Rsh</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Rsh(x *<a href="index.html#Int">Int</a>, n <a href="../../builtin/index.html#uint">uint</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Rsh sets z = x &gt;&gt; n and returns z.
</p>
<h3 id="Int.Scan">func (*Int) <a href="http://localhost:6060/src/math/big/intconv.go?s=6298:6348#L219">Scan</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Scan(s <a href="../../fmt/index.html">fmt</a>.<a href="../../fmt/index.html#ScanState">ScanState</a>, ch <a href="../../builtin/index.html#rune">rune</a>) <a href="../../builtin/index.html#error">error</a></pre>
<p>
Scan is a support routine for fmt.Scanner; it sets z to the value of
the scanned number. It accepts the formats &#39;b&#39; (binary), &#39;o&#39; (octal),
&#39;d&#39; (decimal), &#39;x&#39; (lowercase hexadecimal), and &#39;X&#39; (uppercase hexadecimal).
</p>
<div id="example_Int_Scan" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
<p>Code:</p>
<pre class="code"><span class="comment">// The Scan function is rarely used directly;</span>
<span class="comment">// the fmt package recognizes it as an implementation of fmt.Scanner.</span>
i := new(big.Int)
_, err := fmt.Sscan(&#34;18446744073709551617&#34;, i)
if err != nil {
log.Println(&#34;error scanning value:&#34;, err)
} else {
fmt.Println(i)
}
<span class="comment"></pre>
<p>Output:</p>
<pre class="output">18446744073709551617
</pre>
</div>
</div>
<h3 id="Int.Set">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=1152:1182#L56">Set</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Set(x *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Set sets z to x and returns z.
</p>
<h3 id="Int.SetBit">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=18345:18393#L772">SetBit</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) SetBit(x *<a href="index.html#Int">Int</a>, i <a href="../../builtin/index.html#int">int</a>, b <a href="../../builtin/index.html#uint">uint</a>) *<a href="index.html#Int">Int</a></pre>
<p>
SetBit sets z to x, with x&#39;s i&#39;th bit set to b (0 or 1).
That is, if b is 1 SetBit sets z = x | (1 &lt;&lt; i);
if b is 0 SetBit sets z = x &amp;^ (1 &lt;&lt; i). If b is not 0 or 1,
SetBit will panic.
</p>
<h3 id="Int.SetBits">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=1968:2006#L78">SetBits</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) SetBits(abs []<a href="index.html#Word">Word</a>) *<a href="index.html#Int">Int</a></pre>
<p>
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.
</p>
<h3 id="Int.SetBytes">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=9376:9415#L377">SetBytes</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) SetBytes(buf []<a href="../../builtin/index.html#byte">byte</a>) *<a href="index.html#Int">Int</a></pre>
<p>
SetBytes interprets buf as the bytes of a big-endian unsigned
integer, sets z to that value, and returns z.
</p>
<h3 id="Int.SetInt64">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=717:753#L32">SetInt64</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) SetInt64(x <a href="../../builtin/index.html#int64">int64</a>) *<a href="index.html#Int">Int</a></pre>
<p>
SetInt64 sets z to x and returns z.
</p>
<h3 id="Int.SetString">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=8978:9034#L362">SetString</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) SetString(s <a href="../../builtin/index.html#string">string</a>, base <a href="../../builtin/index.html#int">int</a>) (*<a href="index.html#Int">Int</a>, <a href="../../builtin/index.html#bool">bool</a>)</pre>
<p>
SetString sets z to the value of s, interpreted in the given base,
and returns z and a boolean indicating success. If SetString fails,
the value of z is undefined but the returned value is nil.
</p>
<p>
The base argument must be 0 or a value between 2 and MaxBase. If the base
is 0, the string prefix determines the actual conversion base. A prefix of
&ldquo;0x&rdquo; or &ldquo;0X&rdquo; selects base 16; the &ldquo;0&rdquo; prefix selects base 8, and a
&ldquo;0b&rdquo; or &ldquo;0B&rdquo; prefix selects base 2. Otherwise the selected base is 10.
</p>
<div id="example_Int_SetString" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
<p>Code:</p>
<pre class="code">i := new(big.Int)
i.SetString(&#34;644&#34;, 8) <span class="comment">// octal</span>
fmt.Println(i)
<span class="comment"></pre>
<p>Output:</p>
<pre class="output">420
</pre>
</div>
</div>
<h3 id="Int.SetUint64">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=909:947#L44">SetUint64</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) SetUint64(x <a href="../../builtin/index.html#uint64">uint64</a>) *<a href="index.html#Int">Int</a></pre>
<p>
SetUint64 sets z to x and returns z.
</p>
<h3 id="Int.Sign">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=575:599#L21">Sign</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) Sign() <a href="../../builtin/index.html#int">int</a></pre>
<p>
Sign returns:
</p>
<pre>-1 if x &lt; 0
0 if x == 0
+1 if x &gt; 0
</pre>
<h3 id="Int.String">func (*Int) <a href="http://localhost:6060/src/math/big/intconv.go?s=1200:1229#L31">String</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
<h3 id="Int.Sub">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=2858:2891#L120">Sub</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Sub(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Sub sets z to the difference x-y and returns z.
</p>
<h3 id="Int.Text">func (*Int) <a href="http://localhost:6060/src/math/big/intconv.go?s=807:842#L15">Text</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) Text(base <a href="../../builtin/index.html#int">int</a>) <a href="../../builtin/index.html#string">string</a></pre>
<p>
Text returns the string representation of x in the given base.
Base must be between 2 and 36, inclusive. The result uses the
lower-case letters &#39;a&#39; to &#39;z&#39; for digit values &gt;= 10. No base
prefix (such as &#34;0x&#34;) is added to the string.
</p>
<h3 id="Int.Uint64">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=8404:8433#L349">Uint64</a></h3>
<pre>func (x *<a href="index.html#Int">Int</a>) Uint64() <a href="../../builtin/index.html#uint64">uint64</a></pre>
<p>
Uint64 returns the uint64 representation of x.
If x cannot be represented in a uint64, the result is undefined.
</p>
<h3 id="Int.UnmarshalJSON">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=1992:2038#L62">UnmarshalJSON</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) UnmarshalJSON(text []<a href="../../builtin/index.html#byte">byte</a>) <a href="../../builtin/index.html#error">error</a></pre>
<p>
UnmarshalJSON implements the json.Unmarshaler interface.
</p>
<h3 id="Int.UnmarshalText">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=1381:1427#L44">UnmarshalText</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) UnmarshalText(text []<a href="../../builtin/index.html#byte">byte</a>) <a href="../../builtin/index.html#error">error</a></pre>
<p>
UnmarshalText implements the encoding.TextUnmarshaler interface.
</p>
<h3 id="Int.Xor">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=20954:20987#L882">Xor</a></h3>
<pre>func (z *<a href="index.html#Int">Int</a>) Xor(x, y *<a href="index.html#Int">Int</a>) *<a href="index.html#Int">Int</a></pre>
<p>
Xor sets z = x ^ y and returns z.
</p>
<h2 id="Rat">type <a href="http://localhost:6060/src/math/big/rat.go?s=370:570#L6">Rat</a></h2>
<pre>type Rat struct {
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<p>
A Rat represents a quotient a/b of arbitrary precision.
The zero value for a Rat represents the value 0.
</p>
<h3 id="NewRat">func <a href="http://localhost:6060/src/math/big/rat.go?s=636:664#L14">NewRat</a></h3>
<pre>func NewRat(a, b <a href="../../builtin/index.html#int64">int64</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
NewRat creates a new Rat with numerator a and denominator b.
</p>
<h3 id="Rat.Abs">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=8897:8927#L335">Abs</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) Abs(x *<a href="index.html#Rat">Rat</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
Abs sets z to |x| (the absolute value of x) and returns z.
</p>
<h3 id="Rat.Add">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=11795:11828#L464">Add</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) Add(x, y *<a href="index.html#Rat">Rat</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
Add sets z to the sum x+y and returns z.
</p>
<h3 id="Rat.Cmp">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=11651:11680#L459">Cmp</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) Cmp(y *<a href="index.html#Rat">Rat</a>) <a href="../../builtin/index.html#int">int</a></pre>
<p>
Cmp compares x and y and returns:
</p>
<pre>-1 if x &lt; y
0 if x == y
+1 if x &gt; y
</pre>
<h3 id="Rat.Denom">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=10168:10194#L392">Denom</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) Denom() *<a href="index.html#Int">Int</a></pre>
<p>
Denom returns the denominator of x; it is always &gt; 0.
The result is a reference to x&#39;s denominator; it
may change if a new value is assigned to x, and vice versa.
</p>
<h3 id="Rat.Float32">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=7126:7173#L254">Float32</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) Float32() (f <a href="../../builtin/index.html#float32">float32</a>, exact <a href="../../builtin/index.html#bool">bool</a>)</pre>
<p>
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.
</p>
<h3 id="Rat.Float64">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=7611:7658#L270">Float64</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) Float64() (f <a href="../../builtin/index.html#float64">float64</a>, exact <a href="../../builtin/index.html#bool">bool</a>)</pre>
<p>
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.
</p>
<h3 id="Rat.FloatString">func (*Rat) <a href="http://localhost:6060/src/math/big/ratconv.go?s=4796:4838#L204">FloatString</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) FloatString(prec <a href="../../builtin/index.html#int">int</a>) <a href="../../builtin/index.html#string">string</a></pre>
<p>
FloatString returns a string representation of x in decimal form with prec
digits of precision after the decimal point. The last digit is rounded to
nearest, with halves rounded away from zero.
</p>
<h3 id="Rat.GobDecode">func (*Rat) <a href="http://localhost:6060/src/math/big/ratmarsh.go?s=1058:1099#L32">GobDecode</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) GobDecode(buf []<a href="../../builtin/index.html#byte">byte</a>) <a href="../../builtin/index.html#error">error</a></pre>
<p>
GobDecode implements the gob.GobDecoder interface.
</p>
<h3 id="Rat.GobEncode">func (*Rat) <a href="http://localhost:6060/src/math/big/ratmarsh.go?s=432:473#L9">GobEncode</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) GobEncode() ([]<a href="../../builtin/index.html#byte">byte</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
GobEncode implements the gob.GobEncoder interface.
</p>
<h3 id="Rat.Inv">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=9154:9184#L349">Inv</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) Inv(x *<a href="index.html#Rat">Rat</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
Inv sets z to 1/x and returns z.
</p>
<h3 id="Rat.IsInt">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=9644:9670#L377">IsInt</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) IsInt() <a href="../../builtin/index.html#bool">bool</a></pre>
<p>
IsInt reports whether the denominator of x is 1.
</p>
<h3 id="Rat.MarshalText">func (*Rat) <a href="http://localhost:6060/src/math/big/ratmarsh.go?s=1555:1607#L51">MarshalText</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) MarshalText() (text []<a href="../../builtin/index.html#byte">byte</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
MarshalText implements the encoding.TextMarshaler interface.
</p>
<h3 id="Rat.Mul">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=12266:12299#L482">Mul</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) Mul(x, y *<a href="index.html#Rat">Rat</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
Mul sets z to the product x*y and returns z.
</p>
<h3 id="Rat.Neg">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=9005:9035#L342">Neg</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) Neg(x *<a href="index.html#Rat">Rat</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
Neg sets z to -x and returns z.
</p>
<h3 id="Rat.Num">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=9953:9977#L385">Num</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) Num() *<a href="index.html#Int">Int</a></pre>
<p>
Num returns the numerator of x; it may be &lt;= 0.
The result is a reference to x&#39;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.
</p>
<h3 id="Rat.Quo">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=12495:12528#L490">Quo</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) Quo(x, y *<a href="index.html#Rat">Rat</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
Quo sets z to the quotient x/y and returns z.
If y == 0, a division-by-zero run-time panic occurs.
</p>
<h3 id="Rat.RatString">func (*Rat) <a href="http://localhost:6060/src/math/big/ratconv.go?s=4495:4527#L194">RatString</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) RatString() <a href="../../builtin/index.html#string">string</a></pre>
<p>
RatString returns a string representation of x in the form &#34;a/b&#34; if b != 1,
and in the form &#34;a&#34; if b == 1.
</p>
<h3 id="Rat.Scan">func (*Rat) <a href="http://localhost:6060/src/math/big/ratconv.go?s=516:566#L13">Scan</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) Scan(s <a href="../../fmt/index.html">fmt</a>.<a href="../../fmt/index.html#ScanState">ScanState</a>, ch <a href="../../builtin/index.html#rune">rune</a>) <a href="../../builtin/index.html#error">error</a></pre>
<p>
Scan is a support routine for fmt.Scanner. It accepts the formats
&#39;e&#39;, &#39;E&#39;, &#39;f&#39;, &#39;F&#39;, &#39;g&#39;, &#39;G&#39;, and &#39;v&#39;. All formats are equivalent.
</p>
<div id="example_Rat_Scan" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
<p>Code:</p>
<pre class="code"><span class="comment">// The Scan function is rarely used directly;</span>
<span class="comment">// the fmt package recognizes it as an implementation of fmt.Scanner.</span>
r := new(big.Rat)
_, err := fmt.Sscan(&#34;1.5000&#34;, r)
if err != nil {
log.Println(&#34;error scanning value:&#34;, err)
} else {
fmt.Println(r)
}
<span class="comment"></pre>
<p>Output:</p>
<pre class="output">3/2
</pre>
</div>
</div>
<h3 id="Rat.Set">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=8741:8771#L326">Set</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) Set(x *<a href="index.html#Rat">Rat</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
Set sets z to x (by making a copy of x) and returns z.
</p>
<h3 id="Rat.SetFloat64">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=797:837#L20">SetFloat64</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) SetFloat64(f <a href="../../builtin/index.html#float64">float64</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
SetFloat64 sets z to exactly f and returns z.
If f is not finite, SetFloat returns nil.
</p>
<h3 id="Rat.SetFrac">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=7858:7895#L283">SetFrac</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) SetFrac(a, b *<a href="index.html#Int">Int</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
SetFrac sets z to a/b and returns z.
</p>
<h3 id="Rat.SetFrac64">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=8198:8238#L298">SetFrac64</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) SetFrac64(a, b <a href="../../builtin/index.html#int64">int64</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
SetFrac64 sets z to a/b and returns z.
</p>
<h3 id="Rat.SetInt">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=8468:8501#L312">SetInt</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) SetInt(x *<a href="index.html#Int">Int</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
SetInt sets z to x (by making a copy of x) and returns z.
</p>
<h3 id="Rat.SetInt64">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=8591:8627#L319">SetInt64</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) SetInt64(x <a href="../../builtin/index.html#int64">int64</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
SetInt64 sets z to x and returns z.
</p>
<h3 id="Rat.SetString">func (*Rat) <a href="http://localhost:6060/src/math/big/ratconv.go?s=1120:1166#L31">SetString</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) SetString(s <a href="../../builtin/index.html#string">string</a>) (*<a href="index.html#Rat">Rat</a>, <a href="../../builtin/index.html#bool">bool</a>)</pre>
<p>
SetString sets z to the value of s and returns z and a boolean indicating
success. s can be given as a fraction &#34;a/b&#34; or as a floating-point number
optionally followed by an exponent. If the operation failed, the value of
z is undefined but the returned value is nil.
</p>
<div id="example_Rat_SetString" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
<p>Code:</p>
<pre class="code">r := new(big.Rat)
r.SetString(&#34;355/113&#34;)
fmt.Println(r.FloatString(3))
<span class="comment"></pre>
<p>Output:</p>
<pre class="output">3.142
</pre>
</div>
</div>
<h3 id="Rat.Sign">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=9543:9567#L372">Sign</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) Sign() <a href="../../builtin/index.html#int">int</a></pre>
<p>
Sign returns:
</p>
<pre>-1 if x &lt; 0
0 if x == 0
+1 if x &gt; 0
</pre>
<h3 id="Rat.String">func (*Rat) <a href="http://localhost:6060/src/math/big/ratconv.go?s=4170:4199#L180">String</a></h3>
<pre>func (x *<a href="index.html#Rat">Rat</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
<p>
String returns a string representation of x in the form &#34;a/b&#34; (even if b == 1).
</p>
<h3 id="Rat.Sub">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=12032:12065#L473">Sub</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) Sub(x, y *<a href="index.html#Rat">Rat</a>) *<a href="index.html#Rat">Rat</a></pre>
<p>
Sub sets z to the difference x-y and returns z.
</p>
<h3 id="Rat.UnmarshalText">func (*Rat) <a href="http://localhost:6060/src/math/big/ratmarsh.go?s=1771:1817#L57">UnmarshalText</a></h3>
<pre>func (z *<a href="index.html#Rat">Rat</a>) UnmarshalText(text []<a href="../../builtin/index.html#byte">byte</a>) <a href="../../builtin/index.html#error">error</a></pre>
<p>
UnmarshalText implements the encoding.TextUnmarshaler interface.
</p>
<h2 id="RoundingMode">type <a href="http://localhost:6060/src/math/big/float.go?s=4819:4841#L115">RoundingMode</a></h2>
<pre>type RoundingMode <a href="../../builtin/index.html#byte">byte</a></pre>
<p>
RoundingMode determines how a Float value is rounded to the
desired precision. Rounding may change the Float value; the
rounding error is described by the Float&#39;s Accuracy.
</p>
<pre>const (
<span id="ToNearestEven">ToNearestEven</span> <a href="index.html#RoundingMode">RoundingMode</a> = <a href="../../builtin/index.html#iota">iota</a> <span class="comment">// == IEEE 754-2008 roundTiesToEven</span>
<span id="ToNearestAway">ToNearestAway</span> <span class="comment">// == IEEE 754-2008 roundTiesToAway</span>
<span id="ToZero">ToZero</span> <span class="comment">// == IEEE 754-2008 roundTowardZero</span>
<span id="AwayFromZero">AwayFromZero</span> <span class="comment">// no IEEE 754-2008 equivalent</span>
<span id="ToNegativeInf">ToNegativeInf</span> <span class="comment">// == IEEE 754-2008 roundTowardNegative</span>
<span id="ToPositiveInf">ToPositiveInf</span> <span class="comment">// == IEEE 754-2008 roundTowardPositive</span>
)</pre>
<p>
These constants define supported rounding modes.
</p>
<div id="example_RoundingMode" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
<p>Code:</p>
<pre class="code">operands := []float64{2.6, 2.5, 2.1, -2.1, -2.5, -2.6}
fmt.Print(&#34; x&#34;)
for mode := big.ToNearestEven; mode &lt;= big.ToPositiveInf; mode++ {
fmt.Printf(&#34; %s&#34;, mode)
}
fmt.Println()
for _, f64 := range operands {
fmt.Printf(&#34;%4g&#34;, f64)
for mode := big.ToNearestEven; mode &lt;= big.ToPositiveInf; mode++ {
<span class="comment">// sample operands above require 2 bits to represent mantissa</span>
<span class="comment">// set binary precision to 2 to round them to integer values</span>
f := new(big.Float).SetPrec(2).SetMode(mode).SetFloat64(f64)
fmt.Printf(&#34; %*g&#34;, len(mode.String()), f)
}
fmt.Println()
}
<span class="comment"></pre>
<p>Output:</p>
<pre class="output"> x ToNearestEven ToNearestAway ToZero AwayFromZero ToNegativeInf ToPositiveInf
2.6 3 3 2 3 2 3
2.5 2 3 2 3 2 3
2.1 2 2 2 3 2 3
-2.1 -2 -2 -2 -3 -3 -2
-2.5 -2 -3 -2 -3 -3 -2
-2.6 -3 -3 -2 -3 -3 -2
</pre>
</div>
</div>
<h3 id="RoundingMode.String">func (RoundingMode) <a href="http://localhost:6060/src/math/big/roundingmode_string.go?s=251:288#L1">String</a></h3>
<pre>func (i <a href="index.html#RoundingMode">RoundingMode</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
<h2 id="Word">type <a href="http://localhost:6060/src/math/big/arith.go?s=438:455#L2">Word</a></h2>
<pre>type Word <a href="../../builtin/index.html#uintptr">uintptr</a></pre>
<p>
A Word represents a single digit of a multi-precision unsigned integer.
</p>
<h2 id="pkg-note-BUG">Bugs</h2>
<ul style="list-style: none; padding: 0;">
<li><a href="http://localhost:6060/src/math/big/float.go?s=36857:36949#L1408">&#x261e;</a> When rounding ToNegativeInf, the sign of Float values rounded to 0 is incorrect.
</li>
</ul>
<div id="footer">
Build version go1.6.<br>
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
<a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
<a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
</div>
</div><!-- .container -->
</div><!-- #page -->
<!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
<script type="text/javascript" src="../../../lib/godoc/jquery.js"></script>
<script type="text/javascript" src="../../../lib/godoc/jquery.treeview.js"></script>
<script type="text/javascript" src="../../../lib/godoc/jquery.treeview.edit.js"></script>
<script type="text/javascript" src="../../../lib/godoc/godocs.js"></script>
</body>
</html>