v1.2.0 Throw Error objects
This commit is contained in:
parent
6771e89996
commit
aeb5646957
|
@ -211,6 +211,9 @@ See LICENCE.
|
|||
|
||||
## Change Log
|
||||
|
||||
####1.2.0
|
||||
* 19/9/2013 Throw Error objects for stack.
|
||||
|
||||
####1.1.1
|
||||
* 22/8/2013 Show original value in constructor error message.
|
||||
|
||||
|
@ -222,5 +225,3 @@ See LICENCE.
|
|||
|
||||
####1.0.0
|
||||
* 8/11/2012 Initial release
|
||||
|
||||
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/50b85fd919b406ef9312551092a95fb7 "githalytics.com")](http://githalytics.com/MikeMcl/bignumber.js)
|
||||
|
|
25
bignumber.js
25
bignumber.js
|
@ -1,9 +1,9 @@
|
|||
/* bignumber.js v1.1.1 https://github.com/MikeMcl/bignumber.js/LICENCE */
|
||||
/* bignumber.js v1.2.0 https://github.com/MikeMcl/bignumber.js/LICENCE */
|
||||
;(function ( global ) {
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
bignumber.js v1.1.1
|
||||
bignumber.js v1.2.0
|
||||
A JavaScript library for arbitrary-precision arithmetic.
|
||||
https://github.com/MikeMcl/bignumber.js
|
||||
Copyright (c) 2012 Michael Mclaughlin <M8ch88l@gmail.com>
|
||||
|
@ -409,32 +409,33 @@
|
|||
|
||||
// Assemble error messages. Throw BigNumber Errors.
|
||||
function ifExceptionsThrow( arg, i, j, isArray, isRange, isErrors) {
|
||||
|
||||
if ( ERRORS ) {
|
||||
var method = ['new BigNumber', 'cmp', 'div', 'eq', 'gt', 'gte', 'lt',
|
||||
var error,
|
||||
method = ['new BigNumber', 'cmp', 'div', 'eq', 'gt', 'gte', 'lt',
|
||||
'lte', 'minus', 'mod', 'plus', 'times', 'toFr'
|
||||
][ id ? id < 0 ? -id : id : 1 / id < 0 ? 1 : 0 ] + '()',
|
||||
error = outOfRange ? ' out of range' : ' not a' +
|
||||
message = outOfRange ? ' out of range' : ' not a' +
|
||||
( isRange ? ' non-zero' : 'n' ) + ' integer';
|
||||
|
||||
error = ( [
|
||||
message = ( [
|
||||
method + ' number type has more than 15 significant digits',
|
||||
method + ' not a base ' + j + ' number',
|
||||
method + ' base' + error,
|
||||
method + ' base' + message,
|
||||
method + ' not a number' ][i] ||
|
||||
j + '() ' + i + ( isErrors
|
||||
? ' not a boolean or binary digit'
|
||||
: error + ( isArray
|
||||
: message + ( isArray
|
||||
? ' or not [' + ( outOfRange
|
||||
? ' negative, positive'
|
||||
: ' integer, integer' ) + ' ]'
|
||||
: '' ) ) ) + ': ' + arg;
|
||||
|
||||
outOfRange = id = 0;
|
||||
throw {
|
||||
name : 'BigNumber Error',
|
||||
message : error,
|
||||
toString : function () {return this.name + ': ' + this.message}
|
||||
}
|
||||
error = new Error(message);
|
||||
error['name'] = 'BigNumber Error';
|
||||
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
35
doc/API.html
35
doc/API.html
|
@ -136,7 +136,7 @@ code,pre{font-family:Monaco,Consolas,"Lucida Console",monospace;
|
|||
<a href="#zero-nan-infinity">Zero, NaN & Infinity</a>
|
||||
|
||||
<a href="#Errors">Errors</a>
|
||||
|
||||
|
||||
<a class='end' href="#faq">FAQ</a>
|
||||
|
||||
</div>
|
||||
|
@ -332,7 +332,7 @@ BigNumber.config(null, BigNumber.ROUND_UP) // equivalent</pre>
|
|||
|
||||
<dt id="exponential-at"><code><b>EXPONENTIAL_AT</b></code></dt>
|
||||
<dd>
|
||||
<i>number</i> : integer, magnitude <code>0</code> to
|
||||
<i>number</i> : integer, magnitude <code>0</code> to
|
||||
<code>1e+9</code> inclusive, or<br />
|
||||
<i>number</i>[] : [ integer -1e+9 to 0 inclusive, integer 0 to 1e+9
|
||||
inclusive ]<br />
|
||||
|
@ -387,7 +387,7 @@ BigNumber.config({ EXPONENTIAL_AT : 0 })</pre>
|
|||
|
||||
<dt id="range"><code><b>RANGE</b></code></dt>
|
||||
<dd>
|
||||
<i>number</i> : integer, magnitude <code>1</code> to
|
||||
<i>number</i> : integer, magnitude <code>1</code> to
|
||||
<code>1e+9</code> inclusive, or<br />
|
||||
<i>number</i>[] : [ integer -1e+9 to -1 inclusive, integer 1 to 1e+9
|
||||
inclusive ]<br />
|
||||
|
@ -978,7 +978,7 @@ y.equals(NaN) // false</pre>
|
|||
|
||||
|
||||
<h5 id="gt">
|
||||
greaterThan<code class='inset'>.gt(n [, base]) ⇒
|
||||
greaterThan<code class='inset'>.gt(n [, base]) ⇒
|
||||
<i>boolean</i></code>
|
||||
</h5>
|
||||
<p>
|
||||
|
@ -1322,7 +1322,7 @@ pi.toFr(1) // '3, 1'</pre>
|
|||
</p>
|
||||
<p>
|
||||
See <a href='#Errors'>Errors</a> for the treatment of other
|
||||
non-integer or out of range <code>decimal_places</code> or
|
||||
non-integer or out of range <code>decimal_places</code> or
|
||||
<code>rounding_mode</code> values.
|
||||
</p>
|
||||
<pre>
|
||||
|
@ -1465,9 +1465,10 @@ y.s // -1</pre>
|
|||
|
||||
<h4 id='Errors'>Errors</h4>
|
||||
<p>
|
||||
The table below shows the BigNumber Errors that may be thrown if
|
||||
<code>ERRORS</code> is <code>true</code>, and what happens if
|
||||
<code>ERRORS</code> is <code>false</code>.
|
||||
The errors that are thrown are generic <code>Error</code> objects with
|
||||
<code>name</code> <i>BigNumber Error</i>. The table below shows the errors
|
||||
that may be thrown if <code>ERRORS</code> is <code>true</code>, and the
|
||||
action taken if <code>ERRORS</code> is <code>false</code>.
|
||||
</p>
|
||||
<table class='error-table'>
|
||||
<tr>
|
||||
|
@ -1637,18 +1638,18 @@ y.s // -1</pre>
|
|||
<sup>*</sup>No error is thrown if the value is <code>NaN</code> or 'NaN'
|
||||
</p>
|
||||
<p>
|
||||
The message of a BigNumber Error will also contain the name of the
|
||||
The message of a <i>BigNumber Error</i> will also contain the name of the
|
||||
method from which the error originated.
|
||||
</p>
|
||||
<p>
|
||||
To determine if an exception is a BigNumber Error:
|
||||
To determine if an exception is a <i>BigNumber Error</i>:
|
||||
</p>
|
||||
<pre>
|
||||
try {
|
||||
// do something with BigNumbers
|
||||
// ...
|
||||
} catch (e) {
|
||||
if (e.name == 'BigNumber Error') {
|
||||
// do something
|
||||
if ( e instanceof Error && e.name == 'BigNumber Error' ) {
|
||||
// ...
|
||||
}
|
||||
}</pre>
|
||||
|
||||
|
@ -1662,8 +1663,8 @@ try {
|
|||
<pre>
|
||||
x = new BigDecimal("1.0")
|
||||
y = new BigDecimal("1.1000")
|
||||
z = x.add(y) // 2.1000
|
||||
|
||||
z = x.add(y) // 2.1000
|
||||
|
||||
x = new BigDecimal("1.20")
|
||||
y = new BigDecimal("3.45000")
|
||||
z = x.multiply(y) // 4.1400000</pre>
|
||||
|
@ -1694,10 +1695,10 @@ z = x.multiply(y) // 4.1400000</pre>
|
|||
This library, like binary floating point and most calculators, does not
|
||||
retain trailing fractional zeros. Instead, the <code>toExponential</code>,
|
||||
<code>toFixed</code> and <code>toPrecision</code> methods enable trailing
|
||||
zeros to be added if and when required.
|
||||
zeros to be added if and when required.
|
||||
</p>
|
||||
<br />
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "bignumber.js",
|
||||
"description": "A library for arbitrary-precision decimal and non-decimal arithmetic",
|
||||
"version": "1.1.1",
|
||||
"version": "1.2.0",
|
||||
"keywords": [
|
||||
"arbitrary",
|
||||
"precision",
|
||||
|
|
Loading…
Reference in New Issue