Subversion Repositories oidplus

Rev

Rev 419 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="Author" content="M Mclaughlin">
  7. <title>bignumber.js API</title>
  8. <style>
  9. html{font-size:100%}
  10. body{background:#fff;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;
  11.   line-height:1.65em;min-height:100%;margin:0}
  12. body,i{color:#000}
  13. .nav{background:#fff;position:fixed;top:0;bottom:0;left:0;width:200px;overflow-y:auto;
  14.   padding:15px 0 30px 15px}
  15. div.container{width:600px;margin:50px 0 50px 240px}
  16. p{margin:0 0 1em;width:600px}
  17. pre,ul{margin:1em 0}
  18. h1,h2,h3,h4,h5{margin:0;padding:1.5em 0 0}
  19. h1,h2{padding:.75em 0}
  20. h1{font:400 3em Verdana,sans-serif;color:#000;margin-bottom:1em}
  21. h2{font-size:2.25em;color:#ff2a00}
  22. h3{font-size:1.75em;color:#4dc71f}
  23. h4{font-size:1.75em;color:#ff2a00;padding-bottom:.75em}
  24. h5{font-size:1.2em;margin-bottom:.4em}
  25. h6{font-size:1.1em;margin-bottom:0.8em;padding:0.5em 0}
  26. dd{padding-top:.35em}
  27. dt{padding-top:.5em}
  28. b{font-weight:700}
  29. dt b{font-size:1.3em}
  30. a,a:visited{color:#ff2a00;text-decoration:none}
  31. a:active,a:hover{outline:0;text-decoration:underline}
  32. .nav a,.nav b,.nav a:visited{display:block;color:#ff2a00;font-weight:700; margin-top:15px}
  33. .nav b{color:#4dc71f;margin-top:20px;cursor:default;width:auto}
  34. ul{list-style-type:none;padding:0 0 0 20px}
  35. .nav ul{line-height:14px;padding-left:0;margin:5px 0 0}
  36. .nav ul a,.nav ul a:visited,span{display:inline;color:#000;font-family:Verdana,Geneva,sans-serif;
  37.   font-size:11px;font-weight:400;margin:0}
  38. .inset,ul.inset{margin-left:20px}
  39. .inset{font-size:.9em}
  40. .nav li{width:auto;margin:0 0 3px}
  41. .alias{font-style:italic;margin-left:20px}
  42. table{border-collapse:collapse;border-spacing:0;border:2px solid #a7dbd8;margin:1.75em 0;padding:0}
  43. td,th{text-align:left;margin:0;padding:2px 5px;border:1px dotted #a7dbd8}
  44. th{border-top:2px solid #a7dbd8;border-bottom:2px solid #a7dbd8;color:#ff2a00}
  45. code,pre{font-family:Consolas, monaco, monospace;font-weight:400}
  46. pre{background:#f5f5f5;white-space:pre-wrap;word-wrap:break-word;border-left:5px solid #abef98;
  47.   padding:1px 0 1px 15px;margin:1.2em 0}
  48. code,.nav-title{color:#ff2a00}
  49. .end{margin-bottom:25px}
  50. .centre{text-align:center}
  51. .error-table{font-size:13px;width:100%}
  52. #faq{margin:3em 0 0}
  53. li span{float:right;margin-right:10px;color:#c0c0c0}
  54. #js{font:inherit;color:#4dc71f}
  55. </style>
  56. </head>
  57. <body>
  58.  
  59.   <div class="nav">
  60.  
  61.     <b>v9.0.0</b>
  62.  
  63.         <a class='nav-title' href="#">API</a>
  64.  
  65.     <b> CONSTRUCTOR </b>
  66.     <ul>
  67.       <li><a href="#bignumber">BigNumber</a></li>
  68.     </ul>
  69.  
  70.     <a href="#methods">Methods</a>
  71.     <ul>
  72.       <li><a href="#clone">clone</a></li>
  73.       <li><a href="#config" >config</a><span>set</span></li>
  74.       <li>
  75.         <ul class="inset">
  76.           <li><a href="#decimal-places">DECIMAL_PLACES</a></li>
  77.           <li><a href="#rounding-mode" >ROUNDING_MODE</a></li>
  78.           <li><a href="#exponential-at">EXPONENTIAL_AT</a></li>
  79.           <li><a href="#range"         >RANGE</a></li>
  80.           <li><a href="#crypto"        >CRYPTO</a></li>
  81.           <li><a href="#modulo-mode"   >MODULO_MODE</a></li>
  82.           <li><a href="#pow-precision" >POW_PRECISION</a></li>
  83.           <li><a href="#format"        >FORMAT</a></li>
  84.           <li><a href="#alphabet"      >ALPHABET</a></li>
  85.         </ul>
  86.       </li>
  87.       <li><a href="#isBigNumber">isBigNumber</a></li>
  88.       <li><a href="#max"        >maximum</a><span>max</span></li>
  89.       <li><a href="#min"        >minimum</a><span>min</span></li>
  90.       <li><a href="#random"     >random</a></li>
  91.       <li><a href="#sum"        >sum</a></li>
  92.     </ul>
  93.  
  94.     <a href="#constructor-properties">Properties</a>
  95.     <ul>
  96.       <li><a href="#round-up"        >ROUND_UP</a></li>
  97.       <li><a href="#round-down"      >ROUND_DOWN</a></li>
  98.       <li><a href="#round-ceil"      >ROUND_CEIL</a></li>
  99.       <li><a href="#round-floor"     >ROUND_FLOOR</a></li>
  100.       <li><a href="#round-half-up"   >ROUND_HALF_UP</a></li>
  101.       <li><a href="#round-half-down" >ROUND_HALF_DOWN</a></li>
  102.       <li><a href="#round-half-even" >ROUND_HALF_EVEN</a></li>
  103.       <li><a href="#round-half-ceil" >ROUND_HALF_CEIL</a></li>
  104.       <li><a href="#round-half-floor">ROUND_HALF_FLOOR</a></li>
  105.       <li><a href="#debug"           >DEBUG</a></li>
  106.     </ul>
  107.  
  108.     <b> INSTANCE </b>
  109.  
  110.     <a href="#prototype-methods">Methods</a>
  111.     <ul>
  112.       <li><a href="#abs"    >absoluteValue         </a><span>abs</span>  </li>
  113.       <li><a href="#cmp"    >comparedTo            </a>                  </li>
  114.       <li><a href="#dp"     >decimalPlaces         </a><span>dp</span>   </li>
  115.       <li><a href="#div"    >dividedBy             </a><span>div</span>  </li>
  116.       <li><a href="#divInt" >dividedToIntegerBy    </a><span>idiv</span> </li>
  117.       <li><a href="#pow"    >exponentiatedBy       </a><span>pow</span>  </li>
  118.       <li><a href="#int"    >integerValue          </a>                  </li>
  119.       <li><a href="#eq"     >isEqualTo             </a><span>eq</span>   </li>
  120.       <li><a href="#isF"    >isFinite              </a>                  </li>
  121.       <li><a href="#gt"     >isGreaterThan         </a><span>gt</span>   </li>
  122.       <li><a href="#gte"    >isGreaterThanOrEqualTo</a><span>gte</span>  </li>
  123.       <li><a href="#isInt"  >isInteger             </a>                  </li>
  124.       <li><a href="#lt"     >isLessThan            </a><span>lt</span>   </li>
  125.       <li><a href="#lte"    >isLessThanOrEqualTo   </a><span>lte</span>  </li>
  126.       <li><a href="#isNaN"  >isNaN                 </a>                  </li>
  127.       <li><a href="#isNeg"  >isNegative            </a>                  </li>
  128.       <li><a href="#isPos"  >isPositive            </a>                  </li>
  129.       <li><a href="#isZ"    >isZero                </a>                  </li>
  130.       <li><a href="#minus"  >minus                 </a>                  </li>
  131.       <li><a href="#mod"    >modulo                </a><span>mod</span>  </li>
  132.       <li><a href="#times"  >multipliedBy          </a><span>times</span></li>
  133.       <li><a href="#neg"    >negated               </a>                  </li>
  134.       <li><a href="#plus"   >plus                  </a>                  </li>
  135.       <li><a href="#sd"     >precision             </a><span>sd</span>   </li>
  136.       <li><a href="#shift"  >shiftedBy             </a>                  </li>
  137.       <li><a href="#sqrt"   >squareRoot            </a><span>sqrt</span> </li>
  138.       <li><a href="#toE"    >toExponential         </a>                  </li>
  139.       <li><a href="#toFix"  >toFixed               </a>                  </li>
  140.       <li><a href="#toFor"  >toFormat              </a>                  </li>
  141.       <li><a href="#toFr"   >toFraction            </a>                  </li>
  142.       <li><a href="#toJSON" >toJSON                </a>                  </li>
  143.       <li><a href="#toN"    >toNumber              </a>                  </li>
  144.       <li><a href="#toP"    >toPrecision           </a>                  </li>
  145.       <li><a href="#toS"    >toString              </a>                  </li>
  146.       <li><a href="#valueOf">valueOf               </a>                  </li>
  147.     </ul>
  148.  
  149.     <a href="#instance-properties">Properties</a>
  150.     <ul>
  151.       <li><a href="#coefficient">c: coefficient</a></li>
  152.       <li><a href="#exponent"   >e: exponent</a></li>
  153.       <li><a href="#sign"       >s: sign</a></li>
  154.     </ul>
  155.  
  156.     <a href="#zero-nan-infinity">Zero, NaN &amp; Infinity</a>
  157.     <a href="#Errors">Errors</a>
  158.     <a href="#type-coercion">Type coercion</a>
  159.     <a class='end' href="#faq">FAQ</a>
  160.  
  161.   </div>
  162.  
  163.   <div class="container">
  164.  
  165.     <h1>bignumber<span id='js'>.js</span></h1>
  166.  
  167.     <p>A JavaScript library for arbitrary-precision arithmetic.</p>
  168.     <p><a href="https://github.com/MikeMcl/bignumber.js">Hosted on GitHub</a>. </p>
  169.  
  170.     <h2>API</h2>
  171.  
  172.     <p>
  173.       See the <a href='https://github.com/MikeMcl/bignumber.js'>README</a> on GitHub for a
  174.       quick-start introduction.
  175.     </p>
  176.     <p>
  177.       In all examples below, <code>var</code> and semicolons are not shown, and if a commented-out
  178.       value is in quotes it means <code>toString</code> has been called on the preceding expression.
  179.     </p>
  180.  
  181.  
  182.     <h3>CONSTRUCTOR</h3>
  183.  
  184.  
  185.     <h5 id="bignumber">
  186.       BigNumber<code class='inset'>BigNumber(n [, base]) <i>&rArr; BigNumber</i></code>
  187.     </h5>
  188.     <p>
  189.       <code>n</code>: <i>number|string|BigNumber</i><br />
  190.       <code>base</code>: <i>number</i>: integer, <code>2</code> to <code>36</code> inclusive. (See
  191.       <a href='#alphabet'><code>ALPHABET</code></a> to extend this range).
  192.     </p>
  193.     <p>
  194.       Returns a new instance of a BigNumber object with value <code>n</code>, where <code>n</code>
  195.       is a numeric value in the specified <code>base</code>, or base <code>10</code> if
  196.       <code>base</code> is omitted or is <code>null</code> or <code>undefined</code>.
  197.     </p>
  198.     <pre>
  199. x = new BigNumber(123.4567)                // '123.4567'
  200. // 'new' is optional
  201. y = BigNumber(x)                           // '123.4567'</pre>
  202.     <p>
  203.       If <code>n</code> is a base <code>10</code> value it can be in normal (fixed-point) or
  204.       exponential notation. Values in other bases must be in normal notation. Values in any base can
  205.       have fraction digits, i.e. digits after the decimal point.
  206.     </p>
  207.     <pre>
  208. new BigNumber(43210)                       // '43210'
  209. new BigNumber('4.321e+4')                  // '43210'
  210. new BigNumber('-735.0918e-430')            // '-7.350918e-428'
  211. new BigNumber('123412421.234324', 5)       // '607236.557696'</pre>
  212.     <p>
  213.       Signed <code>0</code>, signed <code>Infinity</code> and <code>NaN</code> are supported.
  214.     </p>
  215.     <pre>
  216. new BigNumber('-Infinity')                 // '-Infinity'
  217. new BigNumber(NaN)                         // 'NaN'
  218. new BigNumber(-0)                          // '0'
  219. new BigNumber('.5')                        // '0.5'
  220. new BigNumber('+2')                        // '2'</pre>
  221.     <p>
  222.       String values in hexadecimal literal form, e.g. <code>'0xff'</code>, are valid, as are
  223.       string values with the octal and binary prefixs <code>'0o'</code> and <code>'0b'</code>.
  224.       String values in octal literal form without the prefix will be interpreted as
  225.       decimals, e.g. <code>'011'</code> is interpreted as 11, not 9.
  226.     </p>
  227.     <pre>
  228. new BigNumber(-10110100.1, 2)              // '-180.5'
  229. new BigNumber('-0b10110100.1')             // '-180.5'
  230. new BigNumber('ff.8', 16)                  // '255.5'
  231. new BigNumber('0xff.8')                    // '255.5'</pre>
  232.     <p>
  233.       If a base is specified, <code>n</code> is rounded according to the current
  234.       <a href='#decimal-places'><code>DECIMAL_PLACES</code></a> and
  235.       <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> settings. <em>This includes base
  236.       <code>10</code> so don't include a <code>base</code> parameter for decimal values unless
  237.      this behaviour is wanted.</em>
  238.    </p>
  239.    <pre>BigNumber.config({ DECIMAL_PLACES: 5 })
  240. new BigNumber(1.23456789)                  // '1.23456789'
  241. new BigNumber(1.23456789, 10)              // '1.23457'</pre>
  242.    <p>An error is thrown if <code>base</code> is invalid. See <a href='#Errors'>Errors</a>.</p>
  243.    <p>
  244.      There is no limit to the number of digits of a value of type <em>string</em> (other than
  245.      that of JavaScript's maximum array size). See <a href='#range'><code>RANGE</code></a> to set
  246.       the maximum and minimum possible exponent value of a BigNumber.
  247.     </p>
  248.     <pre>
  249. new BigNumber('5032485723458348569331745.33434346346912144534543')
  250. new BigNumber('4.321e10000000')</pre>
  251.     <p>BigNumber <code>NaN</code> is returned if <code>n</code> is invalid
  252.     (unless <code>BigNumber.DEBUG</code> is <code>true</code>, see below).</p>
  253.     <pre>
  254. new BigNumber('.1*')                       // 'NaN'
  255. new BigNumber('blurgh')                    // 'NaN'
  256. new BigNumber(9, 2)                        // 'NaN'</pre>
  257.     <p>
  258.       To aid in debugging, if <code>BigNumber.DEBUG</code> is <code>true</code> then an error will
  259.       be thrown on an invalid <code>n</code>. An error will also be thrown if <code>n</code> is of
  260.       type <em>number</em> with more than <code>15</code> significant digits, as calling
  261.       <code><a href='#toS'>toString</a></code> or <code><a href='#valueOf'>valueOf</a></code> on
  262.       these numbers may not result in the intended value.
  263.     </p>
  264.       <pre>
  265. console.log(823456789123456.3)            //  823456789123456.2
  266. new BigNumber(823456789123456.3)          // '823456789123456.2'
  267. BigNumber.DEBUG = true
  268. // '[BigNumber Error] Number primitive has more than 15 significant digits'
  269. new BigNumber(823456789123456.3)
  270. // '[BigNumber Error] Not a base 2 number'
  271. new BigNumber(9, 2)</pre>
  272.     <p>
  273.       A BigNumber can also be created from an object literal.
  274.       Use <code><a href='#isBigNumber'>isBigNumber</a></code> to check that it is well-formed.
  275.     </p>
  276.     <pre>new BigNumber({ s: 1, e: 2, c: [ 777, 12300000000000 ], _isBigNumber: true })    // '777.123'</pre>
  277.  
  278.  
  279.  
  280.  
  281.     <h4 id="methods">Methods</h4>
  282.      <p>The static methods of a BigNumber constructor.</p>
  283.  
  284.  
  285.  
  286.  
  287.     <h5 id="clone">clone
  288.       <code class='inset'>.clone([object]) <i>&rArr; BigNumber constructor</i></code>
  289.     </h5>
  290.     <p><code>object</code>: <i>object</i></p>
  291.     <p>
  292.       Returns a new independent BigNumber constructor with configuration as described by
  293.       <code>object</code> (see <a href='#config'><code>config</code></a>), or with the default
  294.       configuration if <code>object</code> is <code>null</code> or <code>undefined</code>.
  295.     </p>
  296.     <p>
  297.       Throws if <code>object</code> is not an object. See <a href='#Errors'>Errors</a>.
  298.     </p>
  299.     <pre>BigNumber.config({ DECIMAL_PLACES: 5 })
  300. BN = BigNumber.clone({ DECIMAL_PLACES: 9 })
  301.  
  302. x = new BigNumber(1)
  303. y = new BN(1)
  304.  
  305. x.div(3)                        // 0.33333
  306. y.div(3)                        // 0.333333333
  307.  
  308. // BN = BigNumber.clone({ DECIMAL_PLACES: 9 }) is equivalent to:
  309. BN = BigNumber.clone()
  310. BN.config({ DECIMAL_PLACES: 9 })</pre>
  311.  
  312.  
  313.  
  314.     <h5 id="config">config<code class='inset'>set([object]) <i>&rArr; object</i></code></h5>
  315.     <p>
  316.       <code>object</code>: <i>object</i>: an object that contains some or all of the following
  317.       properties.
  318.     </p>
  319.     <p>Configures the settings for this particular BigNumber constructor.</p>
  320.  
  321.     <dl class='inset'>
  322.       <dt id="decimal-places"><code><b>DECIMAL_PLACES</b></code></dt>
  323.       <dd>
  324.         <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive<br />
  325.         Default value: <code>20</code>
  326.       </dd>
  327.       <dd>
  328.         The <span style="text-decoration:underline">maximum</span> number of decimal places of the results of operations involving
  329.         division, i.e. division, square root and base conversion operations, and power
  330.         operations with negative exponents.<br />
  331.       </dd>
  332.       <dd>
  333.       <pre>BigNumber.config({ DECIMAL_PLACES: 5 })
  334. BigNumber.set({ DECIMAL_PLACES: 5 })    // equivalent</pre>
  335.       </dd>
  336.  
  337.  
  338.  
  339.       <dt id="rounding-mode"><code><b>ROUNDING_MODE</b></code></dt>
  340.       <dd>
  341.         <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive<br />
  342.         Default value: <code>4</code> <a href="#round-half-up">(<code>ROUND_HALF_UP</code>)</a>
  343.       </dd>
  344.       <dd>
  345.         The rounding mode used in the above operations and the default rounding mode of
  346.         <a href='#dp'><code>decimalPlaces</code></a>,
  347.         <a href='#sd'><code>precision</code></a>,
  348.         <a href='#toE'><code>toExponential</code></a>,
  349.         <a href='#toFix'><code>toFixed</code></a>,
  350.         <a href='#toFor'><code>toFormat</code></a> and
  351.         <a href='#toP'><code>toPrecision</code></a>.
  352.       </dd>
  353.       <dd>The modes are available as enumerated properties of the BigNumber constructor.</dd>
  354.        <dd>
  355.       <pre>BigNumber.config({ ROUNDING_MODE: 0 })
  356. BigNumber.set({ ROUNDING_MODE: BigNumber.ROUND_UP })    // equivalent</pre>
  357.         </dd>
  358.  
  359.  
  360.  
  361.       <dt id="exponential-at"><code><b>EXPONENTIAL_AT</b></code></dt>
  362.       <dd>
  363.         <i>number</i>: integer, magnitude <code>0</code> to <code>1e+9</code> inclusive, or
  364.         <br />
  365.         <i>number</i>[]: [ integer <code>-1e+9</code> to <code>0</code> inclusive, integer
  366.         <code>0</code> to <code>1e+9</code> inclusive ]<br />
  367.         Default value: <code>[-7, 20]</code>
  368.       </dd>
  369.       <dd>
  370.         The exponent value(s) at which <code>toString</code> returns exponential notation.
  371.       </dd>
  372.       <dd>
  373.         If a single number is assigned, the value is the exponent magnitude.<br />
  374.         If an array of two numbers is assigned then the first number is the negative exponent
  375.         value at and beneath which exponential notation is used, and the second number is the
  376.         positive exponent value at and above which the same.
  377.       </dd>
  378.       <dd>
  379.         For example, to emulate JavaScript numbers in terms of the exponent values at which they
  380.         begin to use exponential notation, use <code>[-7, 20]</code>.
  381.       </dd>
  382.       <dd>
  383.       <pre>BigNumber.config({ EXPONENTIAL_AT: 2 })
  384. new BigNumber(12.3)         // '12.3'        e is only 1
  385. new BigNumber(123)          // '1.23e+2'
  386. new BigNumber(0.123)        // '0.123'       e is only -1
  387. new BigNumber(0.0123)       // '1.23e-2'
  388.  
  389. BigNumber.config({ EXPONENTIAL_AT: [-7, 20] })
  390. new BigNumber(123456789)    // '123456789'   e is only 8
  391. new BigNumber(0.000000123)  // '1.23e-7'
  392.  
  393. // Almost never return exponential notation:
  394. BigNumber.config({ EXPONENTIAL_AT: 1e+9 })
  395.  
  396. // Always return exponential notation:
  397. BigNumber.config({ EXPONENTIAL_AT: 0 })</pre>
  398.       </dd>
  399.       <dd>
  400.         Regardless of the value of <code>EXPONENTIAL_AT</code>, the <code>toFixed</code> method
  401.         will always return a value in normal notation and the <code>toExponential</code> method
  402.         will always return a value in exponential form.
  403.       </dd>
  404.       <dd>
  405.         Calling <code>toString</code> with a base argument, e.g. <code>toString(10)</code>, will
  406.         also always return normal notation.
  407.       </dd>
  408.  
  409.  
  410.  
  411.       <dt id="range"><code><b>RANGE</b></code></dt>
  412.       <dd>
  413.         <i>number</i>: integer, magnitude <code>1</code> to <code>1e+9</code> inclusive, or
  414.         <br />
  415.         <i>number</i>[]: [ integer <code>-1e+9</code> to <code>-1</code> inclusive, integer
  416.         <code>1</code> to <code>1e+9</code> inclusive ]<br />
  417.         Default value: <code>[-1e+9, 1e+9]</code>
  418.       </dd>
  419.       <dd>
  420.         The exponent value(s) beyond which overflow to <code>Infinity</code> and underflow to
  421.         zero occurs.
  422.       </dd>
  423.       <dd>
  424.         If a single number is assigned, it is the maximum exponent magnitude: values wth a
  425.         positive exponent of greater magnitude become <code>Infinity</code> and those with a
  426.         negative exponent of greater magnitude become zero.
  427.       <dd>
  428.         If an array of two numbers is assigned then the first number is the negative exponent
  429.         limit and the second number is the positive exponent limit.
  430.       </dd>
  431.       <dd>
  432.         For example, to emulate JavaScript numbers in terms of the exponent values at which they
  433.         become zero and <code>Infinity</code>, use <code>[-324, 308]</code>.
  434.       </dd>
  435.       <dd>
  436.       <pre>BigNumber.config({ RANGE: 500 })
  437. BigNumber.config().RANGE     // [ -500, 500 ]
  438. new BigNumber('9.999e499')   // '9.999e+499'
  439. new BigNumber('1e500')       // 'Infinity'
  440. new BigNumber('1e-499')      // '1e-499'
  441. new BigNumber('1e-500')      // '0'
  442.  
  443. BigNumber.config({ RANGE: [-3, 4] })
  444. new BigNumber(99999)         // '99999'      e is only 4
  445. new BigNumber(100000)        // 'Infinity'   e is 5
  446. new BigNumber(0.001)         // '0.01'       e is only -3
  447. new BigNumber(0.0001)        // '0'          e is -4</pre>
  448.       </dd>
  449.       <dd>
  450.         The largest possible magnitude of a finite BigNumber is
  451.         <code>9.999...e+1000000000</code>.<br />
  452.         The smallest possible magnitude of a non-zero BigNumber is <code>1e-1000000000</code>.
  453.       </dd>
  454.  
  455.  
  456.  
  457.       <dt id="crypto"><code><b>CRYPTO</b></code></dt>
  458.       <dd>
  459.         <i>boolean</i>: <code>true</code> or <code>false</code>.<br />
  460.         Default value: <code>false</code>
  461.       </dd>
  462.       <dd>
  463.         The value that determines whether cryptographically-secure pseudo-random number
  464.         generation is used.
  465.       </dd>
  466.       <dd>
  467.         If <code>CRYPTO</code> is set to <code>true</code> then the
  468.         <a href='#random'><code>random</code></a> method will generate random digits using
  469.         <code>crypto.getRandomValues</code> in browsers that support it, or
  470.         <code>crypto.randomBytes</code> if using Node.js.
  471.       </dd>
  472.       <dd>
  473.         If neither function is supported by the host environment then attempting to set
  474.         <code>CRYPTO</code> to <code>true</code> will fail and an exception will be thrown.
  475.       </dd>
  476.       <dd>
  477.         If <code>CRYPTO</code> is <code>false</code> then the source of randomness used will be
  478.         <code>Math.random</code> (which is assumed to generate at least <code>30</code> bits of
  479.         randomness).
  480.       </dd>
  481.       <dd>See <a href='#random'><code>random</code></a>.</dd>
  482.       <dd>
  483.       <pre>
  484. // Node.js
  485. global.crypto = require('crypto')
  486.  
  487. BigNumber.config({ CRYPTO: true })
  488. BigNumber.config().CRYPTO       // true
  489. BigNumber.random()              // 0.54340758610486147524</pre>
  490.       </dd>
  491.  
  492.  
  493.  
  494.       <dt id="modulo-mode"><code><b>MODULO_MODE</b></code></dt>
  495.       <dd>
  496.         <i>number</i>: integer, <code>0</code> to <code>9</code> inclusive<br />
  497.         Default value: <code>1</code> (<a href="#round-down"><code>ROUND_DOWN</code></a>)
  498.       </dd>
  499.       <dd>The modulo mode used when calculating the modulus: <code>a mod n</code>.</dd>
  500.       <dd>
  501.         The quotient, <code>q = a / n</code>, is calculated according to the
  502.         <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> that corresponds to the chosen
  503.         <code>MODULO_MODE</code>.
  504.       </dd>
  505.       <dd>The remainder, <code>r</code>, is calculated as: <code>r = a - n * q</code>.</dd>
  506.       <dd>
  507.         The modes that are most commonly used for the modulus/remainder operation are shown in
  508.         the following table. Although the other rounding modes can be used, they may not give
  509.         useful results.
  510.       </dd>
  511.       <dd>
  512.         <table>
  513.           <tr><th>Property</th><th>Value</th><th>Description</th></tr>
  514.           <tr>
  515.             <td><b>ROUND_UP</b></td><td class='centre'>0</td>
  516.             <td>
  517.               The remainder is positive if the dividend is negative, otherwise it is negative.
  518.             </td>
  519.           </tr>
  520.           <tr>
  521.             <td><b>ROUND_DOWN</b></td><td class='centre'>1</td>
  522.             <td>
  523.               The remainder has the same sign as the dividend.<br />
  524.               This uses 'truncating division' and matches the behaviour of JavaScript's
  525.              remainder operator <code>%</code>.
  526.            </td>
  527.          </tr>
  528.          <tr>
  529.            <td><b>ROUND_FLOOR</b></td><td class='centre'>3</td>
  530.            <td>
  531.              The remainder has the same sign as the divisor.<br />
  532.              This matches Python's <code>%</code> operator.
  533.             </td>
  534.           </tr>
  535.           <tr>
  536.             <td><b>ROUND_HALF_EVEN</b></td><td class='centre'>6</td>
  537.             <td>The <i>IEEE 754</i> remainder function.</td>
  538.           </tr>
  539.            <tr>
  540.              <td><b>EUCLID</b></td><td class='centre'>9</td>
  541.              <td>
  542.                The remainder is always positive. Euclidian division: <br />
  543.                <code>q = sign(n) * floor(a / abs(n))</code>
  544.              </td>
  545.            </tr>
  546.         </table>
  547.       </dd>
  548.       <dd>
  549.         The rounding/modulo modes are available as enumerated properties of the BigNumber
  550.         constructor.
  551.       </dd>
  552.       <dd>See <a href='#mod'><code>modulo</code></a>.</dd>
  553.       <dd>
  554.         <pre>BigNumber.config({ MODULO_MODE: BigNumber.EUCLID })
  555. BigNumber.config({ MODULO_MODE: 9 })          // equivalent</pre>
  556.       </dd>
  557.  
  558.  
  559.  
  560.       <dt id="pow-precision"><code><b>POW_PRECISION</b></code></dt>
  561.       <dd>
  562.         <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive.<br />
  563.         Default value: <code>0</code>
  564.       </dd>
  565.       <dd>
  566.         The <i>maximum</i> precision, i.e. number of significant digits, of the result of the power
  567.         operation (unless a modulus is specified).
  568.       </dd>
  569.       <dd>If set to <code>0</code>, the number of significant digits will not be limited.</dd>
  570.       <dd>See <a href='#pow'><code>exponentiatedBy</code></a>.</dd>
  571.       <dd><pre>BigNumber.config({ POW_PRECISION: 100 })</pre></dd>
  572.  
  573.  
  574.  
  575.       <dt id="format"><code><b>FORMAT</b></code></dt>
  576.       <dd><i>object</i></dd>
  577.       <dd>
  578.         The <code>FORMAT</code> object configures the format of the string returned by the
  579.         <a href='#toFor'><code>toFormat</code></a> method.
  580.       </dd>
  581.       <dd>
  582.         The example below shows the properties of the <code>FORMAT</code> object that are
  583.         recognised, and their default values.
  584.       </dd>
  585.       <dd>
  586.          Unlike the other configuration properties, the values of the properties of the
  587.          <code>FORMAT</code> object will not be checked for validity. The existing
  588.          <code>FORMAT</code> object will simply be replaced by the object that is passed in.
  589.          The object can include any number of the properties shown below.
  590.       </dd>
  591.       <dd>See <a href='#toFor'><code>toFormat</code></a> for examples of usage.</dd>
  592.       <dd>
  593.       <pre>
  594. BigNumber.config({
  595.   FORMAT: {
  596.     // string to prepend
  597.     prefix: '',
  598.     // decimal separator
  599.     decimalSeparator: '.',
  600.     // grouping separator of the integer part
  601.     groupSeparator: ',',
  602.     // primary grouping size of the integer part
  603.     groupSize: 3,
  604.     // secondary grouping size of the integer part
  605.     secondaryGroupSize: 0,
  606.     // grouping separator of the fraction part
  607.     fractionGroupSeparator: ' ',
  608.     // grouping size of the fraction part
  609.     fractionGroupSize: 0,
  610.     // string to append
  611.     suffix: ''
  612.   }
  613. });</pre>
  614.       </dd>
  615.  
  616.  
  617.  
  618.       <dt id="alphabet"><code><b>ALPHABET</b></code></dt>
  619.       <dd>
  620.         <i>string</i><br />
  621.         Default value: <code>'0123456789abcdefghijklmnopqrstuvwxyz'</code>
  622.       </dd>
  623.       <dd>
  624.         The alphabet used for base conversion. The length of the alphabet corresponds to the
  625.         maximum value of the base argument that can be passed to the
  626.         <a href='#bignumber'><code>BigNumber</code></a> constructor or
  627.         <a href='#toS'><code>toString</code></a>.
  628.       </dd>
  629.       <dd>
  630.         There is no maximum length for the alphabet, but it must be at least 2 characters long, and
  631.         it must not contain whitespace or a repeated character, or the sign indicators
  632.         <code>'+'</code> and <code>'-'</code>, or the decimal separator <code>'.'</code>.
  633.       </dd>
  634.       <dd>
  635.         <pre>// duodecimal (base 12)
  636. BigNumber.config({ ALPHABET: '0123456789TE' })
  637. x = new BigNumber('T', 12)
  638. x.toString()                // '10'
  639. x.toString(12)              // 'T'</pre>
  640.       </dd>
  641.  
  642.  
  643.  
  644.     </dl>
  645.     <br /><br />
  646.     <p>Returns an object with the above properties and their current values.</p>
  647.     <p>
  648.       Throws if <code>object</code> is not an object, or if an invalid value is assigned to
  649.       one or more of the above properties. See <a href='#Errors'>Errors</a>.
  650.     </p>
  651.     <pre>
  652. BigNumber.config({
  653.   DECIMAL_PLACES: 40,
  654.   ROUNDING_MODE: BigNumber.ROUND_HALF_CEIL,
  655.   EXPONENTIAL_AT: [-10, 20],
  656.   RANGE: [-500, 500],
  657.   CRYPTO: true,
  658.   MODULO_MODE: BigNumber.ROUND_FLOOR,
  659.   POW_PRECISION: 80,
  660.   FORMAT: {
  661.     groupSize: 3,
  662.     groupSeparator: ' ',
  663.     decimalSeparator: ','
  664.   },
  665.   ALPHABET: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
  666. });
  667.  
  668. obj = BigNumber.config();
  669. obj.DECIMAL_PLACES        // 40
  670. obj.RANGE                 // [-500, 500]</pre>
  671.  
  672.  
  673.  
  674.     <h5 id="isBigNumber">
  675.       isBigNumber<code class='inset'>.isBigNumber(value) <i>&rArr; boolean</i></code>
  676.     </h5>
  677.     <p><code>value</code>: <i>any</i><br /></p>
  678.     <p>
  679.       Returns <code>true</code> if <code>value</code> is a BigNumber instance, otherwise returns
  680.       <code>false</code>.
  681.     </p>
  682.     <pre>x = 42
  683. y = new BigNumber(x)
  684.  
  685. BigNumber.isBigNumber(x)             // false
  686. y instanceof BigNumber               // true
  687. BigNumber.isBigNumber(y)             // true
  688.  
  689. BN = BigNumber.clone();
  690. z = new BN(x)
  691. z instanceof BigNumber               // false
  692. BigNumber.isBigNumber(z)             // true</pre>
  693.     <p>
  694.       If <code>value</code> is a BigNumber instance and <code>BigNumber.DEBUG</code> is <code>true</code>,
  695.       then this method will also check if <code>value</code> is well-formed, and throw if it is not.
  696.       See <a href='#Errors'>Errors</a>.
  697.     </p>
  698.     <p>
  699.       The check can be useful if creating a BigNumber from an object literal.
  700.       See <a href='#bignumber'>BigNumber</a>.
  701.     </p>
  702.     <pre>
  703. x = new BigNumber(10)
  704.  
  705. // Change x.c to an illegitimate value.
  706. x.c = NaN
  707.  
  708. BigNumber.DEBUG = false
  709.  
  710. // No error.
  711. BigNumber.isBigNumber(x)    // true
  712.  
  713. BigNumber.DEBUG = true
  714.  
  715. // Error.
  716. BigNumber.isBigNumber(x)    // '[BigNumber Error] Invalid BigNumber'</pre>
  717.  
  718.  
  719.  
  720.     <h5 id="max">maximum<code class='inset'>.max(n...) <i>&rArr; BigNumber</i></code></h5>
  721.     <p>
  722.       <code>n</code>: <i>number|string|BigNumber</i><br />
  723.       <i>See <code><a href="#bignumber">BigNumber</a></code> for further parameter details.</i>
  724.     </p>
  725.     <p>
  726.       Returns a BigNumber whose value is the maximum of the arguments.
  727.     </p>
  728.     <p>The return value is always exact and unrounded.</p>
  729.     <pre>x = new BigNumber('3257869345.0378653')
  730. BigNumber.maximum(4e9, x, '123456789.9')      // '4000000000'
  731.  
  732. arr = [12, '13', new BigNumber(14)]
  733. BigNumber.max.apply(null, arr)                // '14'</pre>
  734.  
  735.  
  736.  
  737.     <h5 id="min">minimum<code class='inset'>.min(n...) <i>&rArr; BigNumber</i></code></h5>
  738.     <p>
  739.       <code>n</code>: <i>number|string|BigNumber</i><br />
  740.       <i>See <code><a href="#bignumber">BigNumber</a></code> for further parameter details.</i>
  741.     </p>
  742.     <p>
  743.       Returns a BigNumber whose value is the minimum of the arguments.
  744.     </p>
  745.     <p>The return value is always exact and unrounded.</p>
  746.     <pre>x = new BigNumber('3257869345.0378653')
  747. BigNumber.minimum(4e9, x, '123456789.9')      // '123456789.9'
  748.  
  749. arr = [2, new BigNumber(-14), '-15.9999', -12]
  750. BigNumber.min.apply(null, arr)                // '-15.9999'</pre>
  751.  
  752.  
  753.  
  754.     <h5 id="random">
  755.       random<code class='inset'>.random([dp]) <i>&rArr; BigNumber</i></code>
  756.     </h5>
  757.     <p><code>dp</code>: <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive</p>
  758.     <p>
  759.       Returns a new BigNumber with a pseudo-random value equal to or greater than <code>0</code> and
  760.       less than <code>1</code>.
  761.     </p>
  762.     <p>
  763.       The return value will have <code>dp</code> decimal places (or less if trailing zeros are
  764.       produced).<br />
  765.       If <code>dp</code> is omitted then the number of decimal places will default to the current
  766.       <a href='#decimal-places'><code>DECIMAL_PLACES</code></a> setting.
  767.     </p>
  768.     <p>
  769.       Depending on the value of this BigNumber constructor's
  770.      <a href='#crypto'><code>CRYPTO</code></a> setting and the support for the
  771.      <code>crypto</code> object in the host environment, the random digits of the return value are
  772.      generated by either <code>Math.random</code> (fastest), <code>crypto.getRandomValues</code>
  773.      (Web Cryptography API in recent browsers) or <code>crypto.randomBytes</code> (Node.js).
  774.    </p>
  775.    <p>
  776.      To be able to set <a href='#crypto'><code>CRYPTO</code></a> to <code>true</code> when using
  777.      Node.js, the <code>crypto</code> object must be available globally:
  778.    </p>
  779.    <pre>global.crypto = require('crypto')</pre>
  780.    <p>
  781.      If <a href='#crypto'><code>CRYPTO</code></a> is <code>true</code>, i.e. one of the
  782.      <code>crypto</code> methods is to be used, the value of a returned BigNumber should be
  783.      cryptographically-secure and statistically indistinguishable from a random value.
  784.    </p>
  785.    <p>
  786.      Throws if <code>dp</code> is invalid. See <a href='#Errors'>Errors</a>.
  787.    </p>
  788.    <pre>BigNumber.config({ DECIMAL_PLACES: 10 })
  789. BigNumber.random()              // '0.4117936847'
  790. BigNumber.random(20)            // '0.78193327636914089009'</pre>
  791.  
  792.  
  793.  
  794.    <h5 id="sum">sum<code class='inset'>.sum(n...) <i>&rArr; BigNumber</i></code></h5>
  795.    <p>
  796.      <code>n</code>: <i>number|string|BigNumber</i><br />
  797.      <i>See <code><a href="#bignumber">BigNumber</a></code> for further parameter details.</i>
  798.    </p>
  799.    <p>Returns a BigNumber whose value is the sum of the arguments.</p>
  800.    <p>The return value is always exact and unrounded.</p>
  801.    <pre>x = new BigNumber('3257869345.0378653')
  802. BigNumber.sum(4e9, x, '123456789.9')      // '7381326134.9378653'
  803.  
  804. arr = [2, new BigNumber(14), '15.9999', 12]
  805. BigNumber.sum.apply(null, arr)            // '43.9999'</pre>
  806.  
  807.  
  808.  
  809.    <h4 id="constructor-properties">Properties</h4>
  810.    <p>
  811.      The library's enumerated rounding modes are stored as properties of the constructor.<br />
  812.       (They are not referenced internally by the library itself.)
  813.     </p>
  814.     <p>
  815.       Rounding modes <code>0</code> to <code>6</code> (inclusive) are the same as those of Java's
  816.      BigDecimal class.
  817.    </p>
  818.    <table>
  819.      <tr>
  820.        <th>Property</th>
  821.        <th>Value</th>
  822.        <th>Description</th>
  823.      </tr>
  824.      <tr>
  825.        <td id="round-up"><b>ROUND_UP</b></td>
  826.        <td class='centre'>0</td>
  827.        <td>Rounds away from zero</td>
  828.      </tr>
  829.      <tr>
  830.        <td id="round-down"><b>ROUND_DOWN</b></td>
  831.        <td class='centre'>1</td>
  832.        <td>Rounds towards zero</td>
  833.      </tr>
  834.      <tr>
  835.        <td id="round-ceil"><b>ROUND_CEIL</b></td>
  836.        <td class='centre'>2</td>
  837.        <td>Rounds towards <code>Infinity</code></td>
  838.      </tr>
  839.      <tr>
  840.        <td id="round-floor"><b>ROUND_FLOOR</b></td>
  841.        <td class='centre'>3</td>
  842.        <td>Rounds towards <code>-Infinity</code></td>
  843.      </tr>
  844.      <tr>
  845.        <td id="round-half-up"><b>ROUND_HALF_UP</b></td>
  846.        <td class='centre'>4</td>
  847.        <td>
  848.          Rounds towards nearest neighbour.<br />
  849.          If equidistant, rounds away from zero
  850.        </td>
  851.      </tr>
  852.      <tr>
  853.        <td id="round-half-down"><b>ROUND_HALF_DOWN</b></td>
  854.        <td class='centre'>5</td>
  855.        <td>
  856.          Rounds towards nearest neighbour.<br />
  857.          If equidistant, rounds towards zero
  858.        </td>
  859.      </tr>
  860.      <tr>
  861.        <td id="round-half-even"><b>ROUND_HALF_EVEN</b></td>
  862.        <td class='centre'>6</td>
  863.        <td>
  864.          Rounds towards nearest neighbour.<br />
  865.          If equidistant, rounds towards even neighbour
  866.        </td>
  867.      </tr>
  868.      <tr>
  869.        <td id="round-half-ceil"><b>ROUND_HALF_CEIL</b></td>
  870.        <td class='centre'>7</td>
  871.        <td>
  872.          Rounds towards nearest neighbour.<br />
  873.          If equidistant, rounds towards <code>Infinity</code>
  874.        </td>
  875.      </tr>
  876.      <tr>
  877.        <td id="round-half-floor"><b>ROUND_HALF_FLOOR</b></td>
  878.        <td class='centre'>8</td>
  879.        <td>
  880.          Rounds towards nearest neighbour.<br />
  881.          If equidistant, rounds towards <code>-Infinity</code>
  882.        </td>
  883.      </tr>
  884.    </table>
  885.    <pre>
  886. BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_CEIL })
  887. BigNumber.config({ ROUNDING_MODE: 2 })     // equivalent</pre>
  888.  
  889.    <h5 id="debug">DEBUG</h5>
  890.    <p><i>undefined|false|true</i></p>
  891.    <p>
  892.      If <code>BigNumber.DEBUG</code> is set <code>true</code> then an error will be thrown
  893.      if this <a href='#bignumber'>BigNumber</a> constructor receives an invalid value, such as
  894.      a value of type <em>number</em> with more than <code>15</code> significant digits.
  895.      See <a href='#bignumber'>BigNumber</a>.
  896.    </p>
  897.    <p>
  898.      An error will also be thrown if the <code><a href='#isBigNumber'>isBigNumber</a></code>
  899.      method receives a BigNumber that is not well-formed.
  900.      See <code><a href='#isBigNumber'>isBigNumber</a></code>.
  901.    </p>
  902.    <pre>BigNumber.DEBUG = true</pre>
  903.  
  904.  
  905.    <h3>INSTANCE</h3>
  906.  
  907.  
  908.    <h4 id="prototype-methods">Methods</h4>
  909.    <p>The methods inherited by a BigNumber instance from its constructor's prototype object.</p>
  910.     <p>A BigNumber is immutable in the sense that it is not changed by its methods. </p>
  911.     <p>
  912.       The treatment of &plusmn;<code>0</code>, &plusmn;<code>Infinity</code> and <code>NaN</code> is
  913.       consistent with how JavaScript treats these values.
  914.     </p>
  915.     <p>Many method names have a shorter alias.</p>
  916.  
  917.  
  918.  
  919.     <h5 id="abs">absoluteValue<code class='inset'>.abs() <i>&rArr; BigNumber</i></code></h5>
  920.     <p>
  921.       Returns a BigNumber whose value is the absolute value, i.e. the magnitude, of the value of
  922.       this BigNumber.
  923.     </p>
  924.     <p>The return value is always exact and unrounded.</p>
  925.     <pre>
  926. x = new BigNumber(-0.8)
  927. y = x.absoluteValue()           // '0.8'
  928. z = y.abs()                     // '0.8'</pre>
  929.  
  930.  
  931.  
  932.     <h5 id="cmp">
  933.       comparedTo<code class='inset'>.comparedTo(n [, base]) <i>&rArr; number</i></code>
  934.     </h5>
  935.     <p>
  936.       <code>n</code>: <i>number|string|BigNumber</i><br />
  937.       <code>base</code>: <i>number</i><br />
  938.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  939.     </p>
  940.     <table>
  941.       <tr><th>Returns</th><th>&nbsp;</th></tr>
  942.       <tr>
  943.         <td class='centre'><code>1</code></td>
  944.         <td>If the value of this BigNumber is greater than the value of <code>n</code></td>
  945.       </tr>
  946.       <tr>
  947.         <td class='centre'><code>-1</code></td>
  948.         <td>If the value of this BigNumber is less than the value of <code>n</code></td>
  949.       </tr>
  950.       <tr>
  951.         <td class='centre'><code>0</code></td>
  952.         <td>If this BigNumber and <code>n</code> have the same value</td>
  953.       </tr>
  954.        <tr>
  955.         <td class='centre'><code>null</code></td>
  956.         <td>If the value of either this BigNumber or <code>n</code> is <code>NaN</code></td>
  957.       </tr>
  958.     </table>
  959.     <pre>
  960. x = new BigNumber(Infinity)
  961. y = new BigNumber(5)
  962. x.comparedTo(y)                 // 1
  963. x.comparedTo(x.minus(1))        // 0
  964. y.comparedTo(NaN)               // null
  965. y.comparedTo('110', 2)          // -1</pre>
  966.  
  967.  
  968.  
  969.     <h5 id="dp">
  970.       decimalPlaces<code class='inset'>.dp([dp [, rm]]) <i>&rArr; BigNumber|number</i></code>
  971.     </h5>
  972.     <p>
  973.       <code>dp</code>: <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive<br />
  974.       <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive
  975.     </p>
  976.     <p>
  977.       If <code>dp</code> is a number, returns a BigNumber whose value is the value of this BigNumber
  978.       rounded by rounding mode <code>rm</code> to a maximum of <code>dp</code> decimal places.
  979.     </p>
  980.     <p>
  981.       If <code>dp</code> is omitted, or is <code>null</code> or <code>undefined</code>, the return
  982.       value is the number of decimal places of the value of this BigNumber, or <code>null</code> if
  983.       the value of this BigNumber is &plusmn;<code>Infinity</code> or <code>NaN</code>.
  984.     </p>
  985.     <p>
  986.       If <code>rm</code> is omitted, or is <code>null</code> or <code>undefined</code>,
  987.       <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.
  988.     </p>
  989.     <p>
  990.       Throws if <code>dp</code> or <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
  991.     </p>
  992.     <pre>
  993. x = new BigNumber(1234.56)
  994. x.decimalPlaces(1)                     // '1234.6'
  995. x.dp()                                 // 2
  996. x.decimalPlaces(2)                     // '1234.56'
  997. x.dp(10)                               // '1234.56'
  998. x.decimalPlaces(0, 1)                  // '1234'
  999. x.dp(0, 6)                             // '1235'
  1000. x.decimalPlaces(1, 1)                  // '1234.5'
  1001. x.dp(1, BigNumber.ROUND_HALF_EVEN)     // '1234.6'
  1002. x                                      // '1234.56'
  1003. y = new BigNumber('9.9e-101')
  1004. y.dp()                                 // 102</pre>
  1005.  
  1006.  
  1007.  
  1008.     <h5 id="div">dividedBy<code class='inset'>.div(n [, base]) <i>&rArr; BigNumber</i></code>
  1009.     </h5>
  1010.     <p>
  1011.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1012.       <code>base</code>: <i>number</i><br />
  1013.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1014.     </p>
  1015.     <p>
  1016.       Returns a BigNumber whose value is the value of this BigNumber divided by
  1017.       <code>n</code>, rounded according to the current
  1018.       <a href='#decimal-places'><code>DECIMAL_PLACES</code></a> and
  1019.       <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> settings.
  1020.     </p>
  1021.     <pre>
  1022. x = new BigNumber(355)
  1023. y = new BigNumber(113)
  1024. x.dividedBy(y)                  // '3.14159292035398230088'
  1025. x.div(5)                        // '71'
  1026. x.div(47, 16)                   // '5'</pre>
  1027.  
  1028.  
  1029.  
  1030.     <h5 id="divInt">
  1031.       dividedToIntegerBy<code class='inset'>.idiv(n [, base]) &rArr;
  1032.       <i>BigNumber</i></code>
  1033.     </h5>
  1034.     <p>
  1035.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1036.       <code>base</code>: <i>number</i><br />
  1037.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1038.     </p>
  1039.     <p>
  1040.       Returns a BigNumber whose value is the integer part of dividing the value of this BigNumber by
  1041.       <code>n</code>.
  1042.     </p>
  1043.     <pre>
  1044. x = new BigNumber(5)
  1045. y = new BigNumber(3)
  1046. x.dividedToIntegerBy(y)         // '1'
  1047. x.idiv(0.7)                     // '7'
  1048. x.idiv('0.f', 16)               // '5'</pre>
  1049.  
  1050.  
  1051.  
  1052.     <h5 id="pow">
  1053.       exponentiatedBy<code class='inset'>.pow(n [, m]) <i>&rArr; BigNumber</i></code>
  1054.     </h5>
  1055.     <p>
  1056.       <code>n</code>: <i>number|string|BigNumber</i>: integer<br />
  1057.       <code>m</code>: <i>number|string|BigNumber</i>
  1058.     </p>
  1059.     <p>
  1060.       Returns a BigNumber whose value is the value of this BigNumber exponentiated by
  1061.       <code>n</code>, i.e. raised to the power <code>n</code>, and optionally modulo a modulus
  1062.       <code>m</code>.
  1063.     </p>
  1064.     <p>
  1065.       Throws if <code>n</code> is not an integer. See <a href='#Errors'>Errors</a>.
  1066.     </p>
  1067.     <p>
  1068.       If <code>n</code> is negative the result is rounded according to the current
  1069.       <a href='#decimal-places'><code>DECIMAL_PLACES</code></a> and
  1070.       <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> settings.
  1071.     </p>
  1072.     <p>
  1073.       As the number of digits of the result of the power operation can grow so large so quickly,
  1074.       e.g. 123.456<sup>10000</sup> has over <code>50000</code> digits, the number of significant
  1075.       digits calculated is limited to the value of the
  1076.       <a href='#pow-precision'><code>POW_PRECISION</code></a> setting (unless a modulus
  1077.       <code>m</code> is specified).
  1078.     </p>
  1079.     <p>
  1080.       By default <a href='#pow-precision'><code>POW_PRECISION</code></a> is set to <code>0</code>.
  1081.       This means that an unlimited number of significant digits will be calculated, and that the
  1082.       method's performance will decrease dramatically for larger exponents.
  1083.    </p>
  1084.    <p>
  1085.      If <code>m</code> is specified and the value of <code>m</code>, <code>n</code> and this
  1086.      BigNumber are integers, and <code>n</code> is positive, then a fast modular exponentiation
  1087.      algorithm is used, otherwise the operation will be performed as
  1088.      <code>x.exponentiatedBy(n).modulo(m)</code> with a
  1089.      <a href='#pow-precision'><code>POW_PRECISION</code></a> of <code>0</code>.
  1090.    </p>
  1091.    <pre>
  1092. Math.pow(0.7, 2)                // 0.48999999999999994
  1093. x = new BigNumber(0.7)
  1094. x.exponentiatedBy(2)            // '0.49'
  1095. BigNumber(3).pow(-2)            // '0.11111111111111111111'</pre>
  1096.  
  1097.  
  1098.  
  1099.    <h5 id="int">
  1100.      integerValue<code class='inset'>.integerValue([rm]) <i>&rArr; BigNumber</i></code>
  1101.    </h5>
  1102.    <p>
  1103.      <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive
  1104.    </p>
  1105.   <p>
  1106.      Returns a BigNumber whose value is the value of this BigNumber rounded to an integer using
  1107.      rounding mode <code>rm</code>.
  1108.    </p>
  1109.    <p>
  1110.      If <code>rm</code> is omitted, or is <code>null</code> or <code>undefined</code>,
  1111.      <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.
  1112.    </p>
  1113.    <p>
  1114.      Throws if <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
  1115.    </p>
  1116.    <pre>
  1117. x = new BigNumber(123.456)
  1118. x.integerValue()                        // '123'
  1119. x.integerValue(BigNumber.ROUND_CEIL)    // '124'
  1120. y = new BigNumber(-12.7)
  1121. y.integerValue()                        // '-13'
  1122. y.integerValue(BigNumber.ROUND_DOWN)    // '-12'</pre>
  1123.    <p>
  1124.      The following is an example of how to add a prototype method that emulates JavaScript's
  1125.       <code>Math.round</code> function. <code>Math.ceil</code>, <code>Math.floor</code> and
  1126.       <code>Math.trunc</code> can be emulated in the same way with
  1127.       <code>BigNumber.ROUND_CEIL</code>, <code>BigNumber.ROUND_FLOOR</code> and
  1128.       <code> BigNumber.ROUND_DOWN</code> respectively.
  1129.     </p>
  1130.     <pre>
  1131. BigNumber.prototype.round = function (n) {
  1132.   return n.integerValue(BigNumber.ROUND_HALF_CEIL);
  1133. };
  1134. x.round()                               // '123'</pre>
  1135.  
  1136.  
  1137.  
  1138.     <h5 id="eq">isEqualTo<code class='inset'>.eq(n [, base]) <i>&rArr; boolean</i></code></h5>
  1139.     <p>
  1140.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1141.       <code>base</code>: <i>number</i><br />
  1142.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1143.     </p>
  1144.     <p>
  1145.       Returns <code>true</code> if the value of this BigNumber is equal to the value of
  1146.       <code>n</code>, otherwise returns <code>false</code>.<br />
  1147.       As with JavaScript, <code>NaN</code> does not equal <code>NaN</code>.
  1148.     </p>
  1149.     <p>Note: This method uses the <a href='#cmp'><code>comparedTo</code></a> method internally.</p>
  1150.     <pre>
  1151. 0 === 1e-324                    // true
  1152. x = new BigNumber(0)
  1153. x.isEqualTo('1e-324')           // false
  1154. BigNumber(-0).eq(x)             // true  ( -0 === 0 )
  1155. BigNumber(255).eq('ff', 16)     // true
  1156.  
  1157. y = new BigNumber(NaN)
  1158. y.isEqualTo(NaN)                // false</pre>
  1159.  
  1160.  
  1161.  
  1162.     <h5 id="isF">isFinite<code class='inset'>.isFinite() <i>&rArr; boolean</i></code></h5>
  1163.     <p>
  1164.       Returns <code>true</code> if the value of this BigNumber is a finite number, otherwise
  1165.       returns <code>false</code>.
  1166.     </p>
  1167.     <p>
  1168.       The only possible non-finite values of a BigNumber are <code>NaN</code>, <code>Infinity</code>
  1169.       and <code>-Infinity</code>.
  1170.     </p>
  1171.     <pre>
  1172. x = new BigNumber(1)
  1173. x.isFinite()                    // true
  1174. y = new BigNumber(Infinity)
  1175. y.isFinite()                    // false</pre>
  1176.     <p>
  1177.       Note: The native method <code>isFinite()</code> can be used if
  1178.       <code>n &lt;= Number.MAX_VALUE</code>.
  1179.     </p>
  1180.  
  1181.  
  1182.  
  1183.     <h5 id="gt">isGreaterThan<code class='inset'>.gt(n [, base]) <i>&rArr; boolean</i></code></h5>
  1184.     <p>
  1185.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1186.       <code>base</code>: <i>number</i><br />
  1187.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1188.     </p>
  1189.     <p>
  1190.       Returns <code>true</code> if the value of this BigNumber is greater than the value of
  1191.       <code>n</code>, otherwise returns <code>false</code>.
  1192.     </p>
  1193.     <p>Note: This method uses the <a href='#cmp'><code>comparedTo</code></a> method internally.</p>
  1194.     <pre>
  1195. 0.1 &gt; (0.3 - 0.2)                             // true
  1196. x = new BigNumber(0.1)
  1197. x.isGreaterThan(BigNumber(0.3).minus(0.2))    // false
  1198. BigNumber(0).gt(x)                            // false
  1199. BigNumber(11, 3).gt(11.1, 2)                  // true</pre>
  1200.  
  1201.  
  1202.  
  1203.     <h5 id="gte">
  1204.       isGreaterThanOrEqualTo<code class='inset'>.gte(n [, base]) <i>&rArr; boolean</i></code>
  1205.     </h5>
  1206.     <p>
  1207.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1208.       <code>base</code>: <i>number</i><br />
  1209.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1210.     </p>
  1211.     <p>
  1212.       Returns <code>true</code> if the value of this BigNumber is greater than or equal to the value
  1213.       of <code>n</code>, otherwise returns <code>false</code>.
  1214.     </p>
  1215.     <p>Note: This method uses the <a href='#cmp'><code>comparedTo</code></a> method internally.</p>
  1216.     <pre>
  1217. (0.3 - 0.2) &gt;= 0.1                     // false
  1218. x = new BigNumber(0.3).minus(0.2)
  1219. x.isGreaterThanOrEqualTo(0.1)          // true
  1220. BigNumber(1).gte(x)                    // true
  1221. BigNumber(10, 18).gte('i', 36)         // true</pre>
  1222.  
  1223.  
  1224.  
  1225.     <h5 id="isInt">isInteger<code class='inset'>.isInteger() <i>&rArr; boolean</i></code></h5>
  1226.     <p>
  1227.       Returns <code>true</code> if the value of this BigNumber is an integer, otherwise returns
  1228.       <code>false</code>.
  1229.     </p>
  1230.     <pre>
  1231. x = new BigNumber(1)
  1232. x.isInteger()                   // true
  1233. y = new BigNumber(123.456)
  1234. y.isInteger()                   // false</pre>
  1235.  
  1236.  
  1237.  
  1238.     <h5 id="lt">isLessThan<code class='inset'>.lt(n [, base]) <i>&rArr; boolean</i></code></h5>
  1239.     <p>
  1240.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1241.       <code>base</code>: <i>number</i><br />
  1242.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1243.     </p>
  1244.     <p>
  1245.       Returns <code>true</code> if the value of this BigNumber is less than the value of
  1246.       <code>n</code>, otherwise returns <code>false</code>.
  1247.     </p>
  1248.      <p>Note: This method uses the <a href='#cmp'><code>comparedTo</code></a> method internally.</p>
  1249.     <pre>
  1250. (0.3 - 0.2) &lt; 0.1                       // true
  1251. x = new BigNumber(0.3).minus(0.2)
  1252. x.isLessThan(0.1)                       // false
  1253. BigNumber(0).lt(x)                      // true
  1254. BigNumber(11.1, 2).lt(11, 3)            // true</pre>
  1255.  
  1256.  
  1257.  
  1258.     <h5 id="lte">
  1259.       isLessThanOrEqualTo<code class='inset'>.lte(n [, base]) <i>&rArr; boolean</i></code>
  1260.     </h5>
  1261.     <p>
  1262.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1263.       <code>base</code>: <i>number</i><br />
  1264.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1265.     </p>
  1266.     <p>
  1267.       Returns <code>true</code> if the value of this BigNumber is less than or equal to the value of
  1268.       <code>n</code>, otherwise returns <code>false</code>.
  1269.     </p>
  1270.     <p>Note: This method uses the <a href='#cmp'><code>comparedTo</code></a> method internally.</p>
  1271.     <pre>
  1272. 0.1 &lt;= (0.3 - 0.2)                                // false
  1273. x = new BigNumber(0.1)
  1274. x.isLessThanOrEqualTo(BigNumber(0.3).minus(0.2))  // true
  1275. BigNumber(-1).lte(x)                              // true
  1276. BigNumber(10, 18).lte('i', 36)                    // true</pre>
  1277.  
  1278.  
  1279.  
  1280.     <h5 id="isNaN">isNaN<code class='inset'>.isNaN() <i>&rArr; boolean</i></code></h5>
  1281.     <p>
  1282.       Returns <code>true</code> if the value of this BigNumber is <code>NaN</code>, otherwise
  1283.       returns <code>false</code>.
  1284.     </p>
  1285.     <pre>
  1286. x = new BigNumber(NaN)
  1287. x.isNaN()                       // true
  1288. y = new BigNumber('Infinity')
  1289. y.isNaN()                       // false</pre>
  1290.     <p>Note: The native method <code>isNaN()</code> can also be used.</p>
  1291.  
  1292.  
  1293.  
  1294.     <h5 id="isNeg">isNegative<code class='inset'>.isNegative() <i>&rArr; boolean</i></code></h5>
  1295.     <p>
  1296.       Returns <code>true</code> if the sign of this BigNumber is negative, otherwise returns
  1297.       <code>false</code>.
  1298.     </p>
  1299.     <pre>
  1300. x = new BigNumber(-0)
  1301. x.isNegative()                  // true
  1302. y = new BigNumber(2)
  1303. y.isNegative()                  // false</pre>
  1304.     <p>Note: <code>n &lt; 0</code> can be used if <code>n &lt;= -Number.MIN_VALUE</code>.</p>
  1305.  
  1306.  
  1307.  
  1308.     <h5 id="isPos">isPositive<code class='inset'>.isPositive() <i>&rArr; boolean</i></code></h5>
  1309.     <p>
  1310.       Returns <code>true</code> if the sign of this BigNumber is positive, otherwise returns
  1311.       <code>false</code>.
  1312.     </p>
  1313.     <pre>
  1314. x = new BigNumber(-0)
  1315. x.isPositive()                  // false
  1316. y = new BigNumber(2)
  1317. y.isPositive()                  // true</pre>
  1318.  
  1319.  
  1320.  
  1321.     <h5 id="isZ">isZero<code class='inset'>.isZero() <i>&rArr; boolean</i></code></h5>
  1322.     <p>
  1323.       Returns <code>true</code> if the value of this BigNumber is zero or minus zero, otherwise
  1324.       returns <code>false</code>.
  1325.     </p>
  1326.     <pre>
  1327. x = new BigNumber(-0)
  1328. x.isZero() &amp;&amp; x.isNegative()         // true
  1329. y = new BigNumber(Infinity)
  1330. y.isZero()                      // false</pre>
  1331.     <p>Note: <code>n == 0</code> can be used if <code>n &gt;= Number.MIN_VALUE</code>.</p>
  1332.  
  1333.  
  1334.  
  1335.     <h5 id="minus">
  1336.       minus<code class='inset'>.minus(n [, base]) <i>&rArr; BigNumber</i></code>
  1337.     </h5>
  1338.     <p>
  1339.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1340.       <code>base</code>: <i>number</i><br />
  1341.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1342.     </p>
  1343.     <p>Returns a BigNumber whose value is the value of this BigNumber minus <code>n</code>.</p>
  1344.     <p>The return value is always exact and unrounded.</p>
  1345.     <pre>
  1346. 0.3 - 0.1                       // 0.19999999999999998
  1347. x = new BigNumber(0.3)
  1348. x.minus(0.1)                    // '0.2'
  1349. x.minus(0.6, 20)                // '0'</pre>
  1350.  
  1351.  
  1352.  
  1353.     <h5 id="mod">modulo<code class='inset'>.mod(n [, base]) <i>&rArr; BigNumber</i></code></h5>
  1354.     <p>
  1355.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1356.       <code>base</code>: <i>number</i><br />
  1357.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1358.     </p>
  1359.     <p>
  1360.       Returns a BigNumber whose value is the value of this BigNumber modulo <code>n</code>, i.e.
  1361.       the integer remainder of dividing this BigNumber by <code>n</code>.
  1362.     </p>
  1363.     <p>
  1364.       The value returned, and in particular its sign, is dependent on the value of the
  1365.       <a href='#modulo-mode'><code>MODULO_MODE</code></a> setting of this BigNumber constructor.
  1366.       If it is <code>1</code> (default value), the result will have the same sign as this BigNumber,
  1367.       and it will match that of Javascript's <code>%</code> operator (within the limits of double
  1368.      precision) and BigDecimal's <code>remainder</code> method.
  1369.     </p>
  1370.     <p>The return value is always exact and unrounded.</p>
  1371.     <p>
  1372.       See <a href='#modulo-mode'><code>MODULO_MODE</code></a> for a description of the other
  1373.       modulo modes.
  1374.     </p>
  1375.     <pre>
  1376. 1 % 0.9                         // 0.09999999999999998
  1377. x = new BigNumber(1)
  1378. x.modulo(0.9)                   // '0.1'
  1379. y = new BigNumber(33)
  1380. y.mod('a', 33)                  // '3'</pre>
  1381.  
  1382.  
  1383.  
  1384.     <h5 id="times">
  1385.       multipliedBy<code class='inset'>.times(n [, base]) <i>&rArr; BigNumber</i></code>
  1386.     </h5>
  1387.     <p>
  1388.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1389.       <code>base</code>: <i>number</i><br />
  1390.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1391.     </p>
  1392.     <p>
  1393.       Returns a BigNumber whose value is the value of this BigNumber multiplied by <code>n</code>.
  1394.     </p>
  1395.     <p>The return value is always exact and unrounded.</p>
  1396.     <pre>
  1397. 0.6 * 3                         // 1.7999999999999998
  1398. x = new BigNumber(0.6)
  1399. y = x.multipliedBy(3)           // '1.8'
  1400. BigNumber('7e+500').times(y)    // '1.26e+501'
  1401. x.multipliedBy('-a', 16)        // '-6'</pre>
  1402.  
  1403.  
  1404.  
  1405.     <h5 id="neg">negated<code class='inset'>.negated() <i>&rArr; BigNumber</i></code></h5>
  1406.     <p>
  1407.       Returns a BigNumber whose value is the value of this BigNumber negated, i.e. multiplied by
  1408.       <code>-1</code>.
  1409.     </p>
  1410.     <pre>
  1411. x = new BigNumber(1.8)
  1412. x.negated()                     // '-1.8'
  1413. y = new BigNumber(-1.3)
  1414. y.negated()                     // '1.3'</pre>
  1415.  
  1416.  
  1417.  
  1418.     <h5 id="plus">plus<code class='inset'>.plus(n [, base]) <i>&rArr; BigNumber</i></code></h5>
  1419.     <p>
  1420.       <code>n</code>: <i>number|string|BigNumber</i><br />
  1421.       <code>base</code>: <i>number</i><br />
  1422.       <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
  1423.     </p>
  1424.     <p>Returns a BigNumber whose value is the value of this BigNumber plus <code>n</code>.</p>
  1425.     <p>The return value is always exact and unrounded.</p>
  1426.     <pre>
  1427. 0.1 + 0.2                       // 0.30000000000000004
  1428. x = new BigNumber(0.1)
  1429. y = x.plus(0.2)                 // '0.3'
  1430. BigNumber(0.7).plus(x).plus(y)  // '1.1'
  1431. x.plus('0.1', 8)                // '0.225'</pre>
  1432.  
  1433.  
  1434.  
  1435.     <h5 id="sd">
  1436.       precision<code class='inset'>.sd([d [, rm]]) <i>&rArr; BigNumber|number</i></code>
  1437.     </h5>
  1438.     <p>
  1439.       <code>d</code>: <i>number|boolean</i>: integer, <code>1</code> to <code>1e+9</code>
  1440.       inclusive, or <code>true</code> or <code>false</code><br />
  1441.       <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive.
  1442.     </p>
  1443.     <p>
  1444.       If <code>d</code> is a number, returns a BigNumber whose value is the value of this BigNumber
  1445.       rounded to a precision of <code>d</code> significant digits using rounding mode
  1446.       <code>rm</code>.
  1447.     </p>
  1448.     <p>
  1449.       If <code>d</code> is omitted or is <code>null</code> or <code>undefined</code>, the return
  1450.       value is the number of significant digits of the value of this BigNumber, or <code>null</code>
  1451.       if the value of this BigNumber is &plusmn;<code>Infinity</code> or <code>NaN</code>.
  1452.     </p>
  1453.     <p>
  1454.       If <code>d</code> is <code>true</code> then any trailing zeros of the integer
  1455.       part of a number are counted as significant digits, otherwise they are not.
  1456.     </p>
  1457.     <p>
  1458.       If <code>rm</code> is omitted or is <code>null</code> or <code>undefined</code>,
  1459.       <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> will be used.
  1460.     </p>
  1461.     <p>
  1462.       Throws if <code>d</code> or <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
  1463.     </p>
  1464.     <pre>
  1465. x = new BigNumber(9876.54321)
  1466. x.precision(6)                         // '9876.54'
  1467. x.sd()                                 // 9
  1468. x.precision(6, BigNumber.ROUND_UP)     // '9876.55'
  1469. x.sd(2)                                // '9900'
  1470. x.precision(2, 1)                      // '9800'
  1471. x                                      // '9876.54321'
  1472. y = new BigNumber(987000)
  1473. y.precision()                          // 3
  1474. y.sd(true)                             // 6</pre>
  1475.  
  1476.  
  1477.  
  1478. <h5 id="shift">shiftedBy<code class='inset'>.shiftedBy(n) <i>&rArr; BigNumber</i></code></h5>
  1479.     <p>
  1480.       <code>n</code>: <i>number</i>: integer,
  1481.       <code>-9007199254740991</code> to <code>9007199254740991</code> inclusive
  1482.     </p>
  1483.     <p>
  1484.       Returns a BigNumber whose value is the value of this BigNumber shifted by <code>n</code>
  1485.       places.
  1486.     <p>
  1487.       The shift is of the decimal point, i.e. of powers of ten, and is to the left if <code>n</code>
  1488.       is negative or to the right if <code>n</code> is positive.
  1489.     </p>
  1490.     <p>The return value is always exact and unrounded.</p>
  1491.     <p>
  1492.       Throws if <code>n</code> is invalid. See <a href='#Errors'>Errors</a>.
  1493.     </p>
  1494.     <pre>
  1495. x = new BigNumber(1.23)
  1496. x.shiftedBy(3)                      // '1230'
  1497. x.shiftedBy(-3)                     // '0.00123'</pre>
  1498.  
  1499.  
  1500.  
  1501.     <h5 id="sqrt">squareRoot<code class='inset'>.sqrt() <i>&rArr; BigNumber</i></code></h5>
  1502.     <p>
  1503.       Returns a BigNumber whose value is the square root of the value of this BigNumber,
  1504.       rounded according to the current
  1505.       <a href='#decimal-places'><code>DECIMAL_PLACES</code></a> and
  1506.       <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> settings.
  1507.     </p>
  1508.     <p>
  1509.       The return value will be correctly rounded, i.e. rounded as if the result was first calculated
  1510.       to an infinite number of correct digits before rounding.
  1511.     </p>
  1512.     <pre>
  1513. x = new BigNumber(16)
  1514. x.squareRoot()                  // '4'
  1515. y = new BigNumber(3)
  1516. y.sqrt()                        // '1.73205080756887729353'</pre>
  1517.  
  1518.  
  1519.  
  1520.     <h5 id="toE">
  1521.       toExponential<code class='inset'>.toExponential([dp [, rm]]) <i>&rArr; string</i></code>
  1522.     </h5>
  1523.     <p>
  1524.       <code>dp</code>: <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive<br />
  1525.       <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive
  1526.     </p>
  1527.     <p>
  1528.       Returns a string representing the value of this BigNumber in exponential notation rounded
  1529.       using rounding mode <code>rm</code> to <code>dp</code> decimal places, i.e with one digit
  1530.       before the decimal point and <code>dp</code> digits after it.
  1531.     </p>
  1532.     <p>
  1533.       If the value of this BigNumber in exponential notation has fewer than <code>dp</code> fraction
  1534.       digits, the return value will be appended with zeros accordingly.
  1535.     </p>
  1536.     <p>
  1537.       If <code>dp</code> is omitted, or is <code>null</code> or <code>undefined</code>, the number
  1538.       of digits after the decimal point defaults to the minimum number of digits necessary to
  1539.       represent the value exactly.<br />
  1540.       If <code>rm</code> is omitted or is <code>null</code> or <code>undefined</code>,
  1541.       <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.
  1542.     </p>
  1543.     <p>
  1544.       Throws if <code>dp</code> or <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
  1545.     </p>
  1546.      <pre>
  1547. x = 45.6
  1548. y = new BigNumber(x)
  1549. x.toExponential()               // '4.56e+1'
  1550. y.toExponential()               // '4.56e+1'
  1551. x.toExponential(0)              // '5e+1'
  1552. y.toExponential(0)              // '5e+1'
  1553. x.toExponential(1)              // '4.6e+1'
  1554. y.toExponential(1)              // '4.6e+1'
  1555. y.toExponential(1, 1)           // '4.5e+1'  (ROUND_DOWN)
  1556. x.toExponential(3)              // '4.560e+1'
  1557. y.toExponential(3)              // '4.560e+1'</pre>
  1558.  
  1559.  
  1560.  
  1561.     <h5 id="toFix">
  1562.       toFixed<code class='inset'>.toFixed([dp [, rm]]) <i>&rArr; string</i></code>
  1563.     </h5>
  1564.     <p>
  1565.       <code>dp</code>: <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive<br />
  1566.       <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive
  1567.     </p>
  1568.     <p>
  1569.       Returns a string representing the value of this BigNumber in normal (fixed-point) notation
  1570.       rounded to <code>dp</code> decimal places using rounding mode <code>rm</code>.
  1571.     </p>
  1572.     <p>
  1573.       If the value of this BigNumber in normal notation has fewer than <code>dp</code> fraction
  1574.       digits, the return value will be appended with zeros accordingly.
  1575.     </p>
  1576.    <p>
  1577.       Unlike <code>Number.prototype.toFixed</code>, which returns exponential notation if a number
  1578.       is greater or equal to <code>10<sup>21</sup></code>, this method will always return normal
  1579.       notation.
  1580.     </p>
  1581.     <p>
  1582.       If <code>dp</code> is omitted or is <code>null</code> or <code>undefined</code>, the return
  1583.       value will be unrounded and in normal notation. This is also unlike
  1584.       <code>Number.prototype.toFixed</code>, which returns the value to zero decimal places.<br />
  1585.       It is useful when fixed-point notation is required and the current
  1586.       <a href="#exponential-at"><code>EXPONENTIAL_AT</code></a> setting causes
  1587.       <code><a href='#toS'>toString</a></code> to return exponential notation.<br />
  1588.       If <code>rm</code> is omitted or is <code>null</code> or <code>undefined</code>,
  1589.       <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.
  1590.     </p>
  1591.     <p>
  1592.       Throws if <code>dp</code> or <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
  1593.     </p>
  1594.     <pre>
  1595. x = 3.456
  1596. y = new BigNumber(x)
  1597. x.toFixed()                     // '3'
  1598. y.toFixed()                     // '3.456'
  1599. y.toFixed(0)                    // '3'
  1600. x.toFixed(2)                    // '3.46'
  1601. y.toFixed(2)                    // '3.46'
  1602. y.toFixed(2, 1)                 // '3.45'  (ROUND_DOWN)
  1603. x.toFixed(5)                    // '3.45600'
  1604. y.toFixed(5)                    // '3.45600'</pre>
  1605.  
  1606.  
  1607.  
  1608.     <h5 id="toFor">
  1609.       toFormat<code class='inset'>.toFormat([dp [, rm[, format]]]) <i>&rArr; string</i></code>
  1610.     </h5>
  1611.     <p>
  1612.       <code>dp</code>: <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive<br />
  1613.       <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive<br />
  1614.       <code>format</code>: <i>object</i>: see <a href='#format'><code>FORMAT</code></a>
  1615.     </p>
  1616.     <p>
  1617.       <p>
  1618.       Returns a string representing the value of this BigNumber in normal (fixed-point) notation
  1619.       rounded to <code>dp</code> decimal places using rounding mode <code>rm</code>, and formatted
  1620.       according to the properties of the <code>format</code> object.
  1621.     </p>
  1622.     <p>
  1623.       See <a href='#format'><code>FORMAT</code></a> and the examples below for the properties of the
  1624.       <code>format</code> object, their types, and their usage. A formatting object may contain
  1625.       some or all of the recognised properties.
  1626.     </p>
  1627.     <p>
  1628.       If <code>dp</code> is omitted or is <code>null</code> or <code>undefined</code>, then the
  1629.       return value is not rounded to a fixed number of decimal places.<br />
  1630.       If <code>rm</code> is omitted or is <code>null</code> or <code>undefined</code>,
  1631.       <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.<br />
  1632.       If <code>format</code> is omitted or is <code>null</code> or <code>undefined</code>, the
  1633.       <a href='#format'><code>FORMAT</code></a> object is used.
  1634.     </p>
  1635.     <p>
  1636.       Throws if <code>dp</code>, <code>rm</code> or <code>format</code> is invalid. See
  1637.       <a href='#Errors'>Errors</a>.
  1638.     </p>
  1639.     <pre>
  1640. fmt = {
  1641.   prefix: '',
  1642.   decimalSeparator: '.',
  1643.   groupSeparator: ',',
  1644.   groupSize: 3,
  1645.   secondaryGroupSize: 0,
  1646.   fractionGroupSeparator: ' ',
  1647.   fractionGroupSize: 0,
  1648.   suffix: ''
  1649. }
  1650.  
  1651. x = new BigNumber('123456789.123456789')
  1652.  
  1653. // Set the global formatting options
  1654. BigNumber.config({ FORMAT: fmt })
  1655.  
  1656. x.toFormat()                              // '123,456,789.123456789'
  1657. x.toFormat(3)                             // '123,456,789.123'
  1658.  
  1659. // If a reference to the object assigned to FORMAT has been retained,
  1660. // the format properties can be changed directly
  1661. fmt.groupSeparator = ' '
  1662. fmt.fractionGroupSize = 5
  1663. x.toFormat()                              // '123 456 789.12345 6789'
  1664.  
  1665. // Alternatively, pass the formatting options as an argument
  1666. fmt = {
  1667.   prefix: '=> ',
  1668.   decimalSeparator: ',',
  1669.   groupSeparator: '.',
  1670.   groupSize: 3,
  1671.   secondaryGroupSize: 2
  1672. }
  1673.  
  1674. x.toFormat()                              // '123 456 789.12345 6789'
  1675. x.toFormat(fmt)                           // '=> 12.34.56.789,123456789'
  1676. x.toFormat(2, fmt)                        // '=> 12.34.56.789,12'
  1677. x.toFormat(3, BigNumber.ROUND_UP, fmt)    // '=> 12.34.56.789,124'</pre>
  1678.  
  1679.  
  1680.  
  1681.     <h5 id="toFr">
  1682.       toFraction<code class='inset'>.toFraction([maximum_denominator])
  1683.       <i>&rArr; [BigNumber, BigNumber]</i></code>
  1684.     </h5>
  1685.     <p>
  1686.       <code>maximum_denominator</code>:
  1687.       <i>number|string|BigNumber</i>: integer &gt;= <code>1</code> and &lt;=
  1688.       <code>Infinity</code>
  1689.     </p>
  1690.     <p>
  1691.       Returns an array of two BigNumbers representing the value of this BigNumber as a simple
  1692.       fraction with an integer numerator and an integer denominator. The denominator will be a
  1693.       positive non-zero value less than or equal to <code>maximum_denominator</code>.
  1694.     </p>
  1695.     <p>
  1696.       If a <code>maximum_denominator</code> is not specified, or is <code>null</code> or
  1697.       <code>undefined</code>, the denominator will be the lowest value necessary to represent the
  1698.       number exactly.
  1699.     </p>
  1700.     <p>
  1701.       Throws if <code>maximum_denominator</code> is invalid. See <a href='#Errors'>Errors</a>.
  1702.     </p>
  1703.     <pre>
  1704. x = new BigNumber(1.75)
  1705. x.toFraction()                  // '7, 4'
  1706.  
  1707. pi = new BigNumber('3.14159265358')
  1708. pi.toFraction()                 // '157079632679,50000000000'
  1709. pi.toFraction(100000)           // '312689, 99532'
  1710. pi.toFraction(10000)            // '355, 113'
  1711. pi.toFraction(100)              // '311, 99'
  1712. pi.toFraction(10)               // '22, 7'
  1713. pi.toFraction(1)                // '3, 1'</pre>
  1714.  
  1715.  
  1716.  
  1717.     <h5 id="toJSON">toJSON<code class='inset'>.toJSON() <i>&rArr; string</i></code></h5>
  1718.     <p>As <a href='#valueOf'><code>valueOf</code></a>.</p>
  1719.     <pre>
  1720. x = new BigNumber('177.7e+457')
  1721. y = new BigNumber(235.4325)
  1722. z = new BigNumber('0.0098074')
  1723.  
  1724. // Serialize an array of three BigNumbers
  1725. str = JSON.stringify( [x, y, z] )
  1726. // "["1.777e+459","235.4325","0.0098074"]"
  1727.  
  1728. // Return an array of three BigNumbers
  1729. JSON.parse(str, function (key, val) {
  1730.     return key === '' ? val : new BigNumber(val)
  1731. })</pre>
  1732.  
  1733.  
  1734.  
  1735.     <h5 id="toN">toNumber<code class='inset'>.toNumber() <i>&rArr; number</i></code></h5>
  1736.     <p>Returns the value of this BigNumber as a JavaScript number primitive.</p>
  1737.     <p>
  1738.       This method is identical to using type coercion with the unary plus operator.
  1739.     </p>
  1740.     <pre>
  1741. x = new BigNumber(456.789)
  1742. x.toNumber()                    // 456.789
  1743. +x                              // 456.789
  1744.  
  1745. y = new BigNumber('45987349857634085409857349856430985')
  1746. y.toNumber()                    // 4.598734985763409e+34
  1747.  
  1748. z = new BigNumber(-0)
  1749. 1 / z.toNumber()                // -Infinity
  1750. 1 / +z                          // -Infinity</pre>
  1751.  
  1752.  
  1753.  
  1754.     <h5 id="toP">
  1755.       toPrecision<code class='inset'>.toPrecision([sd [, rm]]) <i>&rArr; string</i></code>
  1756.     </h5>
  1757.     <p>
  1758.       <code>sd</code>: <i>number</i>: integer, <code>1</code> to <code>1e+9</code> inclusive<br />
  1759.       <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive
  1760.     </p>
  1761.     <p>
  1762.       Returns a string representing the value of this BigNumber rounded to <code>sd</code>
  1763.       significant digits using rounding mode <code>rm</code>.
  1764.     </p>
  1765.     <p>
  1766.       If <code>sd</code> is less than the number of digits necessary to represent the integer part
  1767.       of the value in normal (fixed-point) notation, then exponential notation is used.
  1768.     </p>
  1769.     <p>
  1770.       If <code>sd</code> is omitted, or is <code>null</code> or <code>undefined</code>, then the
  1771.       return value is the same as <code>n.toString()</code>.<br />
  1772.       If <code>rm</code> is omitted or is <code>null</code> or <code>undefined</code>,
  1773.       <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.
  1774.     </p>
  1775.     <p>
  1776.       Throws if <code>sd</code> or <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
  1777.     </p>
  1778.      <pre>
  1779. x = 45.6
  1780. y = new BigNumber(x)
  1781. x.toPrecision()                 // '45.6'
  1782. y.toPrecision()                 // '45.6'
  1783. x.toPrecision(1)                // '5e+1'
  1784. y.toPrecision(1)                // '5e+1'
  1785. y.toPrecision(2, 0)             // '4.6e+1'  (ROUND_UP)
  1786. y.toPrecision(2, 1)             // '4.5e+1'  (ROUND_DOWN)
  1787. x.toPrecision(5)                // '45.600'
  1788. y.toPrecision(5)                // '45.600'</pre>
  1789.  
  1790.  
  1791.  
  1792.     <h5 id="toS">toString<code class='inset'>.toString([base]) <i>&rArr; string</i></code></h5>
  1793.     <p>
  1794.       <code>base</code>: <i>number</i>: integer, <code>2</code> to <code>ALPHABET.length</code>
  1795.       inclusive (see <a href='#alphabet'><code>ALPHABET</code></a>).
  1796.     </p>
  1797.     <p>
  1798.       Returns a string representing the value of this BigNumber in the specified base, or base
  1799.       <code>10</code> if <code>base</code> is omitted or is <code>null</code> or
  1800.       <code>undefined</code>.
  1801.     </p>
  1802.     <p>
  1803.       For bases above <code>10</code>, and using the default base conversion alphabet
  1804.       (see <a href='#alphabet'><code>ALPHABET</code></a>), values from <code>10</code> to
  1805.       <code>35</code> are represented by <code>a-z</code>
  1806.       (as with <code>Number.prototype.toString</code>).
  1807.     </p>
  1808.     <p>
  1809.       If a base is specified the value is rounded according to the current
  1810.       <a href='#decimal-places'><code>DECIMAL_PLACES</code></a>
  1811.       and <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> settings.
  1812.     </p>
  1813.     <p>
  1814.       If a base is not specified, and this BigNumber has a positive
  1815.       exponent that is equal to or greater than the positive component of the
  1816.       current <a href="#exponential-at"><code>EXPONENTIAL_AT</code></a> setting,
  1817.       or a negative exponent equal to or less than the negative component of the
  1818.       setting, then exponential notation is returned.
  1819.     </p>
  1820.     <p>If <code>base</code> is <code>null</code> or <code>undefined</code> it is ignored.</p>
  1821.     <p>
  1822.       Throws if <code>base</code> is invalid. See <a href='#Errors'>Errors</a>.
  1823.     </p>
  1824.     <pre>
  1825. x = new BigNumber(750000)
  1826. x.toString()                    // '750000'
  1827. BigNumber.config({ EXPONENTIAL_AT: 5 })
  1828. x.toString()                    // '7.5e+5'
  1829.  
  1830. y = new BigNumber(362.875)
  1831. y.toString(2)                   // '101101010.111'
  1832. y.toString(9)                   // '442.77777777777777777778'
  1833. y.toString(32)                  // 'ba.s'
  1834.  
  1835. BigNumber.config({ DECIMAL_PLACES: 4 });
  1836. z = new BigNumber('1.23456789')
  1837. z.toString()                    // '1.23456789'
  1838. z.toString(10)                  // '1.2346'</pre>
  1839.  
  1840.  
  1841.  
  1842.     <h5 id="valueOf">valueOf<code class='inset'>.valueOf() <i>&rArr; string</i></code></h5>
  1843.     <p>
  1844.       As <a href='#toS'><code>toString</code></a>, but does not accept a base argument and includes
  1845.       the minus sign for negative zero.
  1846.     </p>
  1847.     <pre>
  1848. x = new BigNumber('-0')
  1849. x.toString()                    // '0'
  1850. x.valueOf()                     // '-0'
  1851. y = new BigNumber('1.777e+457')
  1852. y.valueOf()                     // '1.777e+457'</pre>
  1853.  
  1854.  
  1855.  
  1856.     <h4 id="instance-properties">Properties</h4>
  1857.     <p>The properties of a BigNumber instance:</p>
  1858.     <table>
  1859.       <tr>
  1860.         <th>Property</th>
  1861.         <th>Description</th>
  1862.         <th>Type</th>
  1863.         <th>Value</th>
  1864.       </tr>
  1865.       <tr>
  1866.         <td class='centre' id='coefficient'><b>c</b></td>
  1867.         <td>coefficient<sup>*</sup></td>
  1868.         <td><i>number</i><code>[]</code></td>
  1869.         <td> Array of base <code>1e14</code> numbers</td>
  1870.       </tr>
  1871.       <tr>
  1872.         <td class='centre' id='exponent'><b>e</b></td>
  1873.         <td>exponent</td>
  1874.         <td><i>number</i></td>
  1875.         <td>Integer, <code>-1000000000</code> to <code>1000000000</code> inclusive</td>
  1876.       </tr>
  1877.       <tr>
  1878.         <td class='centre' id='sign'><b>s</b></td>
  1879.         <td>sign</td>
  1880.         <td><i>number</i></td>
  1881.         <td><code>-1</code> or <code>1</code></td>
  1882.       </tr>
  1883.     </table>
  1884.     <p><sup>*</sup>significand</p>
  1885.     <p>
  1886.       The value of any of the <code>c</code>, <code>e</code> and <code>s</code> properties may also
  1887.       be <code>null</code>.
  1888.     </p>
  1889.     <p>
  1890.       The above properties are best considered to be read-only. In early versions of this library it
  1891.       was okay to change the exponent of a BigNumber by writing to its exponent property directly,
  1892.       but this is no longer reliable as the value of the first element of the coefficient array is
  1893.       now dependent on the exponent.
  1894.     </p>
  1895.     <p>
  1896.       Note that, as with JavaScript numbers, the original exponent and fractional trailing zeros are
  1897.       not necessarily preserved.
  1898.     </p>
  1899.     <pre>x = new BigNumber(0.123)              // '0.123'
  1900. x.toExponential()                     // '1.23e-1'
  1901. x.c                                   // '1,2,3'
  1902. x.e                                   // -1
  1903. x.s                                   // 1
  1904.  
  1905. y = new Number(-123.4567000e+2)       // '-12345.67'
  1906. y.toExponential()                     // '-1.234567e+4'
  1907. z = new BigNumber('-123.4567000e+2')  // '-12345.67'
  1908. z.toExponential()                     // '-1.234567e+4'
  1909. z.c                                   // '1,2,3,4,5,6,7'
  1910. z.e                                   // 4
  1911. z.s                                   // -1</pre>
  1912.  
  1913.  
  1914.  
  1915.     <h4 id="zero-nan-infinity">Zero, NaN and Infinity</h4>
  1916.     <p>
  1917.       The table below shows how &plusmn;<code>0</code>, <code>NaN</code> and
  1918.       &plusmn;<code>Infinity</code> are stored.
  1919.     </p>
  1920.     <table>
  1921.       <tr>
  1922.         <th> </th>
  1923.         <th class='centre'>c</th>
  1924.         <th class='centre'>e</th>
  1925.         <th class='centre'>s</th>
  1926.       </tr>
  1927.       <tr>
  1928.         <td>&plusmn;0</td>
  1929.         <td><code>[0]</code></td>
  1930.         <td><code>0</code></td>
  1931.         <td><code>&plusmn;1</code></td>
  1932.       </tr>
  1933.       <tr>
  1934.         <td>NaN</td>
  1935.         <td><code>null</code></td>
  1936.         <td><code>null</code></td>
  1937.         <td><code>null</code></td>
  1938.       </tr>
  1939.       <tr>
  1940.         <td>&plusmn;Infinity</td>
  1941.         <td><code>null</code></td>
  1942.         <td><code>null</code></td>
  1943.         <td><code>&plusmn;1</code></td>
  1944.       </tr>
  1945.     </table>
  1946.     <pre>
  1947. x = new Number(-0)              // 0
  1948. 1 / x == -Infinity              // true
  1949.  
  1950. y = new BigNumber(-0)           // '0'
  1951. y.c                             // '0' ( [0].toString() )
  1952. y.e                             // 0
  1953. y.s                             // -1</pre>
  1954.  
  1955.  
  1956.  
  1957.     <h4 id='Errors'>Errors</h4>
  1958.     <p>The table below shows the errors that are thrown.</p>
  1959.     <p>
  1960.       The errors are generic <code>Error</code> objects whose message begins
  1961.       <code>'[BigNumber Error]'</code>.
  1962.     </p>
  1963.     <table class='error-table'>
  1964.       <tr>
  1965.         <th>Method</th>
  1966.         <th>Throws</th>
  1967.       </tr>
  1968.       <tr>
  1969.         <td rowspan=6>
  1970.           <code>BigNumber</code><br />
  1971.           <code>comparedTo</code><br />
  1972.           <code>dividedBy</code><br />
  1973.           <code>dividedToIntegerBy</code><br />
  1974.           <code>isEqualTo</code><br />
  1975.           <code>isGreaterThan</code><br />
  1976.           <code>isGreaterThanOrEqualTo</code><br />
  1977.           <code>isLessThan</code><br />
  1978.           <code>isLessThanOrEqualTo</code><br />
  1979.           <code>minus</code><br />
  1980.           <code>modulo</code><br />
  1981.           <code>plus</code><br />
  1982.           <code>multipliedBy</code>
  1983.         </td>
  1984.         <td>Base not a primitive number</td>
  1985.       </tr>
  1986.       <tr>
  1987.         <td>Base not an integer</td>
  1988.       </tr>
  1989.       <tr>
  1990.         <td>Base out of range</td>
  1991.       </tr>
  1992.        <tr>
  1993.         <td>Number primitive has more than 15 significant digits<sup>*</sup></td>
  1994.       </tr>
  1995.       <tr>
  1996.         <td>Not a base... number<sup>*</sup></td>
  1997.       </tr>
  1998.       <tr>
  1999.         <td>Not a number<sup>*</sup></td>
  2000.       </tr>
  2001.       <tr>
  2002.         <td><code>clone</code></td>
  2003.         <td>Object expected</td>
  2004.       </tr>
  2005.       <tr>
  2006.         <td rowspan=24><code>config</code></td>
  2007.         <td>Object expected</td>
  2008.       </tr>
  2009.       <tr>
  2010.         <td><code>DECIMAL_PLACES</code> not a primitive number</td>
  2011.       </tr>
  2012.       <tr>
  2013.         <td><code>DECIMAL_PLACES</code> not an integer</td>
  2014.       </tr>
  2015.       <tr>
  2016.         <td><code>DECIMAL_PLACES</code> out of range</td>
  2017.       </tr>
  2018.       <tr>
  2019.         <td><code>ROUNDING_MODE</code> not a primitive number</td>
  2020.       </tr>
  2021.       <tr>
  2022.         <td><code>ROUNDING_MODE</code> not an integer</td>
  2023.       </tr>
  2024.       <tr>
  2025.         <td><code>ROUNDING_MODE</code> out of range</td>
  2026.       </tr>
  2027.       <tr>
  2028.         <td><code>EXPONENTIAL_AT</code> not a primitive number</td>
  2029.       </tr>
  2030.       <tr>
  2031.         <td><code>EXPONENTIAL_AT</code> not an integer</td>
  2032.       </tr>
  2033.       <tr>
  2034.         <td><code>EXPONENTIAL_AT</code> out of range</td>
  2035.       </tr>
  2036.       <tr>
  2037.         <td><code>RANGE</code> not a primitive number</td>
  2038.       </tr>
  2039.       <tr>
  2040.         <td><code>RANGE</code> not an integer</td>
  2041.       </tr>
  2042.       <tr>
  2043.         <td><code>RANGE</code> cannot be zero</td>
  2044.       </tr>
  2045.       <tr>
  2046.         <td><code>RANGE</code> cannot be zero</td>
  2047.       </tr>
  2048.       <tr>
  2049.         <td><code>CRYPTO</code> not true or false</td>
  2050.       </tr>
  2051.       <tr>
  2052.         <td><code>crypto</code> unavailable</td>
  2053.       </tr>
  2054.       <tr>
  2055.         <td><code>MODULO_MODE</code> not a primitive number</td>
  2056.       </tr>
  2057.       <tr>
  2058.         <td><code>MODULO_MODE</code> not an integer</td>
  2059.       </tr>
  2060.       <tr>
  2061.         <td><code>MODULO_MODE</code> out of range</td>
  2062.       </tr>
  2063.       <tr>
  2064.         <td><code>POW_PRECISION</code> not a primitive number</td>
  2065.       </tr>
  2066.       <tr>
  2067.         <td><code>POW_PRECISION</code> not an integer</td>
  2068.       </tr>
  2069.       <tr>
  2070.         <td><code>POW_PRECISION</code> out of range</td>
  2071.       </tr>
  2072.       <tr>
  2073.         <td><code>FORMAT</code> not an object</td>
  2074.       </tr>
  2075.       <tr>
  2076.         <td><code>ALPHABET</code> invalid</td>
  2077.       </tr>
  2078.       <tr>
  2079.         <td rowspan=3>
  2080.           <code>decimalPlaces</code><br />
  2081.           <code>precision</code><br />
  2082.           <code>random</code><br />
  2083.           <code>shiftedBy</code><br />
  2084.           <code>toExponential</code><br />
  2085.           <code>toFixed</code><br />
  2086.           <code>toFormat</code><br />
  2087.           <code>toPrecision</code>
  2088.         </td>
  2089.         <td>Argument not a primitive number</td>
  2090.       </tr>
  2091.       <tr>
  2092.         <td>Argument not an integer</td>
  2093.       </tr>
  2094.       <tr>
  2095.         <td>Argument out of range</td>
  2096.       </tr>
  2097.       <tr>
  2098.         <td>
  2099.           <code>decimalPlaces</code><br />
  2100.           <code>precision</code>
  2101.         </td>
  2102.         <td>Argument not true or false</td>
  2103.       </tr>
  2104.       <tr>
  2105.         <td><code>exponentiatedBy</code></td>
  2106.         <td>Argument not an integer</td>
  2107.       </tr>
  2108.       <tr>
  2109.         <td><code>isBigNumber</code></td>
  2110.         <td>Invalid BigNumber<sup>*</sup></td>
  2111.       </tr>
  2112.       <tr>
  2113.         <td>
  2114.           <code>minimum</code><br />
  2115.           <code>maximum</code>
  2116.         </td>
  2117.         <td>Not a number<sup>*</sup></td>
  2118.       </tr>
  2119.       <tr>
  2120.         <td>
  2121.           <code>random</code>
  2122.         </td>
  2123.         <td>crypto unavailable</td>
  2124.       </tr>
  2125.       <tr>
  2126.         <td>
  2127.           <code>toFormat</code>
  2128.         </td>
  2129.         <td>Argument not an object</td>
  2130.       </tr>
  2131.       <tr>
  2132.         <td rowspan=2><code>toFraction</code></td>
  2133.         <td>Argument not an integer</td>
  2134.       </tr>
  2135.       <tr>
  2136.         <td>Argument out of range</td>
  2137.       </tr>
  2138.       <tr>
  2139.         <td rowspan=3><code>toString</code></td>
  2140.         <td>Base not a primitive number</td>
  2141.       </tr>
  2142.       <tr>
  2143.         <td>Base not an integer</td>
  2144.       </tr>
  2145.       <tr>
  2146.         <td>Base out of range</td>
  2147.       </tr>
  2148.     </table>
  2149.     <p><sup>*</sup>Only thrown if <code>BigNumber.DEBUG</code> is <code>true</code>.</p>
  2150.     <p>To determine if an exception is a BigNumber Error:</p>
  2151.     <pre>
  2152. try {
  2153.   // ...
  2154. } catch (e) {
  2155.   if (e instanceof Error &amp;&amp; e.message.indexOf('[BigNumber Error]') === 0) {
  2156.       // ...
  2157.   }
  2158. }</pre>
  2159.  
  2160.  
  2161.  
  2162.     <h4 id="type-coercion">Type coercion</h4>
  2163.     <p>
  2164.       To prevent the accidental use of a BigNumber in primitive number operations, or the
  2165.       accidental addition of a BigNumber to a string, the <code>valueOf</code> method can be safely
  2166.       overwritten as shown below.
  2167.     </p>
  2168.     <p>
  2169.       The <a href='#valueOf'><code>valueOf</code></a> method is the same as the
  2170.       <a href='#toJSON'><code>toJSON</code></a> method, and both are the same as the
  2171.       <a href='#toS'><code>toString</code></a> method except they do not take a <code>base</code>
  2172.       argument and they include the minus sign for negative zero.
  2173.     </p>
  2174.     <pre>
  2175. BigNumber.prototype.valueOf = function () {
  2176.   throw Error('valueOf called!')
  2177. }
  2178.  
  2179. x = new BigNumber(1)
  2180. x / 2                    // '[BigNumber Error] valueOf called!'
  2181. x + 'abc'                // '[BigNumber Error] valueOf called!'
  2182. </pre>
  2183.  
  2184.  
  2185.  
  2186.     <h4 id='faq'>FAQ</h4>
  2187.  
  2188.     <h6>Why are trailing fractional zeros removed from BigNumbers?</h6>
  2189.     <p>
  2190.       Some arbitrary-precision libraries retain trailing fractional zeros as they can indicate the
  2191.       precision of a value. This can be useful but the results of arithmetic operations can be
  2192.       misleading.
  2193.     </p>
  2194.     <pre>
  2195. x = new BigDecimal("1.0")
  2196. y = new BigDecimal("1.1000")
  2197. z = x.add(y)                      // 2.1000
  2198.  
  2199. x = new BigDecimal("1.20")
  2200. y = new BigDecimal("3.45000")
  2201. z = x.multiply(y)                 // 4.1400000</pre>
  2202.     <p>
  2203.       To specify the precision of a value is to specify that the value lies
  2204.       within a certain range.
  2205.     </p>
  2206.     <p>
  2207.       In the first example, <code>x</code> has a value of <code>1.0</code>. The trailing zero shows
  2208.       the precision of the value, implying that it is in the range <code>0.95</code> to
  2209.       <code>1.05</code>. Similarly, the precision indicated by the trailing zeros of <code>y</code>
  2210.       indicates that the value is in the range <code>1.09995</code> to <code>1.10005</code>.
  2211.     </p>
  2212.     <p>
  2213.       If we  add the two lowest values in the ranges we have, <code>0.95 + 1.09995 = 2.04995</code>,
  2214.       and if we add the two highest values we have, <code>1.05 + 1.10005 = 2.15005</code>, so the
  2215.       range of the result of the addition implied by the precision of its operands is
  2216.       <code>2.04995</code> to <code>2.15005</code>.
  2217.     </p>
  2218.     <p>
  2219.       The result given by BigDecimal of <code>2.1000</code> however, indicates that the value is in
  2220.       the range <code>2.09995</code> to <code>2.10005</code> and therefore the precision implied by
  2221.       its trailing zeros may be misleading.
  2222.     </p>
  2223.     <p>
  2224.       In the second example, the true range is <code>4.122744</code> to <code>4.157256</code> yet
  2225.       the BigDecimal answer of <code>4.1400000</code> indicates a range of <code>4.13999995</code>
  2226.       to  <code>4.14000005</code>. Again, the precision implied by the trailing zeros may be
  2227.       misleading.
  2228.     </p>
  2229.     <p>
  2230.       This library, like binary floating point and most calculators, does not retain trailing
  2231.       fractional zeros. Instead, the <code>toExponential</code>, <code>toFixed</code> and
  2232.       <code>toPrecision</code> methods enable trailing zeros to be added if and when required.<br />
  2233.     </p>
  2234.   </div>
  2235.  
  2236. </body>
  2237. </html>
  2238.