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

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>big - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package big</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "math/big"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. <dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd>
  58. </dl>
  59. </div>
  60. <!-- The package's Name is printed as title by the top-level template -->
  61. <div id="pkg-overview" class="toggleVisible">
  62. <div class="collapsed">
  63. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  64. </div>
  65. <div class="expanded">
  66. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  67. <p>
  68. Package big implements arbitrary-precision arithmetic (big numbers).
  69. The following numeric types are supported:
  70. </p>
  71. <pre>Int signed integers
  72. Rat rational numbers
  73. Float floating-point numbers
  74. </pre>
  75. <p>
  76. The zero value for an Int, Rat, or Float correspond to 0. Thus, new
  77. values can be declared in the usual ways and denote 0 without further
  78. initialization:
  79. </p>
  80. <pre>var x Int // &amp;x is an *Int of value 0
  81. var r = &amp;Rat{} // r is a *Rat of value 0
  82. y := new(Float) // y is a *Float of value 0
  83. </pre>
  84. <p>
  85. Alternatively, new values can be allocated and initialized with factory
  86. functions of the form:
  87. </p>
  88. <pre>func NewT(v V) *T
  89. </pre>
  90. <p>
  91. For instance, NewInt(x) returns an *Int set to the value of the int64
  92. argument x, NewRat(a, b) returns a *Rat set to the fraction a/b where
  93. a and b are int64 values, and NewFloat(f) returns a *Float initialized
  94. to the float64 argument f. More flexibility is provided with explicit
  95. setters, for instance:
  96. </p>
  97. <pre>var z1 Int
  98. z1.SetUint64(123) // z1 := 123
  99. z2 := new(Rat).SetFloat64(1.2) // z2 := 6/5
  100. z3 := new(Float).SetInt(z1) // z3 := 123.0
  101. </pre>
  102. <p>
  103. Setters, numeric operations and predicates are represented as methods of
  104. the form:
  105. </p>
  106. <pre>func (z *T) SetV(v V) *T // z = v
  107. func (z *T) Unary(x *T) *T // z = unary x
  108. func (z *T) Binary(x, y *T) *T // z = x binary y
  109. func (x *T) Pred() P // p = pred(x)
  110. </pre>
  111. <p>
  112. with T one of Int, Rat, or Float. For unary and binary operations, the
  113. result is the receiver (usually named z in that case; see below); if it
  114. is one of the operands x or y it may be safely overwritten (and its memory
  115. reused).
  116. </p>
  117. <p>
  118. Arithmetic expressions are typically written as a sequence of individual
  119. method calls, with each call corresponding to an operation. The receiver
  120. denotes the result and the method arguments are the operation&#39;s operands.
  121. For instance, given three *Int values a, b and c, the invocation
  122. </p>
  123. <pre>c.Add(a, b)
  124. </pre>
  125. <p>
  126. computes the sum a + b and stores the result in c, overwriting whatever
  127. value was held in c before. Unless specified otherwise, operations permit
  128. aliasing of parameters, so it is perfectly ok to write
  129. </p>
  130. <pre>sum.Add(sum, x)
  131. </pre>
  132. <p>
  133. to accumulate values x in a sum.
  134. </p>
  135. <p>
  136. (By always passing in a result value via the receiver, memory use can be
  137. much better controlled. Instead of having to allocate new memory for each
  138. result, an operation can reuse the space allocated for the result value,
  139. and overwrite that value with the new result in the process.)
  140. </p>
  141. <p>
  142. Notational convention: Incoming method parameters (including the receiver)
  143. are named consistently in the API to clarify their use. Incoming operands
  144. are usually named x, y, a, b, and so on, but never z. A parameter specifying
  145. the result is named z (typically the receiver).
  146. </p>
  147. <p>
  148. For instance, the arguments for (*Int).Add are named x and y, and because
  149. the receiver specifies the result destination, it is called z:
  150. </p>
  151. <pre>func (z *Int) Add(x, y *Int) *Int
  152. </pre>
  153. <p>
  154. Methods of this form typically return the incoming receiver as well, to
  155. enable simple call chaining.
  156. </p>
  157. <p>
  158. Methods which don&#39;t require a result value to be passed in (for instance,
  159. Int.Sign), simply return the result. In this case, the receiver is typically
  160. the first operand, named x:
  161. </p>
  162. <pre>func (x *Int) Sign() int
  163. </pre>
  164. <p>
  165. Various methods support conversions between strings and corresponding
  166. numeric values, and vice versa: *Int, *Rat, and *Float values implement
  167. the Stringer interface for a (default) string representation of the value,
  168. but also provide SetString methods to initialize a value from a string in
  169. a variety of supported formats (see the respective SetString documentation).
  170. </p>
  171. <p>
  172. Finally, *Int, *Rat, and *Float satisfy the fmt package&#39;s Scanner interface
  173. for scanning and (except for *Rat) the Formatter interface for formatted
  174. printing.
  175. </p>
  176. </div>
  177. </div>
  178. <div id="example__eConvergents" class="toggle">
  179. <div class="collapsed">
  180. <p class="exampleHeading toggleButton"><span class="text">Example (EConvergents)</span></p>
  181. </div>
  182. <div class="expanded">
  183. <p class="exampleHeading toggleButton"><span class="text">Example (EConvergents)</span></p>
  184. <p>This example demonstrates how to use big.Rat to compute the
  185. first 15 terms in the sequence of rational convergents for
  186. the constant e (base of natural logarithm).
  187. </p>
  188. <p>Code:</p>
  189. <pre class="code">package big_test
  190. import (
  191. &#34;fmt&#34;
  192. &#34;math/big&#34;
  193. )
  194. <span class="comment">// Use the classic continued fraction for e</span>
  195. <span class="comment">// e = [1; 0, 1, 1, 2, 1, 1, ... 2n, 1, 1, ...]</span>
  196. <span class="comment">// i.e., for the nth term, use</span>
  197. <span class="comment">// 1 if n mod 3 != 1</span>
  198. <span class="comment">// (n-1)/3 * 2 if n mod 3 == 1</span>
  199. func recur(n, lim int64) *big.Rat {
  200. term := new(big.Rat)
  201. if n%3 != 1 {
  202. term.SetInt64(1)
  203. } else {
  204. term.SetInt64((n - 1) / 3 * 2)
  205. }
  206. if n &gt; lim {
  207. return term
  208. }
  209. <span class="comment">// Directly initialize frac as the fractional</span>
  210. <span class="comment">// inverse of the result of recur.</span>
  211. frac := new(big.Rat).Inv(recur(n+1, lim))
  212. return term.Add(term, frac)
  213. }
  214. <span class="comment">// This example demonstrates how to use big.Rat to compute the</span>
  215. <span class="comment">// first 15 terms in the sequence of rational convergents for</span>
  216. <span class="comment">// the constant e (base of natural logarithm).</span>
  217. func Example_eConvergents() {
  218. for i := 1; i &lt;= 15; i++ {
  219. r := recur(0, int64(i))
  220. <span class="comment">// Print r both as a fraction and as a floating-point number.</span>
  221. <span class="comment">// Since big.Rat implements fmt.Formatter, we can use %-13s to</span>
  222. <span class="comment">// get a left-aligned string representation of the fraction.</span>
  223. fmt.Printf(&#34;%-13s = %s\n&#34;, r, r.FloatString(8))
  224. }
  225. <span class="comment">// Output:</span>
  226. <span class="comment">// 2/1 = 2.00000000</span>
  227. <span class="comment">// 3/1 = 3.00000000</span>
  228. <span class="comment">// 8/3 = 2.66666667</span>
  229. <span class="comment">// 11/4 = 2.75000000</span>
  230. <span class="comment">// 19/7 = 2.71428571</span>
  231. <span class="comment">// 87/32 = 2.71875000</span>
  232. <span class="comment">// 106/39 = 2.71794872</span>
  233. <span class="comment">// 193/71 = 2.71830986</span>
  234. <span class="comment">// 1264/465 = 2.71827957</span>
  235. <span class="comment">// 1457/536 = 2.71828358</span>
  236. <span class="comment">// 2721/1001 = 2.71828172</span>
  237. <span class="comment">// 23225/8544 = 2.71828184</span>
  238. <span class="comment">// 25946/9545 = 2.71828182</span>
  239. <span class="comment">// 49171/18089 = 2.71828183</span>
  240. <span class="comment">// 517656/190435 = 2.71828183</span>
  241. }
  242. </pre>
  243. </div>
  244. </div>
  245. <div id="example__fibonacci" class="toggle">
  246. <div class="collapsed">
  247. <p class="exampleHeading toggleButton"><span class="text">Example (Fibonacci)</span></p>
  248. </div>
  249. <div class="expanded">
  250. <p class="exampleHeading toggleButton"><span class="text">Example (Fibonacci)</span></p>
  251. <p>This example demonstrates how to use big.Int to compute the smallest
  252. Fibonacci number with 100 decimal digits and to test whether it is prime.
  253. </p>
  254. <p>Code:</p>
  255. <pre class="code"><span class="comment">// Initialize two big ints with the first two numbers in the sequence.</span>
  256. a := big.NewInt(0)
  257. b := big.NewInt(1)
  258. <span class="comment">// Initialize limit as 10^99, the smallest integer with 100 digits.</span>
  259. var limit big.Int
  260. limit.Exp(big.NewInt(10), big.NewInt(99), nil)
  261. <span class="comment">// Loop while a is smaller than 1e100.</span>
  262. for a.Cmp(&amp;limit) &lt; 0 {
  263. <span class="comment">// Compute the next Fibonacci number, storing it in a.</span>
  264. a.Add(a, b)
  265. <span class="comment">// Swap a and b so that b is the next number in the sequence.</span>
  266. a, b = b, a
  267. }
  268. fmt.Println(a) <span class="comment">// 100-digit Fibonacci number</span>
  269. <span class="comment">// Test a for primality.</span>
  270. <span class="comment">// (ProbablyPrimes&#39; argument sets the number of Miller-Rabin</span>
  271. <span class="comment">// rounds to be performed. 20 is a good value.)</span>
  272. fmt.Println(a.ProbablyPrime(20))
  273. <span class="comment"></pre>
  274. <p>Output:</p>
  275. <pre class="output">1344719667586153181419716641724567886890850696275767987106294472017884974410332069524504824747437757
  276. false
  277. </pre>
  278. </div>
  279. </div>
  280. <div id="example__sqrt2" class="toggle">
  281. <div class="collapsed">
  282. <p class="exampleHeading toggleButton"><span class="text">Example (Sqrt2)</span></p>
  283. </div>
  284. <div class="expanded">
  285. <p class="exampleHeading toggleButton"><span class="text">Example (Sqrt2)</span></p>
  286. <p>This example shows how to use big.Float to compute the square root of 2 with
  287. a precision of 200 bits, and how to print the result as a decimal number.
  288. </p>
  289. <p>Code:</p>
  290. <pre class="code"><span class="comment">// We&#39;ll do computations with 200 bits of precision in the mantissa.</span>
  291. const prec = 200
  292. <span class="comment">// Compute the square root of 2 using Newton&#39;s Method. We start with</span>
  293. <span class="comment">// an initial estimate for sqrt(2), and then iterate:</span>
  294. <span class="comment">// x_{n+1} = 1/2 * ( x_n + (2.0 / x_n) )</span>
  295. <span class="comment">// Since Newton&#39;s Method doubles the number of correct digits at each</span>
  296. <span class="comment">// iteration, we need at least log_2(prec) steps.</span>
  297. steps := int(math.Log2(prec))
  298. <span class="comment">// Initialize values we need for the computation.</span>
  299. two := new(big.Float).SetPrec(prec).SetInt64(2)
  300. half := new(big.Float).SetPrec(prec).SetFloat64(0.5)
  301. <span class="comment">// Use 1 as the initial estimate.</span>
  302. x := new(big.Float).SetPrec(prec).SetInt64(1)
  303. <span class="comment">// We use t as a temporary variable. There&#39;s no need to set its precision</span>
  304. <span class="comment">// since big.Float values with unset (== 0) precision automatically assume</span>
  305. <span class="comment">// the largest precision of the arguments when used as the result (receiver)</span>
  306. <span class="comment">// of a big.Float operation.</span>
  307. t := new(big.Float)
  308. <span class="comment">// Iterate.</span>
  309. for i := 0; i &lt;= steps; i++ {
  310. t.Quo(two, x) <span class="comment">// t = 2.0 / x_n</span>
  311. t.Add(x, t) <span class="comment">// t = x_n + (2.0 / x_n)</span>
  312. x.Mul(half, t) <span class="comment">// x_{n+1} = 0.5 * t</span>
  313. }
  314. <span class="comment">// We can use the usual fmt.Printf verbs since big.Float implements fmt.Formatter</span>
  315. fmt.Printf(&#34;sqrt(2) = %.50f\n&#34;, x)
  316. <span class="comment">// Print the error between 2 and x*x.</span>
  317. t.Mul(x, x) <span class="comment">// t = x*x</span>
  318. fmt.Printf(&#34;error = %e\n&#34;, t.Sub(two, t))
  319. <span class="comment"></pre>
  320. <p>Output:</p>
  321. <pre class="output">sqrt(2) = 1.41421356237309504880168872420969807856967187537695
  322. error = 0.000000e+00
  323. </pre>
  324. </div>
  325. </div>
  326. <div id="pkg-index" class="toggleVisible">
  327. <div class="collapsed">
  328. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  329. </div>
  330. <div class="expanded">
  331. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  332. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  333. <div id="manual-nav">
  334. <dl>
  335. <dd><a href="index.html#pkg-constants">Constants</a></dd>
  336. <dd><a href="index.html#Jacobi">func Jacobi(x, y *Int) int</a></dd>
  337. <dd><a href="index.html#Accuracy">type Accuracy</a></dd>
  338. <dd>&nbsp; &nbsp; <a href="index.html#Accuracy.String">func (i Accuracy) String() string</a></dd>
  339. <dd><a href="index.html#ErrNaN">type ErrNaN</a></dd>
  340. <dd>&nbsp; &nbsp; <a href="index.html#ErrNaN.Error">func (err ErrNaN) Error() string</a></dd>
  341. <dd><a href="index.html#Float">type Float</a></dd>
  342. <dd>&nbsp; &nbsp; <a href="index.html#NewFloat">func NewFloat(x float64) *Float</a></dd>
  343. <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>
  344. <dd>&nbsp; &nbsp; <a href="index.html#Float.Abs">func (z *Float) Abs(x *Float) *Float</a></dd>
  345. <dd>&nbsp; &nbsp; <a href="index.html#Float.Acc">func (x *Float) Acc() Accuracy</a></dd>
  346. <dd>&nbsp; &nbsp; <a href="index.html#Float.Add">func (z *Float) Add(x, y *Float) *Float</a></dd>
  347. <dd>&nbsp; &nbsp; <a href="index.html#Float.Append">func (x *Float) Append(buf []byte, fmt byte, prec int) []byte</a></dd>
  348. <dd>&nbsp; &nbsp; <a href="index.html#Float.Cmp">func (x *Float) Cmp(y *Float) int</a></dd>
  349. <dd>&nbsp; &nbsp; <a href="index.html#Float.Copy">func (z *Float) Copy(x *Float) *Float</a></dd>
  350. <dd>&nbsp; &nbsp; <a href="index.html#Float.Float32">func (x *Float) Float32() (float32, Accuracy)</a></dd>
  351. <dd>&nbsp; &nbsp; <a href="index.html#Float.Float64">func (x *Float) Float64() (float64, Accuracy)</a></dd>
  352. <dd>&nbsp; &nbsp; <a href="index.html#Float.Format">func (x *Float) Format(s fmt.State, format rune)</a></dd>
  353. <dd>&nbsp; &nbsp; <a href="index.html#Float.Int">func (x *Float) Int(z *Int) (*Int, Accuracy)</a></dd>
  354. <dd>&nbsp; &nbsp; <a href="index.html#Float.Int64">func (x *Float) Int64() (int64, Accuracy)</a></dd>
  355. <dd>&nbsp; &nbsp; <a href="index.html#Float.IsInf">func (x *Float) IsInf() bool</a></dd>
  356. <dd>&nbsp; &nbsp; <a href="index.html#Float.IsInt">func (x *Float) IsInt() bool</a></dd>
  357. <dd>&nbsp; &nbsp; <a href="index.html#Float.MantExp">func (x *Float) MantExp(mant *Float) (exp int)</a></dd>
  358. <dd>&nbsp; &nbsp; <a href="index.html#Float.MarshalText">func (x *Float) MarshalText() (text []byte, err error)</a></dd>
  359. <dd>&nbsp; &nbsp; <a href="index.html#Float.MinPrec">func (x *Float) MinPrec() uint</a></dd>
  360. <dd>&nbsp; &nbsp; <a href="index.html#Float.Mode">func (x *Float) Mode() RoundingMode</a></dd>
  361. <dd>&nbsp; &nbsp; <a href="index.html#Float.Mul">func (z *Float) Mul(x, y *Float) *Float</a></dd>
  362. <dd>&nbsp; &nbsp; <a href="index.html#Float.Neg">func (z *Float) Neg(x *Float) *Float</a></dd>
  363. <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>
  364. <dd>&nbsp; &nbsp; <a href="index.html#Float.Prec">func (x *Float) Prec() uint</a></dd>
  365. <dd>&nbsp; &nbsp; <a href="index.html#Float.Quo">func (z *Float) Quo(x, y *Float) *Float</a></dd>
  366. <dd>&nbsp; &nbsp; <a href="index.html#Float.Rat">func (x *Float) Rat(z *Rat) (*Rat, Accuracy)</a></dd>
  367. <dd>&nbsp; &nbsp; <a href="index.html#Float.Set">func (z *Float) Set(x *Float) *Float</a></dd>
  368. <dd>&nbsp; &nbsp; <a href="index.html#Float.SetFloat64">func (z *Float) SetFloat64(x float64) *Float</a></dd>
  369. <dd>&nbsp; &nbsp; <a href="index.html#Float.SetInf">func (z *Float) SetInf(signbit bool) *Float</a></dd>
  370. <dd>&nbsp; &nbsp; <a href="index.html#Float.SetInt">func (z *Float) SetInt(x *Int) *Float</a></dd>
  371. <dd>&nbsp; &nbsp; <a href="index.html#Float.SetInt64">func (z *Float) SetInt64(x int64) *Float</a></dd>
  372. <dd>&nbsp; &nbsp; <a href="index.html#Float.SetMantExp">func (z *Float) SetMantExp(mant *Float, exp int) *Float</a></dd>
  373. <dd>&nbsp; &nbsp; <a href="index.html#Float.SetMode">func (z *Float) SetMode(mode RoundingMode) *Float</a></dd>
  374. <dd>&nbsp; &nbsp; <a href="index.html#Float.SetPrec">func (z *Float) SetPrec(prec uint) *Float</a></dd>
  375. <dd>&nbsp; &nbsp; <a href="index.html#Float.SetRat">func (z *Float) SetRat(x *Rat) *Float</a></dd>
  376. <dd>&nbsp; &nbsp; <a href="index.html#Float.SetString">func (z *Float) SetString(s string) (*Float, bool)</a></dd>
  377. <dd>&nbsp; &nbsp; <a href="index.html#Float.SetUint64">func (z *Float) SetUint64(x uint64) *Float</a></dd>
  378. <dd>&nbsp; &nbsp; <a href="index.html#Float.Sign">func (x *Float) Sign() int</a></dd>
  379. <dd>&nbsp; &nbsp; <a href="index.html#Float.Signbit">func (x *Float) Signbit() bool</a></dd>
  380. <dd>&nbsp; &nbsp; <a href="index.html#Float.String">func (x *Float) String() string</a></dd>
  381. <dd>&nbsp; &nbsp; <a href="index.html#Float.Sub">func (z *Float) Sub(x, y *Float) *Float</a></dd>
  382. <dd>&nbsp; &nbsp; <a href="index.html#Float.Text">func (x *Float) Text(format byte, prec int) string</a></dd>
  383. <dd>&nbsp; &nbsp; <a href="index.html#Float.Uint64">func (x *Float) Uint64() (uint64, Accuracy)</a></dd>
  384. <dd>&nbsp; &nbsp; <a href="index.html#Float.UnmarshalText">func (z *Float) UnmarshalText(text []byte) error</a></dd>
  385. <dd><a href="index.html#Int">type Int</a></dd>
  386. <dd>&nbsp; &nbsp; <a href="index.html#NewInt">func NewInt(x int64) *Int</a></dd>
  387. <dd>&nbsp; &nbsp; <a href="index.html#Int.Abs">func (z *Int) Abs(x *Int) *Int</a></dd>
  388. <dd>&nbsp; &nbsp; <a href="index.html#Int.Add">func (z *Int) Add(x, y *Int) *Int</a></dd>
  389. <dd>&nbsp; &nbsp; <a href="index.html#Int.And">func (z *Int) And(x, y *Int) *Int</a></dd>
  390. <dd>&nbsp; &nbsp; <a href="index.html#Int.AndNot">func (z *Int) AndNot(x, y *Int) *Int</a></dd>
  391. <dd>&nbsp; &nbsp; <a href="index.html#Int.Append">func (x *Int) Append(buf []byte, base int) []byte</a></dd>
  392. <dd>&nbsp; &nbsp; <a href="index.html#Int.Binomial">func (z *Int) Binomial(n, k int64) *Int</a></dd>
  393. <dd>&nbsp; &nbsp; <a href="index.html#Int.Bit">func (x *Int) Bit(i int) uint</a></dd>
  394. <dd>&nbsp; &nbsp; <a href="index.html#Int.BitLen">func (x *Int) BitLen() int</a></dd>
  395. <dd>&nbsp; &nbsp; <a href="index.html#Int.Bits">func (x *Int) Bits() []Word</a></dd>
  396. <dd>&nbsp; &nbsp; <a href="index.html#Int.Bytes">func (x *Int) Bytes() []byte</a></dd>
  397. <dd>&nbsp; &nbsp; <a href="index.html#Int.Cmp">func (x *Int) Cmp(y *Int) (r int)</a></dd>
  398. <dd>&nbsp; &nbsp; <a href="index.html#Int.Div">func (z *Int) Div(x, y *Int) *Int</a></dd>
  399. <dd>&nbsp; &nbsp; <a href="index.html#Int.DivMod">func (z *Int) DivMod(x, y, m *Int) (*Int, *Int)</a></dd>
  400. <dd>&nbsp; &nbsp; <a href="index.html#Int.Exp">func (z *Int) Exp(x, y, m *Int) *Int</a></dd>
  401. <dd>&nbsp; &nbsp; <a href="index.html#Int.Format">func (x *Int) Format(s fmt.State, ch rune)</a></dd>
  402. <dd>&nbsp; &nbsp; <a href="index.html#Int.GCD">func (z *Int) GCD(x, y, a, b *Int) *Int</a></dd>
  403. <dd>&nbsp; &nbsp; <a href="index.html#Int.GobDecode">func (z *Int) GobDecode(buf []byte) error</a></dd>
  404. <dd>&nbsp; &nbsp; <a href="index.html#Int.GobEncode">func (x *Int) GobEncode() ([]byte, error)</a></dd>
  405. <dd>&nbsp; &nbsp; <a href="index.html#Int.Int64">func (x *Int) Int64() int64</a></dd>
  406. <dd>&nbsp; &nbsp; <a href="index.html#Int.Lsh">func (z *Int) Lsh(x *Int, n uint) *Int</a></dd>
  407. <dd>&nbsp; &nbsp; <a href="index.html#Int.MarshalJSON">func (x *Int) MarshalJSON() ([]byte, error)</a></dd>
  408. <dd>&nbsp; &nbsp; <a href="index.html#Int.MarshalText">func (x *Int) MarshalText() (text []byte, err error)</a></dd>
  409. <dd>&nbsp; &nbsp; <a href="index.html#Int.Mod">func (z *Int) Mod(x, y *Int) *Int</a></dd>
  410. <dd>&nbsp; &nbsp; <a href="index.html#Int.ModInverse">func (z *Int) ModInverse(g, n *Int) *Int</a></dd>
  411. <dd>&nbsp; &nbsp; <a href="index.html#Int.ModSqrt">func (z *Int) ModSqrt(x, p *Int) *Int</a></dd>
  412. <dd>&nbsp; &nbsp; <a href="index.html#Int.Mul">func (z *Int) Mul(x, y *Int) *Int</a></dd>
  413. <dd>&nbsp; &nbsp; <a href="index.html#Int.MulRange">func (z *Int) MulRange(a, b int64) *Int</a></dd>
  414. <dd>&nbsp; &nbsp; <a href="index.html#Int.Neg">func (z *Int) Neg(x *Int) *Int</a></dd>
  415. <dd>&nbsp; &nbsp; <a href="index.html#Int.Not">func (z *Int) Not(x *Int) *Int</a></dd>
  416. <dd>&nbsp; &nbsp; <a href="index.html#Int.Or">func (z *Int) Or(x, y *Int) *Int</a></dd>
  417. <dd>&nbsp; &nbsp; <a href="index.html#Int.ProbablyPrime">func (x *Int) ProbablyPrime(n int) bool</a></dd>
  418. <dd>&nbsp; &nbsp; <a href="index.html#Int.Quo">func (z *Int) Quo(x, y *Int) *Int</a></dd>
  419. <dd>&nbsp; &nbsp; <a href="index.html#Int.QuoRem">func (z *Int) QuoRem(x, y, r *Int) (*Int, *Int)</a></dd>
  420. <dd>&nbsp; &nbsp; <a href="index.html#Int.Rand">func (z *Int) Rand(rnd *rand.Rand, n *Int) *Int</a></dd>
  421. <dd>&nbsp; &nbsp; <a href="index.html#Int.Rem">func (z *Int) Rem(x, y *Int) *Int</a></dd>
  422. <dd>&nbsp; &nbsp; <a href="index.html#Int.Rsh">func (z *Int) Rsh(x *Int, n uint) *Int</a></dd>
  423. <dd>&nbsp; &nbsp; <a href="index.html#Int.Scan">func (z *Int) Scan(s fmt.ScanState, ch rune) error</a></dd>
  424. <dd>&nbsp; &nbsp; <a href="index.html#Int.Set">func (z *Int) Set(x *Int) *Int</a></dd>
  425. <dd>&nbsp; &nbsp; <a href="index.html#Int.SetBit">func (z *Int) SetBit(x *Int, i int, b uint) *Int</a></dd>
  426. <dd>&nbsp; &nbsp; <a href="index.html#Int.SetBits">func (z *Int) SetBits(abs []Word) *Int</a></dd>
  427. <dd>&nbsp; &nbsp; <a href="index.html#Int.SetBytes">func (z *Int) SetBytes(buf []byte) *Int</a></dd>
  428. <dd>&nbsp; &nbsp; <a href="index.html#Int.SetInt64">func (z *Int) SetInt64(x int64) *Int</a></dd>
  429. <dd>&nbsp; &nbsp; <a href="index.html#Int.SetString">func (z *Int) SetString(s string, base int) (*Int, bool)</a></dd>
  430. <dd>&nbsp; &nbsp; <a href="index.html#Int.SetUint64">func (z *Int) SetUint64(x uint64) *Int</a></dd>
  431. <dd>&nbsp; &nbsp; <a href="index.html#Int.Sign">func (x *Int) Sign() int</a></dd>
  432. <dd>&nbsp; &nbsp; <a href="index.html#Int.String">func (x *Int) String() string</a></dd>
  433. <dd>&nbsp; &nbsp; <a href="index.html#Int.Sub">func (z *Int) Sub(x, y *Int) *Int</a></dd>
  434. <dd>&nbsp; &nbsp; <a href="index.html#Int.Text">func (x *Int) Text(base int) string</a></dd>
  435. <dd>&nbsp; &nbsp; <a href="index.html#Int.Uint64">func (x *Int) Uint64() uint64</a></dd>
  436. <dd>&nbsp; &nbsp; <a href="index.html#Int.UnmarshalJSON">func (z *Int) UnmarshalJSON(text []byte) error</a></dd>
  437. <dd>&nbsp; &nbsp; <a href="index.html#Int.UnmarshalText">func (z *Int) UnmarshalText(text []byte) error</a></dd>
  438. <dd>&nbsp; &nbsp; <a href="index.html#Int.Xor">func (z *Int) Xor(x, y *Int) *Int</a></dd>
  439. <dd><a href="index.html#Rat">type Rat</a></dd>
  440. <dd>&nbsp; &nbsp; <a href="index.html#NewRat">func NewRat(a, b int64) *Rat</a></dd>
  441. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Abs">func (z *Rat) Abs(x *Rat) *Rat</a></dd>
  442. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Add">func (z *Rat) Add(x, y *Rat) *Rat</a></dd>
  443. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Cmp">func (x *Rat) Cmp(y *Rat) int</a></dd>
  444. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Denom">func (x *Rat) Denom() *Int</a></dd>
  445. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Float32">func (x *Rat) Float32() (f float32, exact bool)</a></dd>
  446. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Float64">func (x *Rat) Float64() (f float64, exact bool)</a></dd>
  447. <dd>&nbsp; &nbsp; <a href="index.html#Rat.FloatString">func (x *Rat) FloatString(prec int) string</a></dd>
  448. <dd>&nbsp; &nbsp; <a href="index.html#Rat.GobDecode">func (z *Rat) GobDecode(buf []byte) error</a></dd>
  449. <dd>&nbsp; &nbsp; <a href="index.html#Rat.GobEncode">func (x *Rat) GobEncode() ([]byte, error)</a></dd>
  450. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Inv">func (z *Rat) Inv(x *Rat) *Rat</a></dd>
  451. <dd>&nbsp; &nbsp; <a href="index.html#Rat.IsInt">func (x *Rat) IsInt() bool</a></dd>
  452. <dd>&nbsp; &nbsp; <a href="index.html#Rat.MarshalText">func (x *Rat) MarshalText() (text []byte, err error)</a></dd>
  453. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Mul">func (z *Rat) Mul(x, y *Rat) *Rat</a></dd>
  454. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Neg">func (z *Rat) Neg(x *Rat) *Rat</a></dd>
  455. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Num">func (x *Rat) Num() *Int</a></dd>
  456. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Quo">func (z *Rat) Quo(x, y *Rat) *Rat</a></dd>
  457. <dd>&nbsp; &nbsp; <a href="index.html#Rat.RatString">func (x *Rat) RatString() string</a></dd>
  458. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Scan">func (z *Rat) Scan(s fmt.ScanState, ch rune) error</a></dd>
  459. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Set">func (z *Rat) Set(x *Rat) *Rat</a></dd>
  460. <dd>&nbsp; &nbsp; <a href="index.html#Rat.SetFloat64">func (z *Rat) SetFloat64(f float64) *Rat</a></dd>
  461. <dd>&nbsp; &nbsp; <a href="index.html#Rat.SetFrac">func (z *Rat) SetFrac(a, b *Int) *Rat</a></dd>
  462. <dd>&nbsp; &nbsp; <a href="index.html#Rat.SetFrac64">func (z *Rat) SetFrac64(a, b int64) *Rat</a></dd>
  463. <dd>&nbsp; &nbsp; <a href="index.html#Rat.SetInt">func (z *Rat) SetInt(x *Int) *Rat</a></dd>
  464. <dd>&nbsp; &nbsp; <a href="index.html#Rat.SetInt64">func (z *Rat) SetInt64(x int64) *Rat</a></dd>
  465. <dd>&nbsp; &nbsp; <a href="index.html#Rat.SetString">func (z *Rat) SetString(s string) (*Rat, bool)</a></dd>
  466. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Sign">func (x *Rat) Sign() int</a></dd>
  467. <dd>&nbsp; &nbsp; <a href="index.html#Rat.String">func (x *Rat) String() string</a></dd>
  468. <dd>&nbsp; &nbsp; <a href="index.html#Rat.Sub">func (z *Rat) Sub(x, y *Rat) *Rat</a></dd>
  469. <dd>&nbsp; &nbsp; <a href="index.html#Rat.UnmarshalText">func (z *Rat) UnmarshalText(text []byte) error</a></dd>
  470. <dd><a href="index.html#RoundingMode">type RoundingMode</a></dd>
  471. <dd>&nbsp; &nbsp; <a href="index.html#RoundingMode.String">func (i RoundingMode) String() string</a></dd>
  472. <dd><a href="index.html#Word">type Word</a></dd>
  473. <dd><a href="index.html#pkg-note-BUG">Bugs</a></dd>
  474. </dl>
  475. </div><!-- #manual-nav -->
  476. <div id="pkg-examples">
  477. <h4>Examples</h4>
  478. <dl>
  479. <dd><a class="exampleLink" href="index.html#example_Float_Add">Float.Add</a></dd>
  480. <dd><a class="exampleLink" href="index.html#example_Float_Cmp">Float.Cmp</a></dd>
  481. <dd><a class="exampleLink" href="index.html#example_Int_Scan">Int.Scan</a></dd>
  482. <dd><a class="exampleLink" href="index.html#example_Int_SetString">Int.SetString</a></dd>
  483. <dd><a class="exampleLink" href="index.html#example_Rat_Scan">Rat.Scan</a></dd>
  484. <dd><a class="exampleLink" href="index.html#example_Rat_SetString">Rat.SetString</a></dd>
  485. <dd><a class="exampleLink" href="index.html#example_RoundingMode">RoundingMode</a></dd>
  486. <dd><a class="exampleLink" href="index.html#example__eConvergents">Package (EConvergents)</a></dd>
  487. <dd><a class="exampleLink" href="index.html#example__fibonacci">Package (Fibonacci)</a></dd>
  488. <dd><a class="exampleLink" href="index.html#example__sqrt2">Package (Sqrt2)</a></dd>
  489. </dl>
  490. </div>
  491. <h4>Package files</h4>
  492. <p>
  493. <span style="font-size:90%">
  494. <a href="http://localhost:6060/src/math/big/accuracy_string.go">accuracy_string.go</a>
  495. <a href="http://localhost:6060/src/math/big/arith.go">arith.go</a>
  496. <a href="http://localhost:6060/src/math/big/arith_decl.go">arith_decl.go</a>
  497. <a href="http://localhost:6060/src/math/big/decimal.go">decimal.go</a>
  498. <a href="http://localhost:6060/src/math/big/doc.go">doc.go</a>
  499. <a href="http://localhost:6060/src/math/big/float.go">float.go</a>
  500. <a href="http://localhost:6060/src/math/big/floatconv.go">floatconv.go</a>
  501. <a href="http://localhost:6060/src/math/big/floatmarsh.go">floatmarsh.go</a>
  502. <a href="http://localhost:6060/src/math/big/ftoa.go">ftoa.go</a>
  503. <a href="http://localhost:6060/src/math/big/int.go">int.go</a>
  504. <a href="http://localhost:6060/src/math/big/intconv.go">intconv.go</a>
  505. <a href="http://localhost:6060/src/math/big/intmarsh.go">intmarsh.go</a>
  506. <a href="http://localhost:6060/src/math/big/nat.go">nat.go</a>
  507. <a href="http://localhost:6060/src/math/big/natconv.go">natconv.go</a>
  508. <a href="http://localhost:6060/src/math/big/rat.go">rat.go</a>
  509. <a href="http://localhost:6060/src/math/big/ratconv.go">ratconv.go</a>
  510. <a href="http://localhost:6060/src/math/big/ratmarsh.go">ratmarsh.go</a>
  511. <a href="http://localhost:6060/src/math/big/roundingmode_string.go">roundingmode_string.go</a>
  512. </span>
  513. </p>
  514. </div><!-- .expanded -->
  515. </div><!-- #pkg-index -->
  516. <div id="pkg-callgraph" class="toggle" style="display: none">
  517. <div class="collapsed">
  518. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  519. </div> <!-- .expanded -->
  520. <div class="expanded">
  521. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  522. <p>
  523. In the call graph viewer below, each node
  524. is a function belonging to this package
  525. and its children are the functions it
  526. calls&mdash;perhaps dynamically.
  527. </p>
  528. <p>
  529. The root nodes are the entry points of the
  530. package: functions that may be called from
  531. outside the package.
  532. There may be non-exported or anonymous
  533. functions among them if they are called
  534. dynamically from another package.
  535. </p>
  536. <p>
  537. Click a node to visit that function's source code.
  538. From there you can visit its callers by
  539. clicking its declaring <code>func</code>
  540. token.
  541. </p>
  542. <p>
  543. Functions may be omitted if they were
  544. determined to be unreachable in the
  545. particular programs or tests that were
  546. analyzed.
  547. </p>
  548. <!-- Zero means show all package entry points. -->
  549. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  550. </div>
  551. </div> <!-- #pkg-callgraph -->
  552. <h2 id="pkg-constants">Constants</h2>
  553. <pre>const (
  554. <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>
  555. <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>
  556. <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>
  557. )</pre>
  558. <p>
  559. Exponent and precision limits.
  560. </p>
  561. <pre>const <span id="MaxBase">MaxBase</span> = &#39;z&#39; - &#39;a&#39; + 10 + 1</pre>
  562. <p>
  563. MaxBase is the largest number base accepted for string conversions.
  564. </p>
  565. <h2 id="Jacobi">func <a href="http://localhost:6060/src/math/big/int.go?s=13910:13936#L583">Jacobi</a></h2>
  566. <pre>func Jacobi(x, y *<a href="index.html#Int">Int</a>) <a href="../../builtin/index.html#int">int</a></pre>
  567. <p>
  568. Jacobi returns the Jacobi symbol (x/y), either +1, -1, or 0.
  569. The y argument must be an odd integer.
  570. </p>
  571. <h2 id="Accuracy">type <a href="http://localhost:6060/src/math/big/float.go?s=5519:5537#L131">Accuracy</a></h2>
  572. <pre>type Accuracy <a href="../../builtin/index.html#int8">int8</a></pre>
  573. <p>
  574. Accuracy describes the rounding error produced by the most recent
  575. operation that generated a Float value, relative to the exact value.
  576. </p>
  577. <pre>const (
  578. <span id="Below">Below</span> <a href="index.html#Accuracy">Accuracy</a> = -1
  579. <span id="Exact">Exact</span> <a href="index.html#Accuracy">Accuracy</a> = 0
  580. <span id="Above">Above</span> <a href="index.html#Accuracy">Accuracy</a> = +1
  581. )</pre>
  582. <p>
  583. Constants describing the Accuracy of a Float.
  584. </p>
  585. <h3 id="Accuracy.String">func (Accuracy) <a href="http://localhost:6060/src/math/big/accuracy_string.go?s=171:204#L1">String</a></h3>
  586. <pre>func (i <a href="index.html#Accuracy">Accuracy</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
  587. <h2 id="ErrNaN">type <a href="http://localhost:6060/src/math/big/float.go?s=2893:2927#L60">ErrNaN</a></h2>
  588. <pre>type ErrNaN struct {
  589. <span class="comment">// contains filtered or unexported fields</span>
  590. }</pre>
  591. <p>
  592. An ErrNaN panic is raised by a Float operation that would lead to
  593. a NaN under IEEE-754 rules. An ErrNaN implements the error interface.
  594. </p>
  595. <h3 id="ErrNaN.Error">func (ErrNaN) <a href="http://localhost:6060/src/math/big/float.go?s=2929:2961#L64">Error</a></h3>
  596. <pre>func (err <a href="index.html#ErrNaN">ErrNaN</a>) Error() <a href="../../builtin/index.html#string">string</a></pre>
  597. <h2 id="Float">type <a href="http://localhost:6060/src/math/big/float.go?s=2637:2749#L48">Float</a></h2>
  598. <pre>type Float struct {
  599. <span class="comment">// contains filtered or unexported fields</span>
  600. }</pre>
  601. <p>
  602. A nonzero finite Float represents a multi-precision floating point number
  603. </p>
  604. <pre>sign × mantissa × 2**exponent
  605. </pre>
  606. <p>
  607. with 0.5 &lt;= mantissa &lt; 1.0, and MinExp &lt;= exponent &lt;= MaxExp.
  608. A Float may also be zero (+0, -0) or infinite (+Inf, -Inf).
  609. All Floats are ordered, and the ordering of two Floats x and y
  610. is defined by x.Cmp(y).
  611. </p>
  612. <p>
  613. Each Float value also has a precision, rounding mode, and accuracy.
  614. The precision is the maximum number of mantissa bits available to
  615. represent the value. The rounding mode specifies how a result should
  616. be rounded to fit into the mantissa bits, and accuracy describes the
  617. rounding error with respect to the exact result.
  618. </p>
  619. <p>
  620. Unless specified otherwise, all operations (including setters) that
  621. specify a *Float variable for the result (usually via the receiver
  622. with the exception of MantExp), round the numeric result according
  623. to the precision and rounding mode of the result variable.
  624. </p>
  625. <p>
  626. If the provided result precision is 0 (see below), it is set to the
  627. precision of the argument with the largest precision value before any
  628. rounding takes place, and the rounding mode remains unchanged. Thus,
  629. uninitialized Floats provided as result arguments will have their
  630. precision set to a reasonable value determined by the operands and
  631. their mode is the zero value for RoundingMode (ToNearestEven).
  632. </p>
  633. <p>
  634. By setting the desired precision to 24 or 53 and using matching rounding
  635. mode (typically ToNearestEven), Float operations produce the same results
  636. as the corresponding float32 or float64 IEEE-754 arithmetic for operands
  637. that correspond to normal (i.e., not denormal) float32 or float64 numbers.
  638. Exponent underflow and overflow lead to a 0 or an Infinity for different
  639. values than IEEE-754 because Float exponents have a much larger range.
  640. </p>
  641. <p>
  642. The zero (uninitialized) value for a Float is ready to use and represents
  643. the number +0.0 exactly, with precision 0 and rounding mode ToNearestEven.
  644. </p>
  645. <h3 id="NewFloat">func <a href="http://localhost:6060/src/math/big/float.go?s=3139:3170#L71">NewFloat</a></h3>
  646. <pre>func NewFloat(x <a href="../../builtin/index.html#float64">float64</a>) *<a href="index.html#Float">Float</a></pre>
  647. <p>
  648. NewFloat allocates and returns a new Float set to x,
  649. with precision 53 and rounding mode ToNearestEven.
  650. NewFloat panics with ErrNaN if x is a NaN.
  651. </p>
  652. <h3 id="ParseFloat">func <a href="http://localhost:6060/src/math/big/floatconv.go?s=6934:7028#L263">ParseFloat</a></h3>
  653. <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>
  654. <p>
  655. ParseFloat is like f.Parse(s, base) with f set to the given precision
  656. and rounding mode.
  657. </p>
  658. <h3 id="Float.Abs">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=29473:29509#L1163">Abs</a></h3>
  659. <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>
  660. <p>
  661. Abs sets z to the (possibly rounded) value |x| (the absolute value of x)
  662. and returns z.
  663. </p>
  664. <h3 id="Float.Acc">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=7444:7474#L211">Acc</a></h3>
  665. <pre>func (x *<a href="index.html#Float">Float</a>) Acc() <a href="index.html#Accuracy">Accuracy</a></pre>
  666. <p>
  667. Acc returns the accuracy of x produced by the most recent operation.
  668. </p>
  669. <h3 id="Float.Add">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=36950:36989#L1409">Add</a></h3>
  670. <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>
  671. <p>
  672. Add sets z to the rounded sum x+y and returns z. If z&#39;s precision is 0,
  673. it is changed to the larger of x&#39;s or y&#39;s precision before the operation.
  674. Rounding is performed according to z&#39;s precision and rounding mode; and
  675. z&#39;s accuracy reports the result error relative to the exact (not rounded)
  676. result. Add panics with ErrNaN if x and y are infinities with opposite
  677. signs. The value of z is undefined in that case.
  678. </p>
  679. <p>
  680. BUG(gri) When rounding ToNegativeInf, the sign of Float values rounded to 0 is incorrect.
  681. </p>
  682. <div id="example_Float_Add" class="toggle">
  683. <div class="collapsed">
  684. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  685. </div>
  686. <div class="expanded">
  687. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  688. <p>Code:</p>
  689. <pre class="code"><span class="comment">// Operating on numbers of different precision.</span>
  690. var x, y, z big.Float
  691. x.SetInt64(1000) <span class="comment">// x is automatically set to 64bit precision</span>
  692. y.SetFloat64(2.718281828) <span class="comment">// y is automatically set to 53bit precision</span>
  693. z.SetPrec(32)
  694. z.Add(&amp;x, &amp;y)
  695. fmt.Printf(&#34;x = %.10g (%s, prec = %d, acc = %s)\n&#34;, &amp;x, x.Text(&#39;p&#39;, 0), x.Prec(), x.Acc())
  696. fmt.Printf(&#34;y = %.10g (%s, prec = %d, acc = %s)\n&#34;, &amp;y, y.Text(&#39;p&#39;, 0), y.Prec(), y.Acc())
  697. fmt.Printf(&#34;z = %.10g (%s, prec = %d, acc = %s)\n&#34;, &amp;z, z.Text(&#39;p&#39;, 0), z.Prec(), z.Acc())
  698. <span class="comment"></pre>
  699. <p>Output:</p>
  700. <pre class="output">x = 1000 (0x.fap+10, prec = 64, acc = Exact)
  701. y = 2.718281828 (0x.adf85458248cd8p+2, prec = 53, acc = Exact)
  702. z = 1002.718282 (0x.faadf854p+10, prec = 32, acc = Below)
  703. </pre>
  704. </div>
  705. </div>
  706. <h3 id="Float.Append">func (*Float) <a href="http://localhost:6060/src/math/big/ftoa.go?s=2225:2286#L46">Append</a></h3>
  707. <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>
  708. <p>
  709. Append appends to buf the string form of the floating-point number x,
  710. as generated by x.Text, and returns the extended buffer.
  711. </p>
  712. <h3 id="Float.Cmp">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=41304:41337#L1627">Cmp</a></h3>
  713. <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>
  714. <p>
  715. Cmp compares x and y and returns:
  716. </p>
  717. <pre>-1 if x &lt; y
  718. 0 if x == y (incl. -0 == 0, -Inf == -Inf, and +Inf == +Inf)
  719. +1 if x &gt; y
  720. </pre>
  721. <div id="example_Float_Cmp" class="toggle">
  722. <div class="collapsed">
  723. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  724. </div>
  725. <div class="expanded">
  726. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  727. <p>Code:</p>
  728. <pre class="code">inf := math.Inf(1)
  729. zero := 0.0
  730. operands := []float64{-inf, -1.2, -zero, 0, +1.2, +inf}
  731. fmt.Println(&#34; x y cmp&#34;)
  732. fmt.Println(&#34;---------------&#34;)
  733. for _, x64 := range operands {
  734. x := big.NewFloat(x64)
  735. for _, y64 := range operands {
  736. y := big.NewFloat(y64)
  737. fmt.Printf(&#34;%4g %4g %3d\n&#34;, x, y, x.Cmp(y))
  738. }
  739. fmt.Println()
  740. }
  741. <span class="comment"></pre>
  742. <p>Output:</p>
  743. <pre class="output"> x y cmp
  744. ---------------
  745. -Inf -Inf 0
  746. -Inf -1.2 -1
  747. -Inf -0 -1
  748. -Inf 0 -1
  749. -Inf 1.2 -1
  750. -Inf +Inf -1
  751. -1.2 -Inf 1
  752. -1.2 -1.2 0
  753. -1.2 -0 -1
  754. -1.2 0 -1
  755. -1.2 1.2 -1
  756. -1.2 +Inf -1
  757. -0 -Inf 1
  758. -0 -1.2 1
  759. -0 -0 0
  760. -0 0 0
  761. -0 1.2 -1
  762. -0 +Inf -1
  763. 0 -Inf 1
  764. 0 -1.2 1
  765. 0 -0 0
  766. 0 0 0
  767. 0 1.2 -1
  768. 0 +Inf -1
  769. 1.2 -Inf 1
  770. 1.2 -1.2 1
  771. 1.2 -0 1
  772. 1.2 0 1
  773. 1.2 1.2 0
  774. 1.2 +Inf -1
  775. +Inf -Inf 1
  776. +Inf -1.2 1
  777. +Inf -0 1
  778. +Inf 0 1
  779. +Inf 1.2 1
  780. +Inf +Inf 0
  781. </pre>
  782. </div>
  783. </div>
  784. <h3 id="Float.Copy">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=18453:18490#L685">Copy</a></h3>
  785. <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>
  786. <p>
  787. Copy sets z to x, with the same precision, rounding mode, and
  788. accuracy as x, and returns z. x is not changed even if z and
  789. x are the same.
  790. </p>
  791. <h3 id="Float.Float32">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=21859:21904#L848">Float32</a></h3>
  792. <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>
  793. <p>
  794. Float32 returns the float32 value nearest to x. If x is too small to be
  795. represented by a float32 (|x| &lt; math.SmallestNonzeroFloat32), the result
  796. is (0, Below) or (-0, Above), respectively, depending on the sign of x.
  797. If x is too large to be represented by a float32 (|x| &gt; math.MaxFloat32),
  798. the result is (+Inf, Above) or (-Inf, Below), depending on the sign of x.
  799. </p>
  800. <h3 id="Float.Float64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=24713:24758#L955">Float64</a></h3>
  801. <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>
  802. <p>
  803. Float64 returns the float64 value nearest to x. If x is too small to be
  804. represented by a float64 (|x| &lt; math.SmallestNonzeroFloat64), the result
  805. is (0, Below) or (-0, Above), respectively, depending on the sign of x.
  806. If x is too large to be represented by a float64 (|x| &gt; math.MaxFloat64),
  807. the result is (+Inf, Above) or (-Inf, Below), depending on the sign of x.
  808. </p>
  809. <h3 id="Float.Format">func (*Float) <a href="http://localhost:6060/src/math/big/ftoa.go?s=10329:10377#L376">Format</a></h3>
  810. <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>
  811. <p>
  812. Format implements fmt.Formatter. It accepts all the regular
  813. formats for floating-point numbers (&#39;e&#39;, &#39;E&#39;, &#39;f&#39;, &#39;F&#39;, &#39;g&#39;,
  814. &#39;G&#39;) as well as &#39;b&#39;, &#39;p&#39;, and &#39;v&#39;. See (*Float).Text for the
  815. interpretation of &#39;b&#39; and &#39;p&#39;. The &#39;v&#39; format is handled like
  816. &#39;g&#39;.
  817. Format also supports specification of the minimum precision
  818. in digits, the output field width, as well as the format verbs
  819. &#39;+&#39; and &#39; &#39; for sign control, &#39;0&#39; for space or zero padding,
  820. and &#39;-&#39; for left or right justification. See the fmt package
  821. for details.
  822. </p>
  823. <h3 id="Float.Int">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=27440:27484#L1063">Int</a></h3>
  824. <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>
  825. <p>
  826. Int returns the result of truncating x towards zero;
  827. or nil if x is an infinity.
  828. The result is Exact if x.IsInt(); otherwise it is Below
  829. for x &gt; 0, and Above for x &lt; 0.
  830. If a non-nil *Int argument z is provided, Int stores
  831. the result in z instead of allocating a new Int.
  832. </p>
  833. <h3 id="Float.Int64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=20590:20631#L793">Int64</a></h3>
  834. <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>
  835. <p>
  836. Int64 returns the integer resulting from truncating x towards zero.
  837. If math.MinInt64 &lt;= x &lt;= math.MaxInt64, the result is Exact if x is
  838. an integer, and Above (x &lt; 0) or Below (x &gt; 0) otherwise.
  839. The result is (math.MinInt64, Above) for x &lt; math.MinInt64,
  840. and (math.MaxInt64, Below) for x &gt; math.MaxInt64.
  841. </p>
  842. <h3 id="Float.IsInf">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=9686:9714#L319">IsInf</a></h3>
  843. <pre>func (x *<a href="index.html#Float">Float</a>) IsInf() <a href="../../builtin/index.html#bool">bool</a></pre>
  844. <p>
  845. IsInf reports whether x is +Inf or -Inf.
  846. </p>
  847. <h3 id="Float.IsInt">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=9818:9846#L325">IsInt</a></h3>
  848. <pre>func (x *<a href="index.html#Float">Float</a>) IsInt() <a href="../../builtin/index.html#bool">bool</a></pre>
  849. <p>
  850. IsInt reports whether x is an integer.
  851. ±Inf values are not integers.
  852. </p>
  853. <h3 id="Float.MantExp">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=8319:8365#L249">MantExp</a></h3>
  854. <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>
  855. <p>
  856. MantExp breaks x into its mantissa and exponent components
  857. and returns the exponent. If a non-nil mant argument is
  858. provided its value is set to the mantissa of x, with the
  859. same precision and rounding mode as x. The components
  860. satisfy x == mant × 2**exp, with 0.5 &lt;= |mant| &lt; 1.0.
  861. Calling MantExp with a nil argument is an efficient way to
  862. get the exponent of the receiver.
  863. </p>
  864. <p>
  865. Special cases are:
  866. </p>
  867. <pre>( ±0).MantExp(mant) = 0, with mant set to ±0
  868. (±Inf).MantExp(mant) = 0, with mant set to ±Inf
  869. </pre>
  870. <p>
  871. x and mant may be the same in which case x is set to its
  872. mantissa value.
  873. </p>
  874. <h3 id="Float.MarshalText">func (*Float) <a href="http://localhost:6060/src/math/big/floatmarsh.go?s=426:480#L4">MarshalText</a></h3>
  875. <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>
  876. <p>
  877. MarshalText implements the encoding.TextMarshaler interface.
  878. Only the Float value is marshaled (in full precision), other
  879. attributes such as precision or accuracy are ignored.
  880. </p>
  881. <h3 id="Float.MinPrec">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=7146:7176#L198">MinPrec</a></h3>
  882. <pre>func (x *<a href="index.html#Float">Float</a>) MinPrec() <a href="../../builtin/index.html#uint">uint</a></pre>
  883. <p>
  884. MinPrec returns the minimum precision required to represent x exactly
  885. (i.e., the smallest prec before x.SetPrec(prec) would start rounding x).
  886. The result is 0 for |x| == 0 and |x| == Inf.
  887. </p>
  888. <h3 id="Float.Mode">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=7316:7351#L206">Mode</a></h3>
  889. <pre>func (x *<a href="index.html#Float">Float</a>) Mode() <a href="index.html#RoundingMode">RoundingMode</a></pre>
  890. <p>
  891. Mode returns the rounding mode of x.
  892. </p>
  893. <h3 id="Float.Mul">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=39536:39575#L1535">Mul</a></h3>
  894. <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>
  895. <p>
  896. Mul sets z to the rounded product x*y and returns z.
  897. Precision, rounding, and accuracy reporting are as for Add.
  898. Mul panics with ErrNaN if one operand is zero and the other
  899. operand an infinity. The value of z is undefined in that case.
  900. </p>
  901. <h3 id="Float.Neg">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=29642:29678#L1171">Neg</a></h3>
  902. <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>
  903. <p>
  904. Neg sets z to the (possibly rounded) value of x with its sign negated,
  905. and returns z.
  906. </p>
  907. <h3 id="Float.Parse">func (*Float) <a href="http://localhost:6060/src/math/big/floatconv.go?s=6238:6308#L235">Parse</a></h3>
  908. <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>
  909. <p>
  910. Parse parses s which must contain a text representation of a floating-
  911. point number with a mantissa in the given conversion base (the exponent
  912. is always a decimal number), or a string representing an infinite value.
  913. </p>
  914. <p>
  915. It sets z to the (possibly rounded) value of the corresponding floating-
  916. point value, and returns z, the actual base b, and an error err, if any.
  917. If z&#39;s precision is 0, it is changed to 64 before rounding takes effect.
  918. The number must be of the form:
  919. </p>
  920. <pre> number = [ sign ] [ prefix ] mantissa [ exponent ] | infinity .
  921. sign = &#34;+&#34; | &#34;-&#34; .
  922. prefix = &#34;0&#34; ( &#34;x&#34; | &#34;X&#34; | &#34;b&#34; | &#34;B&#34; ) .
  923. mantissa = digits | digits &#34;.&#34; [ digits ] | &#34;.&#34; digits .
  924. exponent = ( &#34;E&#34; | &#34;e&#34; | &#34;p&#34; ) [ sign ] digits .
  925. digits = digit { digit } .
  926. digit = &#34;0&#34; ... &#34;9&#34; | &#34;a&#34; ... &#34;z&#34; | &#34;A&#34; ... &#34;Z&#34; .
  927. infinity = [ sign ] ( &#34;inf&#34; | &#34;Inf&#34; ) .
  928. </pre>
  929. <p>
  930. The base argument must be 0, 2, 10, or 16. Providing an invalid base
  931. argument will lead to a run-time panic.
  932. </p>
  933. <p>
  934. For base 0, the number prefix determines the actual base: A prefix of
  935. &#34;0x&#34; or &#34;0X&#34; selects base 16, and a &#34;0b&#34; or &#34;0B&#34; prefix selects
  936. base 2; otherwise, the actual base is 10 and no prefix is accepted.
  937. The octal prefix &#34;0&#34; is not supported (a leading &#34;0&#34; is simply
  938. considered a &#34;0&#34;).
  939. </p>
  940. <p>
  941. A &#34;p&#34; exponent indicates a binary (rather then decimal) exponent;
  942. for instance &#34;0x1.fffffffffffffp1023&#34; (using base 0) represents the
  943. maximum float64 value. For hexadecimal mantissae, the exponent must
  944. be binary, if present (an &#34;e&#34; or &#34;E&#34; exponent indicator cannot be
  945. distinguished from a mantissa digit).
  946. </p>
  947. <p>
  948. The returned *Float f is nil and the value of z is valid but not
  949. defined if an error is reported.
  950. </p>
  951. <h3 id="Float.Prec">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=6895:6922#L191">Prec</a></h3>
  952. <pre>func (x *<a href="index.html#Float">Float</a>) Prec() <a href="../../builtin/index.html#uint">uint</a></pre>
  953. <p>
  954. Prec returns the mantissa precision of x in bits.
  955. The result may be 0 for |x| == 0 and |x| == Inf.
  956. </p>
  957. <h3 id="Float.Quo">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=40457:40496#L1580">Quo</a></h3>
  958. <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>
  959. <p>
  960. Quo sets z to the rounded quotient x/y and returns z.
  961. Precision, rounding, and accuracy reporting are as for Add.
  962. Quo panics with ErrNaN if both operands are zero or infinities.
  963. The value of z is undefined in that case.
  964. </p>
  965. <h3 id="Float.Rat">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=28539:28583#L1119">Rat</a></h3>
  966. <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>
  967. <p>
  968. Rat returns the rational number corresponding to x;
  969. or nil if x is an infinity.
  970. The result is Exact if x is not an Inf.
  971. If a non-nil *Rat argument z is provided, Rat stores
  972. the result in z instead of allocating a new Rat.
  973. </p>
  974. <h3 id="Float.Set">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=17991:18027#L661">Set</a></h3>
  975. <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>
  976. <p>
  977. Set sets z to the (possibly rounded) value of x and returns z.
  978. If z&#39;s precision is 0, it is changed to the precision of x
  979. before setting z (and rounding will have no effect).
  980. Rounding is performed according to z&#39;s precision and rounding
  981. mode; and z&#39;s accuracy reports the result error relative to the
  982. exact (not rounded) result.
  983. </p>
  984. <h3 id="Float.SetFloat64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=15354:15398#L559">SetFloat64</a></h3>
  985. <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>
  986. <p>
  987. SetFloat64 sets z to the (possibly rounded) value of x and returns z.
  988. If z&#39;s precision is 0, it is changed to 53 (and rounding will have
  989. no effect). SetFloat64 panics with ErrNaN if x is a NaN.
  990. </p>
  991. <h3 id="Float.SetInf">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=17539:17582#L648">SetInf</a></h3>
  992. <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>
  993. <p>
  994. SetInf sets z to the infinite Float -Inf if signbit is
  995. set, or +Inf if signbit is not set, and returns z. The
  996. precision of z is unchanged and the result is always
  997. Exact.
  998. </p>
  999. <h3 id="Float.SetInt">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=16530:16567#L607">SetInt</a></h3>
  1000. <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>
  1001. <p>
  1002. SetInt sets z to the (possibly rounded) value of x and returns z.
  1003. If z&#39;s precision is 0, it is changed to the larger of x.BitLen()
  1004. or 64 (and rounding will have no effect).
  1005. </p>
  1006. <h3 id="Float.SetInt64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=14916:14956#L546">SetInt64</a></h3>
  1007. <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>
  1008. <p>
  1009. SetInt64 sets z to the (possibly rounded) value of x and returns z.
  1010. If z&#39;s precision is 0, it is changed to 64 (and rounding will have
  1011. no effect).
  1012. </p>
  1013. <h3 id="Float.SetMantExp">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=9312:9367#L300">SetMantExp</a></h3>
  1014. <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>
  1015. <p>
  1016. SetMantExp sets z to mant × 2**exp and and returns z.
  1017. The result z has the same precision and rounding mode
  1018. as mant. SetMantExp is an inverse of MantExp but does
  1019. not require 0.5 &lt;= |mant| &lt; 1.0. Specifically:
  1020. </p>
  1021. <pre>mant := new(Float)
  1022. new(Float).SetMantExp(mant, x.MantExp(mant)).Cmp(x) == 0
  1023. </pre>
  1024. <p>
  1025. Special cases are:
  1026. </p>
  1027. <pre>z.SetMantExp( ±0, exp) = ±0
  1028. z.SetMantExp(±Inf, exp) = ±Inf
  1029. </pre>
  1030. <p>
  1031. z and mant may be the same in which case z&#39;s exponent
  1032. is set to exp.
  1033. </p>
  1034. <h3 id="Float.SetMode">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=6695:6744#L183">SetMode</a></h3>
  1035. <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>
  1036. <p>
  1037. SetMode sets z&#39;s rounding mode to mode and returns an exact z.
  1038. z remains unchanged otherwise.
  1039. z.SetMode(z.Mode()) is a cheap way to set z&#39;s accuracy to Exact.
  1040. </p>
  1041. <h3 id="Float.SetPrec">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=6039:6080#L147">SetPrec</a></h3>
  1042. <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>
  1043. <p>
  1044. SetPrec sets z&#39;s precision to prec and returns the (possibly) rounded
  1045. value of z. Rounding occurs according to z&#39;s rounding mode if the mantissa
  1046. cannot be represented in prec bits without loss of precision.
  1047. SetPrec(0) maps all finite values to ±0; infinite values remain unchanged.
  1048. If prec &gt; MaxPrec, it is set to MaxPrec.
  1049. </p>
  1050. <h3 id="Float.SetRat">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=17135:17172#L631">SetRat</a></h3>
  1051. <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>
  1052. <p>
  1053. SetRat sets z to the (possibly rounded) value of x and returns z.
  1054. If z&#39;s precision is 0, it is changed to the largest of a.BitLen(),
  1055. b.BitLen(), or 64; with x = a/b.
  1056. </p>
  1057. <h3 id="Float.SetString">func (*Float) <a href="http://localhost:6060/src/math/big/floatconv.go?s=461:511#L8">SetString</a></h3>
  1058. <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>
  1059. <p>
  1060. SetString sets z to the value of s and returns z and a boolean indicating
  1061. success. s must be a floating-point number of the same format as accepted
  1062. by Parse, with base argument 0.
  1063. </p>
  1064. <h3 id="Float.SetUint64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=14682:14724#L539">SetUint64</a></h3>
  1065. <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>
  1066. <p>
  1067. SetUint64 sets z to the (possibly rounded) value of x and returns z.
  1068. If z&#39;s precision is 0, it is changed to 64 (and rounding will have
  1069. no effect).
  1070. </p>
  1071. <h3 id="Float.Sign">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=7569:7595#L221">Sign</a></h3>
  1072. <pre>func (x *<a href="index.html#Float">Float</a>) Sign() <a href="../../builtin/index.html#int">int</a></pre>
  1073. <p>
  1074. Sign returns:
  1075. </p>
  1076. <pre>-1 if x &lt; 0
  1077. 0 if x is ±0
  1078. +1 if x &gt; 0
  1079. </pre>
  1080. <h3 id="Float.Signbit">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=9592:9622#L314">Signbit</a></h3>
  1081. <pre>func (x *<a href="index.html#Float">Float</a>) Signbit() <a href="../../builtin/index.html#bool">bool</a></pre>
  1082. <p>
  1083. Signbit returns true if x is negative or negative zero.
  1084. </p>
  1085. <h3 id="Float.String">func (*Float) <a href="http://localhost:6060/src/math/big/ftoa.go?s=2031:2062#L40">String</a></h3>
  1086. <pre>func (x *<a href="index.html#Float">Float</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
  1087. <p>
  1088. String formats x like x.Text(&#39;g&#39;, 10).
  1089. (String must be called explicitly, Float.Format does not support %s verb.)
  1090. </p>
  1091. <h3 id="Float.Sub">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=38237:38276#L1472">Sub</a></h3>
  1092. <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>
  1093. <p>
  1094. Sub sets z to the rounded difference x-y and returns z.
  1095. Precision, rounding, and accuracy reporting are as for Add.
  1096. Sub panics with ErrNaN if x and y are infinities with equal
  1097. signs. The value of z is undefined in that case.
  1098. </p>
  1099. <h3 id="Float.Text">func (*Float) <a href="http://localhost:6060/src/math/big/ftoa.go?s=1721:1771#L33">Text</a></h3>
  1100. <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>
  1101. <p>
  1102. Text converts the floating-point number x to a string according
  1103. to the given format and precision prec. The format is one of:
  1104. </p>
  1105. <pre>&#39;e&#39; -d.dddde±dd, decimal exponent, at least two (possibly 0) exponent digits
  1106. &#39;E&#39; -d.ddddE±dd, decimal exponent, at least two (possibly 0) exponent digits
  1107. &#39;f&#39; -ddddd.dddd, no exponent
  1108. &#39;g&#39; like &#39;e&#39; for large exponents, like &#39;f&#39; otherwise
  1109. &#39;G&#39; like &#39;E&#39; for large exponents, like &#39;f&#39; otherwise
  1110. &#39;b&#39; -ddddddp±dd, binary exponent
  1111. &#39;p&#39; -0x.dddp±dd, binary exponent, hexadecimal mantissa
  1112. </pre>
  1113. <p>
  1114. For the binary exponent formats, the mantissa is printed in normalized form:
  1115. </p>
  1116. <pre>&#39;b&#39; decimal integer mantissa using x.Prec() bits, or -0
  1117. &#39;p&#39; hexadecimal fraction with 0.5 &lt;= 0.mantissa &lt; 1.0, or -0
  1118. </pre>
  1119. <p>
  1120. If format is a different character, Text returns a &#34;%&#34; followed by the
  1121. unrecognized format character.
  1122. </p>
  1123. <p>
  1124. The precision prec controls the number of digits (excluding the exponent)
  1125. 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;
  1126. it is the number of digits after the decimal point. For &#39;g&#39; and &#39;G&#39; it is
  1127. the total number of digits. A negative precision selects the smallest
  1128. number of decimal digits necessary to identify the value x uniquely using
  1129. x.Prec() mantissa bits.
  1130. The prec value is ignored for the &#39;b&#39; or &#39;p&#39; format.
  1131. </p>
  1132. <h3 id="Float.Uint64">func (*Float) <a href="http://localhost:6060/src/math/big/float.go?s=19650:19693#L748">Uint64</a></h3>
  1133. <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>
  1134. <p>
  1135. Uint64 returns the unsigned integer resulting from truncating x
  1136. towards zero. If 0 &lt;= x &lt;= math.MaxUint64, the result is Exact
  1137. if x is an integer and Below otherwise.
  1138. The result is (0, Above) for x &lt; 0, and (math.MaxUint64, Below)
  1139. for x &gt; math.MaxUint64.
  1140. </p>
  1141. <h3 id="Float.UnmarshalText">func (*Float) <a href="http://localhost:6060/src/math/big/floatmarsh.go?s=800:848#L16">UnmarshalText</a></h3>
  1142. <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>
  1143. <p>
  1144. UnmarshalText implements the encoding.TextUnmarshaler interface.
  1145. The result is rounded per the precision and rounding mode of z.
  1146. If z&#39;s precision is 0, it is changed to 64 before rounding takes
  1147. effect.
  1148. </p>
  1149. <h2 id="Int">type <a href="http://localhost:6060/src/math/big/int.go?s=388:468#L8">Int</a></h2>
  1150. <pre>type Int struct {
  1151. <span class="comment">// contains filtered or unexported fields</span>
  1152. }</pre>
  1153. <p>
  1154. An Int represents a signed multi-precision integer.
  1155. The zero value for an Int represents the value 0.
  1156. </p>
  1157. <h3 id="NewInt">func <a href="http://localhost:6060/src/math/big/int.go?s=1058:1083#L51">NewInt</a></h3>
  1158. <pre>func NewInt(x <a href="../../builtin/index.html#int64">int64</a>) *<a href="index.html#Int">Int</a></pre>
  1159. <p>
  1160. NewInt allocates and returns a new Int set to x.
  1161. </p>
  1162. <h3 id="Int.Abs">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=2124:2154#L85">Abs</a></h3>
  1163. <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>
  1164. <p>
  1165. Abs sets z to |x| (the absolute value of x) and returns z.
  1166. </p>
  1167. <h3 id="Int.Add">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=2381:2414#L99">Add</a></h3>
  1168. <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>
  1169. <p>
  1170. Add sets z to the sum x+y and returns z.
  1171. </p>
  1172. <h3 id="Int.And">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=18689:18722#L789">And</a></h3>
  1173. <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>
  1174. <p>
  1175. And sets z = x &amp; y and returns z.
  1176. </p>
  1177. <h3 id="Int.AndNot">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=19370:19406#L819">AndNot</a></h3>
  1178. <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>
  1179. <p>
  1180. AndNot sets z = x &amp;^ y and returns z.
  1181. </p>
  1182. <h3 id="Int.Append">func (*Int) <a href="http://localhost:6060/src/math/big/intconv.go?s=1046:1095#L24">Append</a></h3>
  1183. <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>
  1184. <p>
  1185. Append appends the string representation of x, as generated by
  1186. x.Text(base), to buf and returns the extended buffer.
  1187. </p>
  1188. <h3 id="Int.Binomial">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=4127:4166#L175">Binomial</a></h3>
  1189. <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>
  1190. <p>
  1191. Binomial sets z to the binomial coefficient of (n, k) and returns z.
  1192. </p>
  1193. <h3 id="Int.Bit">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=17801:17830#L749">Bit</a></h3>
  1194. <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>
  1195. <p>
  1196. Bit returns the value of the i&#39;th bit of x. That is, it
  1197. returns (x&gt;&gt;i)&amp;1. The bit index i must be &gt;= 0.
  1198. </p>
  1199. <h3 id="Int.BitLen">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=9739:9765#L391">BitLen</a></h3>
  1200. <pre>func (x *<a href="index.html#Int">Int</a>) BitLen() <a href="../../builtin/index.html#int">int</a></pre>
  1201. <p>
  1202. BitLen returns the length of the absolute value of x in bits.
  1203. The bit length of 0 is 0.
  1204. </p>
  1205. <h3 id="Int.Bits">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=1572:1599#L69">Bits</a></h3>
  1206. <pre>func (x *<a href="index.html#Int">Int</a>) Bits() []<a href="index.html#Word">Word</a></pre>
  1207. <p>
  1208. Bits provides raw (unchecked but fast) access to x by returning its
  1209. absolute value as a little-endian Word slice. The result and x share
  1210. the same underlying array.
  1211. Bits is intended to support implementation of missing low-level Int
  1212. functionality outside this package; it should be avoided otherwise.
  1213. </p>
  1214. <h3 id="Int.Bytes">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=9544:9572#L384">Bytes</a></h3>
  1215. <pre>func (x *<a href="index.html#Int">Int</a>) Bytes() []<a href="../../builtin/index.html#byte">byte</a></pre>
  1216. <p>
  1217. Bytes returns the absolute value of x as a big-endian byte slice.
  1218. </p>
  1219. <h3 id="Int.Cmp">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=7472:7505#L298">Cmp</a></h3>
  1220. <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>
  1221. <p>
  1222. Cmp compares x and y and returns:
  1223. </p>
  1224. <pre>-1 if x &lt; y
  1225. 0 if x == y
  1226. +1 if x &gt; y
  1227. </pre>
  1228. <h3 id="Int.Div">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=5888:5921#L225">Div</a></h3>
  1229. <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>
  1230. <p>
  1231. Div sets z to the quotient x/y for y != 0 and returns z.
  1232. If y == 0, a division-by-zero run-time panic occurs.
  1233. Div implements Euclidean division (unlike Go); see DivMod for more details.
  1234. </p>
  1235. <h3 id="Int.DivMod">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=7093:7140#L274">DivMod</a></h3>
  1236. <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>
  1237. <p>
  1238. DivMod sets z to the quotient x div y and m to the modulus x mod y
  1239. and returns the pair (z, m) for y != 0.
  1240. If y == 0, a division-by-zero run-time panic occurs.
  1241. </p>
  1242. <p>
  1243. DivMod implements Euclidean division and modulus (unlike Go):
  1244. </p>
  1245. <pre>q = x div y such that
  1246. m = x - y*q with 0 &lt;= m &lt; |y|
  1247. </pre>
  1248. <p>
  1249. (See Raymond T. Boute, &ldquo;The Euclidean definition of the functions
  1250. div and mod&rdquo;. ACM Transactions on Programming Languages and
  1251. Systems (TOPLAS), 14(2):127-144, New York, NY, USA, 4/1992.
  1252. ACM press.)
  1253. See QuoRem for T-division and modulus (like Go).
  1254. </p>
  1255. <h3 id="Int.Exp">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=9982:10018#L398">Exp</a></h3>
  1256. <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>
  1257. <p>
  1258. Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z.
  1259. If y &lt;= 0, the result is 1 mod |m|; if m == nil or m == 0, z = x**y.
  1260. See Knuth, volume 2, section 4.6.3.
  1261. </p>
  1262. <h3 id="Int.Format">func (*Int) <a href="http://localhost:6060/src/math/big/intconv.go?s=2004:2046#L56">Format</a></h3>
  1263. <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>
  1264. <p>
  1265. Format is a support routine for fmt.Formatter. It accepts
  1266. the formats &#39;b&#39; (binary), &#39;o&#39; (octal), &#39;d&#39; (decimal), &#39;x&#39;
  1267. (lowercase hexadecimal), and &#39;X&#39; (uppercase hexadecimal).
  1268. Also supported are the full suite of package fmt&#39;s format
  1269. verbs for integral types, including &#39;+&#39;, &#39;-&#39;, and &#39; &#39;
  1270. for sign control, &#39;#&#39; for leading zero in octal and for
  1271. hexadecimal, a leading &#34;0x&#34; or &#34;0X&#34; for &#34;%#x&#34; and &#34;%#X&#34;
  1272. respectively, specification of minimum digits precision,
  1273. output field width, space or zero padding, and left or
  1274. right justification.
  1275. </p>
  1276. <h3 id="Int.GCD">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=10689:10728#L425">GCD</a></h3>
  1277. <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>
  1278. <p>
  1279. GCD sets z to the greatest common divisor of a and b, which both must
  1280. be &gt; 0, and returns z.
  1281. If x and y are not nil, GCD sets x and y such that z = a*x + b*y.
  1282. If either a or b is &lt;= 0, GCD sets z = x = y = 0.
  1283. </p>
  1284. <h3 id="Int.GobDecode">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=782:823#L20">GobDecode</a></h3>
  1285. <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>
  1286. <p>
  1287. GobDecode implements the gob.GobDecoder interface.
  1288. </p>
  1289. <h3 id="Int.GobEncode">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=398:439#L5">GobEncode</a></h3>
  1290. <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>
  1291. <p>
  1292. GobEncode implements the gob.GobEncoder interface.
  1293. </p>
  1294. <h3 id="Int.Int64">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=8193:8220#L339">Int64</a></h3>
  1295. <pre>func (x *<a href="index.html#Int">Int</a>) Int64() <a href="../../builtin/index.html#int64">int64</a></pre>
  1296. <p>
  1297. Int64 returns the int64 representation of x.
  1298. If x cannot be represented in an int64, the result is undefined.
  1299. </p>
  1300. <h3 id="Int.Lsh">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=17199:17237#L725">Lsh</a></h3>
  1301. <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>
  1302. <p>
  1303. Lsh sets z = x &lt;&lt; n and returns z.
  1304. </p>
  1305. <h3 id="Int.MarshalJSON">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=1859:1902#L57">MarshalJSON</a></h3>
  1306. <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>
  1307. <p>
  1308. MarshalJSON implements the json.Marshaler interface.
  1309. </p>
  1310. <h3 id="Int.MarshalText">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=1172:1224#L36">MarshalText</a></h3>
  1311. <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>
  1312. <p>
  1313. MarshalText implements the encoding.TextMarshaler interface.
  1314. </p>
  1315. <h3 id="Int.Mod">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=6287:6320#L242">Mod</a></h3>
  1316. <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>
  1317. <p>
  1318. Mod sets z to the modulus x%y for y != 0 and returns z.
  1319. If y == 0, a division-by-zero run-time panic occurs.
  1320. Mod implements Euclidean modulus (unlike Go); see DivMod for more details.
  1321. </p>
  1322. <h3 id="Int.ModInverse">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=13518:13558#L569">ModInverse</a></h3>
  1323. <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>
  1324. <p>
  1325. ModInverse sets z to the multiplicative inverse of g in the ring ℤ/nℤ
  1326. and returns z. If g and n are not relatively prime, the result is undefined.
  1327. </p>
  1328. <h3 id="Int.ModSqrt">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=16674:16711#L703">ModSqrt</a></h3>
  1329. <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>
  1330. <p>
  1331. ModSqrt sets z to a square root of x mod p if such a square root exists, and
  1332. returns z. The modulus p must be an odd prime. If x is not a square mod p,
  1333. ModSqrt leaves z unchanged and returns nil. This function panics if p is
  1334. not an odd integer.
  1335. </p>
  1336. <h3 id="Int.Mul">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=3332:3365#L141">Mul</a></h3>
  1337. <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>
  1338. <p>
  1339. Mul sets z to the product x*y and returns z.
  1340. </p>
  1341. <h3 id="Int.MulRange">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=3711:3750#L154">MulRange</a></h3>
  1342. <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>
  1343. <p>
  1344. MulRange sets z to the product of all integers
  1345. in the range [a, b] inclusively and returns z.
  1346. If a &gt; b (empty range), the result is 1.
  1347. </p>
  1348. <h3 id="Int.Neg">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=2230:2260#L92">Neg</a></h3>
  1349. <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>
  1350. <p>
  1351. Neg sets z to -x and returns z.
  1352. </p>
  1353. <h3 id="Int.Not">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=21631:21661#L912">Not</a></h3>
  1354. <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>
  1355. <p>
  1356. Not sets z = ^x and returns z.
  1357. </p>
  1358. <h3 id="Int.Or">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=20184:20216#L852">Or</a></h3>
  1359. <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>
  1360. <p>
  1361. Or sets z = x | y and returns z.
  1362. </p>
  1363. <h3 id="Int.ProbablyPrime">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=12954:12993#L549">ProbablyPrime</a></h3>
  1364. <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>
  1365. <p>
  1366. ProbablyPrime performs n Miller-Rabin tests to check whether x is prime.
  1367. If x is prime, it returns true.
  1368. If x is not prime, it returns false with probability at least 1 - ¼ⁿ.
  1369. </p>
  1370. <p>
  1371. It is not suitable for judging primes that an adversary may have crafted
  1372. to fool this test.
  1373. </p>
  1374. <h3 id="Int.Quo">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=4573:4606#L189">Quo</a></h3>
  1375. <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>
  1376. <p>
  1377. Quo sets z to the quotient x/y for y != 0 and returns z.
  1378. If y == 0, a division-by-zero run-time panic occurs.
  1379. Quo implements truncated division (like Go); see QuoRem for more details.
  1380. </p>
  1381. <h3 id="Int.QuoRem">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=5489:5536#L216">QuoRem</a></h3>
  1382. <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>
  1383. <p>
  1384. QuoRem sets z to the quotient x/y and r to the remainder x%y
  1385. and returns the pair (z, r) for y != 0.
  1386. If y == 0, a division-by-zero run-time panic occurs.
  1387. </p>
  1388. <p>
  1389. QuoRem implements T-division and modulus (like Go):
  1390. </p>
  1391. <pre>q = x/y with the result truncated to zero
  1392. r = x - y*q
  1393. </pre>
  1394. <p>
  1395. (See Daan Leijen, &ldquo;Division and Modulus for Computer Scientists&rdquo;.)
  1396. See DivMod for Euclidean division and modulus (unlike Go).
  1397. </p>
  1398. <h3 id="Int.Rand">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=13166:13213#L557">Rand</a></h3>
  1399. <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>
  1400. <p>
  1401. Rand sets z to a pseudo-random number in [0, n) and returns z.
  1402. </p>
  1403. <h3 id="Int.Rem">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=4915:4948#L198">Rem</a></h3>
  1404. <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>
  1405. <p>
  1406. Rem sets z to the remainder x%y for y != 0 and returns z.
  1407. If y == 0, a division-by-zero run-time panic occurs.
  1408. Rem implements truncated modulus (like Go); see QuoRem for more details.
  1409. </p>
  1410. <h3 id="Int.Rsh">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=17335:17373#L732">Rsh</a></h3>
  1411. <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>
  1412. <p>
  1413. Rsh sets z = x &gt;&gt; n and returns z.
  1414. </p>
  1415. <h3 id="Int.Scan">func (*Int) <a href="http://localhost:6060/src/math/big/intconv.go?s=6298:6348#L219">Scan</a></h3>
  1416. <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>
  1417. <p>
  1418. Scan is a support routine for fmt.Scanner; it sets z to the value of
  1419. the scanned number. It accepts the formats &#39;b&#39; (binary), &#39;o&#39; (octal),
  1420. &#39;d&#39; (decimal), &#39;x&#39; (lowercase hexadecimal), and &#39;X&#39; (uppercase hexadecimal).
  1421. </p>
  1422. <div id="example_Int_Scan" class="toggle">
  1423. <div class="collapsed">
  1424. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1425. </div>
  1426. <div class="expanded">
  1427. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1428. <p>Code:</p>
  1429. <pre class="code"><span class="comment">// The Scan function is rarely used directly;</span>
  1430. <span class="comment">// the fmt package recognizes it as an implementation of fmt.Scanner.</span>
  1431. i := new(big.Int)
  1432. _, err := fmt.Sscan(&#34;18446744073709551617&#34;, i)
  1433. if err != nil {
  1434. log.Println(&#34;error scanning value:&#34;, err)
  1435. } else {
  1436. fmt.Println(i)
  1437. }
  1438. <span class="comment"></pre>
  1439. <p>Output:</p>
  1440. <pre class="output">18446744073709551617
  1441. </pre>
  1442. </div>
  1443. </div>
  1444. <h3 id="Int.Set">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=1152:1182#L56">Set</a></h3>
  1445. <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>
  1446. <p>
  1447. Set sets z to x and returns z.
  1448. </p>
  1449. <h3 id="Int.SetBit">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=18345:18393#L772">SetBit</a></h3>
  1450. <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>
  1451. <p>
  1452. SetBit sets z to x, with x&#39;s i&#39;th bit set to b (0 or 1).
  1453. That is, if b is 1 SetBit sets z = x | (1 &lt;&lt; i);
  1454. if b is 0 SetBit sets z = x &amp;^ (1 &lt;&lt; i). If b is not 0 or 1,
  1455. SetBit will panic.
  1456. </p>
  1457. <h3 id="Int.SetBits">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=1968:2006#L78">SetBits</a></h3>
  1458. <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>
  1459. <p>
  1460. SetBits provides raw (unchecked but fast) access to z by setting its
  1461. value to abs, interpreted as a little-endian Word slice, and returning
  1462. z. The result and abs share the same underlying array.
  1463. SetBits is intended to support implementation of missing low-level Int
  1464. functionality outside this package; it should be avoided otherwise.
  1465. </p>
  1466. <h3 id="Int.SetBytes">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=9376:9415#L377">SetBytes</a></h3>
  1467. <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>
  1468. <p>
  1469. SetBytes interprets buf as the bytes of a big-endian unsigned
  1470. integer, sets z to that value, and returns z.
  1471. </p>
  1472. <h3 id="Int.SetInt64">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=717:753#L32">SetInt64</a></h3>
  1473. <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>
  1474. <p>
  1475. SetInt64 sets z to x and returns z.
  1476. </p>
  1477. <h3 id="Int.SetString">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=8978:9034#L362">SetString</a></h3>
  1478. <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>
  1479. <p>
  1480. SetString sets z to the value of s, interpreted in the given base,
  1481. and returns z and a boolean indicating success. If SetString fails,
  1482. the value of z is undefined but the returned value is nil.
  1483. </p>
  1484. <p>
  1485. The base argument must be 0 or a value between 2 and MaxBase. If the base
  1486. is 0, the string prefix determines the actual conversion base. A prefix of
  1487. &ldquo;0x&rdquo; or &ldquo;0X&rdquo; selects base 16; the &ldquo;0&rdquo; prefix selects base 8, and a
  1488. &ldquo;0b&rdquo; or &ldquo;0B&rdquo; prefix selects base 2. Otherwise the selected base is 10.
  1489. </p>
  1490. <div id="example_Int_SetString" class="toggle">
  1491. <div class="collapsed">
  1492. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1493. </div>
  1494. <div class="expanded">
  1495. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1496. <p>Code:</p>
  1497. <pre class="code">i := new(big.Int)
  1498. i.SetString(&#34;644&#34;, 8) <span class="comment">// octal</span>
  1499. fmt.Println(i)
  1500. <span class="comment"></pre>
  1501. <p>Output:</p>
  1502. <pre class="output">420
  1503. </pre>
  1504. </div>
  1505. </div>
  1506. <h3 id="Int.SetUint64">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=909:947#L44">SetUint64</a></h3>
  1507. <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>
  1508. <p>
  1509. SetUint64 sets z to x and returns z.
  1510. </p>
  1511. <h3 id="Int.Sign">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=575:599#L21">Sign</a></h3>
  1512. <pre>func (x *<a href="index.html#Int">Int</a>) Sign() <a href="../../builtin/index.html#int">int</a></pre>
  1513. <p>
  1514. Sign returns:
  1515. </p>
  1516. <pre>-1 if x &lt; 0
  1517. 0 if x == 0
  1518. +1 if x &gt; 0
  1519. </pre>
  1520. <h3 id="Int.String">func (*Int) <a href="http://localhost:6060/src/math/big/intconv.go?s=1200:1229#L31">String</a></h3>
  1521. <pre>func (x *<a href="index.html#Int">Int</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
  1522. <h3 id="Int.Sub">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=2858:2891#L120">Sub</a></h3>
  1523. <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>
  1524. <p>
  1525. Sub sets z to the difference x-y and returns z.
  1526. </p>
  1527. <h3 id="Int.Text">func (*Int) <a href="http://localhost:6060/src/math/big/intconv.go?s=807:842#L15">Text</a></h3>
  1528. <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>
  1529. <p>
  1530. Text returns the string representation of x in the given base.
  1531. Base must be between 2 and 36, inclusive. The result uses the
  1532. lower-case letters &#39;a&#39; to &#39;z&#39; for digit values &gt;= 10. No base
  1533. prefix (such as &#34;0x&#34;) is added to the string.
  1534. </p>
  1535. <h3 id="Int.Uint64">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=8404:8433#L349">Uint64</a></h3>
  1536. <pre>func (x *<a href="index.html#Int">Int</a>) Uint64() <a href="../../builtin/index.html#uint64">uint64</a></pre>
  1537. <p>
  1538. Uint64 returns the uint64 representation of x.
  1539. If x cannot be represented in a uint64, the result is undefined.
  1540. </p>
  1541. <h3 id="Int.UnmarshalJSON">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=1992:2038#L62">UnmarshalJSON</a></h3>
  1542. <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>
  1543. <p>
  1544. UnmarshalJSON implements the json.Unmarshaler interface.
  1545. </p>
  1546. <h3 id="Int.UnmarshalText">func (*Int) <a href="http://localhost:6060/src/math/big/intmarsh.go?s=1381:1427#L44">UnmarshalText</a></h3>
  1547. <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>
  1548. <p>
  1549. UnmarshalText implements the encoding.TextUnmarshaler interface.
  1550. </p>
  1551. <h3 id="Int.Xor">func (*Int) <a href="http://localhost:6060/src/math/big/int.go?s=20954:20987#L882">Xor</a></h3>
  1552. <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>
  1553. <p>
  1554. Xor sets z = x ^ y and returns z.
  1555. </p>
  1556. <h2 id="Rat">type <a href="http://localhost:6060/src/math/big/rat.go?s=370:570#L6">Rat</a></h2>
  1557. <pre>type Rat struct {
  1558. <span class="comment">// contains filtered or unexported fields</span>
  1559. }</pre>
  1560. <p>
  1561. A Rat represents a quotient a/b of arbitrary precision.
  1562. The zero value for a Rat represents the value 0.
  1563. </p>
  1564. <h3 id="NewRat">func <a href="http://localhost:6060/src/math/big/rat.go?s=636:664#L14">NewRat</a></h3>
  1565. <pre>func NewRat(a, b <a href="../../builtin/index.html#int64">int64</a>) *<a href="index.html#Rat">Rat</a></pre>
  1566. <p>
  1567. NewRat creates a new Rat with numerator a and denominator b.
  1568. </p>
  1569. <h3 id="Rat.Abs">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=8897:8927#L335">Abs</a></h3>
  1570. <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>
  1571. <p>
  1572. Abs sets z to |x| (the absolute value of x) and returns z.
  1573. </p>
  1574. <h3 id="Rat.Add">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=11795:11828#L464">Add</a></h3>
  1575. <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>
  1576. <p>
  1577. Add sets z to the sum x+y and returns z.
  1578. </p>
  1579. <h3 id="Rat.Cmp">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=11651:11680#L459">Cmp</a></h3>
  1580. <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>
  1581. <p>
  1582. Cmp compares x and y and returns:
  1583. </p>
  1584. <pre>-1 if x &lt; y
  1585. 0 if x == y
  1586. +1 if x &gt; y
  1587. </pre>
  1588. <h3 id="Rat.Denom">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=10168:10194#L392">Denom</a></h3>
  1589. <pre>func (x *<a href="index.html#Rat">Rat</a>) Denom() *<a href="index.html#Int">Int</a></pre>
  1590. <p>
  1591. Denom returns the denominator of x; it is always &gt; 0.
  1592. The result is a reference to x&#39;s denominator; it
  1593. may change if a new value is assigned to x, and vice versa.
  1594. </p>
  1595. <h3 id="Rat.Float32">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=7126:7173#L254">Float32</a></h3>
  1596. <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>
  1597. <p>
  1598. Float32 returns the nearest float32 value for x and a bool indicating
  1599. whether f represents x exactly. If the magnitude of x is too large to
  1600. be represented by a float32, f is an infinity and exact is false.
  1601. The sign of f always matches the sign of x, even if f == 0.
  1602. </p>
  1603. <h3 id="Rat.Float64">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=7611:7658#L270">Float64</a></h3>
  1604. <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>
  1605. <p>
  1606. Float64 returns the nearest float64 value for x and a bool indicating
  1607. whether f represents x exactly. If the magnitude of x is too large to
  1608. be represented by a float64, f is an infinity and exact is false.
  1609. The sign of f always matches the sign of x, even if f == 0.
  1610. </p>
  1611. <h3 id="Rat.FloatString">func (*Rat) <a href="http://localhost:6060/src/math/big/ratconv.go?s=4796:4838#L204">FloatString</a></h3>
  1612. <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>
  1613. <p>
  1614. FloatString returns a string representation of x in decimal form with prec
  1615. digits of precision after the decimal point. The last digit is rounded to
  1616. nearest, with halves rounded away from zero.
  1617. </p>
  1618. <h3 id="Rat.GobDecode">func (*Rat) <a href="http://localhost:6060/src/math/big/ratmarsh.go?s=1058:1099#L32">GobDecode</a></h3>
  1619. <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>
  1620. <p>
  1621. GobDecode implements the gob.GobDecoder interface.
  1622. </p>
  1623. <h3 id="Rat.GobEncode">func (*Rat) <a href="http://localhost:6060/src/math/big/ratmarsh.go?s=432:473#L9">GobEncode</a></h3>
  1624. <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>
  1625. <p>
  1626. GobEncode implements the gob.GobEncoder interface.
  1627. </p>
  1628. <h3 id="Rat.Inv">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=9154:9184#L349">Inv</a></h3>
  1629. <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>
  1630. <p>
  1631. Inv sets z to 1/x and returns z.
  1632. </p>
  1633. <h3 id="Rat.IsInt">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=9644:9670#L377">IsInt</a></h3>
  1634. <pre>func (x *<a href="index.html#Rat">Rat</a>) IsInt() <a href="../../builtin/index.html#bool">bool</a></pre>
  1635. <p>
  1636. IsInt reports whether the denominator of x is 1.
  1637. </p>
  1638. <h3 id="Rat.MarshalText">func (*Rat) <a href="http://localhost:6060/src/math/big/ratmarsh.go?s=1555:1607#L51">MarshalText</a></h3>
  1639. <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>
  1640. <p>
  1641. MarshalText implements the encoding.TextMarshaler interface.
  1642. </p>
  1643. <h3 id="Rat.Mul">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=12266:12299#L482">Mul</a></h3>
  1644. <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>
  1645. <p>
  1646. Mul sets z to the product x*y and returns z.
  1647. </p>
  1648. <h3 id="Rat.Neg">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=9005:9035#L342">Neg</a></h3>
  1649. <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>
  1650. <p>
  1651. Neg sets z to -x and returns z.
  1652. </p>
  1653. <h3 id="Rat.Num">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=9953:9977#L385">Num</a></h3>
  1654. <pre>func (x *<a href="index.html#Rat">Rat</a>) Num() *<a href="index.html#Int">Int</a></pre>
  1655. <p>
  1656. Num returns the numerator of x; it may be &lt;= 0.
  1657. The result is a reference to x&#39;s numerator; it
  1658. may change if a new value is assigned to x, and vice versa.
  1659. The sign of the numerator corresponds to the sign of x.
  1660. </p>
  1661. <h3 id="Rat.Quo">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=12495:12528#L490">Quo</a></h3>
  1662. <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>
  1663. <p>
  1664. Quo sets z to the quotient x/y and returns z.
  1665. If y == 0, a division-by-zero run-time panic occurs.
  1666. </p>
  1667. <h3 id="Rat.RatString">func (*Rat) <a href="http://localhost:6060/src/math/big/ratconv.go?s=4495:4527#L194">RatString</a></h3>
  1668. <pre>func (x *<a href="index.html#Rat">Rat</a>) RatString() <a href="../../builtin/index.html#string">string</a></pre>
  1669. <p>
  1670. RatString returns a string representation of x in the form &#34;a/b&#34; if b != 1,
  1671. and in the form &#34;a&#34; if b == 1.
  1672. </p>
  1673. <h3 id="Rat.Scan">func (*Rat) <a href="http://localhost:6060/src/math/big/ratconv.go?s=516:566#L13">Scan</a></h3>
  1674. <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>
  1675. <p>
  1676. Scan is a support routine for fmt.Scanner. It accepts the formats
  1677. &#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.
  1678. </p>
  1679. <div id="example_Rat_Scan" class="toggle">
  1680. <div class="collapsed">
  1681. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1682. </div>
  1683. <div class="expanded">
  1684. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1685. <p>Code:</p>
  1686. <pre class="code"><span class="comment">// The Scan function is rarely used directly;</span>
  1687. <span class="comment">// the fmt package recognizes it as an implementation of fmt.Scanner.</span>
  1688. r := new(big.Rat)
  1689. _, err := fmt.Sscan(&#34;1.5000&#34;, r)
  1690. if err != nil {
  1691. log.Println(&#34;error scanning value:&#34;, err)
  1692. } else {
  1693. fmt.Println(r)
  1694. }
  1695. <span class="comment"></pre>
  1696. <p>Output:</p>
  1697. <pre class="output">3/2
  1698. </pre>
  1699. </div>
  1700. </div>
  1701. <h3 id="Rat.Set">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=8741:8771#L326">Set</a></h3>
  1702. <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>
  1703. <p>
  1704. Set sets z to x (by making a copy of x) and returns z.
  1705. </p>
  1706. <h3 id="Rat.SetFloat64">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=797:837#L20">SetFloat64</a></h3>
  1707. <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>
  1708. <p>
  1709. SetFloat64 sets z to exactly f and returns z.
  1710. If f is not finite, SetFloat returns nil.
  1711. </p>
  1712. <h3 id="Rat.SetFrac">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=7858:7895#L283">SetFrac</a></h3>
  1713. <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>
  1714. <p>
  1715. SetFrac sets z to a/b and returns z.
  1716. </p>
  1717. <h3 id="Rat.SetFrac64">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=8198:8238#L298">SetFrac64</a></h3>
  1718. <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>
  1719. <p>
  1720. SetFrac64 sets z to a/b and returns z.
  1721. </p>
  1722. <h3 id="Rat.SetInt">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=8468:8501#L312">SetInt</a></h3>
  1723. <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>
  1724. <p>
  1725. SetInt sets z to x (by making a copy of x) and returns z.
  1726. </p>
  1727. <h3 id="Rat.SetInt64">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=8591:8627#L319">SetInt64</a></h3>
  1728. <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>
  1729. <p>
  1730. SetInt64 sets z to x and returns z.
  1731. </p>
  1732. <h3 id="Rat.SetString">func (*Rat) <a href="http://localhost:6060/src/math/big/ratconv.go?s=1120:1166#L31">SetString</a></h3>
  1733. <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>
  1734. <p>
  1735. SetString sets z to the value of s and returns z and a boolean indicating
  1736. success. s can be given as a fraction &#34;a/b&#34; or as a floating-point number
  1737. optionally followed by an exponent. If the operation failed, the value of
  1738. z is undefined but the returned value is nil.
  1739. </p>
  1740. <div id="example_Rat_SetString" class="toggle">
  1741. <div class="collapsed">
  1742. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1743. </div>
  1744. <div class="expanded">
  1745. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1746. <p>Code:</p>
  1747. <pre class="code">r := new(big.Rat)
  1748. r.SetString(&#34;355/113&#34;)
  1749. fmt.Println(r.FloatString(3))
  1750. <span class="comment"></pre>
  1751. <p>Output:</p>
  1752. <pre class="output">3.142
  1753. </pre>
  1754. </div>
  1755. </div>
  1756. <h3 id="Rat.Sign">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=9543:9567#L372">Sign</a></h3>
  1757. <pre>func (x *<a href="index.html#Rat">Rat</a>) Sign() <a href="../../builtin/index.html#int">int</a></pre>
  1758. <p>
  1759. Sign returns:
  1760. </p>
  1761. <pre>-1 if x &lt; 0
  1762. 0 if x == 0
  1763. +1 if x &gt; 0
  1764. </pre>
  1765. <h3 id="Rat.String">func (*Rat) <a href="http://localhost:6060/src/math/big/ratconv.go?s=4170:4199#L180">String</a></h3>
  1766. <pre>func (x *<a href="index.html#Rat">Rat</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
  1767. <p>
  1768. String returns a string representation of x in the form &#34;a/b&#34; (even if b == 1).
  1769. </p>
  1770. <h3 id="Rat.Sub">func (*Rat) <a href="http://localhost:6060/src/math/big/rat.go?s=12032:12065#L473">Sub</a></h3>
  1771. <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>
  1772. <p>
  1773. Sub sets z to the difference x-y and returns z.
  1774. </p>
  1775. <h3 id="Rat.UnmarshalText">func (*Rat) <a href="http://localhost:6060/src/math/big/ratmarsh.go?s=1771:1817#L57">UnmarshalText</a></h3>
  1776. <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>
  1777. <p>
  1778. UnmarshalText implements the encoding.TextUnmarshaler interface.
  1779. </p>
  1780. <h2 id="RoundingMode">type <a href="http://localhost:6060/src/math/big/float.go?s=4819:4841#L115">RoundingMode</a></h2>
  1781. <pre>type RoundingMode <a href="../../builtin/index.html#byte">byte</a></pre>
  1782. <p>
  1783. RoundingMode determines how a Float value is rounded to the
  1784. desired precision. Rounding may change the Float value; the
  1785. rounding error is described by the Float&#39;s Accuracy.
  1786. </p>
  1787. <pre>const (
  1788. <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>
  1789. <span id="ToNearestAway">ToNearestAway</span> <span class="comment">// == IEEE 754-2008 roundTiesToAway</span>
  1790. <span id="ToZero">ToZero</span> <span class="comment">// == IEEE 754-2008 roundTowardZero</span>
  1791. <span id="AwayFromZero">AwayFromZero</span> <span class="comment">// no IEEE 754-2008 equivalent</span>
  1792. <span id="ToNegativeInf">ToNegativeInf</span> <span class="comment">// == IEEE 754-2008 roundTowardNegative</span>
  1793. <span id="ToPositiveInf">ToPositiveInf</span> <span class="comment">// == IEEE 754-2008 roundTowardPositive</span>
  1794. )</pre>
  1795. <p>
  1796. These constants define supported rounding modes.
  1797. </p>
  1798. <div id="example_RoundingMode" class="toggle">
  1799. <div class="collapsed">
  1800. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1801. </div>
  1802. <div class="expanded">
  1803. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1804. <p>Code:</p>
  1805. <pre class="code">operands := []float64{2.6, 2.5, 2.1, -2.1, -2.5, -2.6}
  1806. fmt.Print(&#34; x&#34;)
  1807. for mode := big.ToNearestEven; mode &lt;= big.ToPositiveInf; mode++ {
  1808. fmt.Printf(&#34; %s&#34;, mode)
  1809. }
  1810. fmt.Println()
  1811. for _, f64 := range operands {
  1812. fmt.Printf(&#34;%4g&#34;, f64)
  1813. for mode := big.ToNearestEven; mode &lt;= big.ToPositiveInf; mode++ {
  1814. <span class="comment">// sample operands above require 2 bits to represent mantissa</span>
  1815. <span class="comment">// set binary precision to 2 to round them to integer values</span>
  1816. f := new(big.Float).SetPrec(2).SetMode(mode).SetFloat64(f64)
  1817. fmt.Printf(&#34; %*g&#34;, len(mode.String()), f)
  1818. }
  1819. fmt.Println()
  1820. }
  1821. <span class="comment"></pre>
  1822. <p>Output:</p>
  1823. <pre class="output"> x ToNearestEven ToNearestAway ToZero AwayFromZero ToNegativeInf ToPositiveInf
  1824. 2.6 3 3 2 3 2 3
  1825. 2.5 2 3 2 3 2 3
  1826. 2.1 2 2 2 3 2 3
  1827. -2.1 -2 -2 -2 -3 -3 -2
  1828. -2.5 -2 -3 -2 -3 -3 -2
  1829. -2.6 -3 -3 -2 -3 -3 -2
  1830. </pre>
  1831. </div>
  1832. </div>
  1833. <h3 id="RoundingMode.String">func (RoundingMode) <a href="http://localhost:6060/src/math/big/roundingmode_string.go?s=251:288#L1">String</a></h3>
  1834. <pre>func (i <a href="index.html#RoundingMode">RoundingMode</a>) String() <a href="../../builtin/index.html#string">string</a></pre>
  1835. <h2 id="Word">type <a href="http://localhost:6060/src/math/big/arith.go?s=438:455#L2">Word</a></h2>
  1836. <pre>type Word <a href="../../builtin/index.html#uintptr">uintptr</a></pre>
  1837. <p>
  1838. A Word represents a single digit of a multi-precision unsigned integer.
  1839. </p>
  1840. <h2 id="pkg-note-BUG">Bugs</h2>
  1841. <ul style="list-style: none; padding: 0;">
  1842. <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.
  1843. </li>
  1844. </ul>
  1845. <div id="footer">
  1846. Build version go1.6.<br>
  1847. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  1848. the content of this page is licensed under the
  1849. Creative Commons Attribution 3.0 License,
  1850. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  1851. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  1852. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  1853. </div>
  1854. </div><!-- .container -->
  1855. </div><!-- #page -->
  1856. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  1857. <script type="text/javascript" src="../../../lib/godoc/jquery.js"></script>
  1858. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.js"></script>
  1859. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.edit.js"></script>
  1860. <script type="text/javascript" src="../../../lib/godoc/godocs.js"></script>
  1861. </body>
  1862. </html>