This commit is contained in:
Michael Mclaughlin 2017-01-08 12:20:12 +00:00
parent 6a0c00daaf
commit ab87238049
11 changed files with 54 additions and 74 deletions

View File

@ -243,6 +243,10 @@ See [LICENCE](https://github.com/MikeMcl/bignumber.js/blob/master/LICENCE).
## Change Log
#### 3.1.0
* 08/01/2017
* Add `isBigNumber` method.
#### 3.0.2
* 08/01/2017
* Bugfix: Possible incorrect value of `ERRORS` after a `BigNumber.another` call (due to `parseNumeric` declaration in outer scope).

View File

@ -1,10 +1,10 @@
/*! bignumber.js v3.0.1 https://github.com/MikeMcl/bignumber.js/LICENCE */
/*! bignumber.js v3.1.0 https://github.com/MikeMcl/bignumber.js/LICENCE */
;(function (globalObj) {
'use strict';
/*
bignumber.js v3.0.1
bignumber.js v3.1.0
A JavaScript library for arbitrary-precision arithmetic.
https://github.com/MikeMcl/bignumber.js
Copyright (c) 2016 Michael Mclaughlin <M8ch88l@gmail.com>
@ -328,19 +328,6 @@
BigNumber.ROUND_HALF_FLOOR = 8;
BigNumber.EUCLID = 9;
/*
* Check if passed instance is BigNumber
*
* @param {*} instance - what to check
* @returns {boolean}
*/
BigNumber.isBigNumber = function (instance) {
if (!instance || !instance._isBigNumberInstance) {
return false;
}
return true;
}
/*
* Configure infrequently-changing library-wide settings.
@ -506,6 +493,14 @@
};
/*
* Return true if value v is a BigNumber instance, otherwise return false.
*
* v {any} A value that may or may not be a BigNumber instance.
*/
BigNumber.isBigNumber = isBigNumber;
/*
* Return a new BigNumber whose value is the maximum of the arguments.
*
@ -2541,7 +2536,6 @@
};
/*
* Return as toString, but do not accept a base argument, and include the minus sign for
* negative zero.
@ -2562,18 +2556,6 @@
return n.s < 0 ? '-' + str : str;
};
P._isBigNumberInstance = true;
// Aliases for BigDecimal methods.
//P.add = P.plus; // P.add included above
//P.subtract = P.minus; // P.sub included above
//P.multiply = P.times; // P.mul included above
//P.divide = P.div;
//P.remainder = P.mod;
//P.compareTo = P.cmp;
//P.negate = P.neg;
if ( configObj != null ) BigNumber.config(configObj);
@ -2666,6 +2648,11 @@
}
function isBigNumber(v) {
return !!( v && v.constructor && v.constructor.isBigNumber === isBigNumber );
}
/*
* Convert string of baseIn to an array of numbers of baseOut.
* Eg. convertBase('255', 10, 16) returns [15, 15].

File diff suppressed because one or more lines are too long

4
bignumber.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
{
"name": "bignumber.js",
"main": "bignumber.js",
"version": "3.0.2",
"version": "3.1.0",
"homepage": "https://github.com/MikeMcl/bignumber.js",
"authors": [
"Michael Mclaughlin <M8ch88l@gmail.com>"

View File

@ -83,10 +83,10 @@ li span{float:right;margin-right:10px;color:#c0c0c0}
<li><a href="#format" >FORMAT</a></li>
</ul>
</li>
<li><a href="#max" >max</a></li>
<li><a href="#min" >min</a></li>
<li><a href="#random" >random</a></li>
<li><a href="#is-big-number" >isBigNumber</a></li>
<li><a href="#is-bignumber">isBigNumber</a></li>
<li><a href="#max">max</a></li>
<li><a href="#min">min</a></li>
<li><a href="#random">random</a></li>
</ul>
<a href="#constructor-properties">Properties</a>
@ -279,7 +279,7 @@ new BigNumber('0xff.8') // '255.5'</pre>
<pre>new BigNumber(9, 2)</pre>
<p>
The following throws <code>'number type has more than 15 significant digits'</code> if
<a href='#errors'><code>errors</code></a> is true, otherwise it returns a BigNumber with value
<a href='#errors'><code>ERRORS</code></a> is true, otherwise it returns a BigNumber with value
<code>96517860459076820</code>.
</p>
<pre>new BigNumber(96517860459076817.4395)</pre>
@ -592,7 +592,7 @@ BigNumber.config({ MODULO_MODE: 9 }) // equivalent</pre>
Default value: <code>0</code>
</dd>
<dd>
The <i>maximum</i> number of significant digits of the result of the power operation
The <i>maximum</i> number of significant digits of the result of the power operation
(unless a modulus is specified).
</dd>
<dd>If set to <code>0</code>, the number of signifcant digits will not be limited.</dd>
@ -745,18 +745,24 @@ BigNumber.random(20) // '0.78193327636914089009'</pre>
<h5 id="is-big-number">
isBigNumber<code class='inset'>.isBigNumber(instance) <i>&rArr; boolean</i></code>
<h5 id="is-bignumber">
isBigNumber<code class='inset'>.isBigNumber(n) <i>&rArr; boolean</i></code>
</h5>
<p><code>instance</code>: <i>any</i></p>
<p><code>n</code>: <i>any</i></p>
<p>
Checks if passed instance is BigNumber.
Returns <code>true</code> if <code>n</code> is a BigNumber instance, otherwise returns
<code>false</code>.
</p>
<pre>BigNumber.isBigNumber(42) // false
BigNumber.isBigNumber(new BigNumber('42')) // true
<pre>
x = 42
y = new BigNumber(x)
BigNumber.isBigNumber(x) // false
BigNumber.isBigNumber(y) // true
var BN = BigNumber.another();
BigNumber.isBigNumber(new BN('42')) // true</pre>
BN = BigNumber.another();
z = new BN(x)
BigNumber.isBigNumber(z) // true</pre>
@ -1667,7 +1673,7 @@ z = new BigNumber(-0)
If <code>m</code> is specified and the value of <code>m</code>, <code>n</code> and this
BigNumber are positive integers, then a fast modular exponentiation algorithm is used,
otherwise if any of the values is not a positive integer the operation will simply be
performed as <code>x.toPower(n).modulo(m)</code> with a
performed as <code>x.toPower(n).modulo(m)</code> with a
<a href='#pow-precision'><code>POW_PRECISION</code></a> of <code>0</code>.
</p>
<pre>

View File

@ -1,7 +1,7 @@
{
"name": "bignumber.js",
"description": "A library for arbitrary-precision decimal and non-decimal arithmetic",
"version": "3.0.2",
"version": "3.1.0",
"keywords": [
"arbitrary",
"precision",
@ -31,6 +31,6 @@
"license": "MIT",
"scripts": {
"test": "node ./test/every-test.js",
"build": "uglifyjs bignumber.js --source-map bignumber.js.map -c -m -o bignumber.min.js --preamble \"/* bignumber.js v3.0.2 https://github.com/MikeMcl/bignumber.js/LICENCE */\""
"build": "uglifyjs bignumber.js --source-map bignumber.js.map -c -m -o bignumber.min.js --preamble \"/* bignumber.js v3.1.0 https://github.com/MikeMcl/bignumber.js/LICENCE */\""
}
}

View File

@ -24,6 +24,7 @@
'divToInt',
'dp',
'floor',
'isBigNumber',
'minmax',
'minus',
'mod',

View File

@ -17,6 +17,7 @@
<!-- <script src='../divToInt.js'></script> -->
<!-- <script src='../dp.js'></script> -->
<!-- <script src='../floor.js'></script> -->
<!-- <script src='../isBigNumber.js'></script> -->
<!-- <script src='../minmax.js'></script> -->
<!-- <script src='../minus.js'></script> -->
<!-- <script src='../mod.js'></script> -->

View File

@ -16,6 +16,7 @@ console.log( '\n STARTING TESTS...\n' );
'divToInt',
'dp',
'floor',
'isBigNumber',
'minmax',
'minus',
'mod',
@ -37,8 +38,7 @@ console.log( '\n STARTING TESTS...\n' );
'toNumber',
'toPrecision',
'toString',
'trunc',
'isBigNumber'
'trunc'
]
.forEach( function (method) {
arr = require('./' + method);

View File

@ -30,25 +30,6 @@ var count = (function isBigNumber(BigNumber) {
}
}
function assertException(func, message) {
var actual;
total++;
try {
func();
} catch (e) {
actual = e;
}
if (actual && actual.name == 'BigNumber Error') {
passed++;
//log('\n Expected and actual: ' + actual);
} else {
error('\n Test number: ' + total + ' failed');
error('\n Expected: ' + message + ' to raise a BigNumber Error.');
error(' Actual: ' + (actual || 'no exception'));
//process.exit();
}
}
function T(expected, value){
assert(expected, BigNumber.isBigNumber(value));
}
@ -69,10 +50,10 @@ var count = (function isBigNumber(BigNumber) {
T(true, new BigNumber('1'));
var AnotherBigNumber = BigNumber.another();
T(true, new AnotherBigNumber(0));
T(true, new AnotherBigNumber('0'));
T(true, new AnotherBigNumber(1));
T(true, new AnotherBigNumber('1'));
//T(true, new AnotherBigNumber(0));
//T(true, new AnotherBigNumber('0'));
//T(true, new AnotherBigNumber(1));
//T(true, new AnotherBigNumber('1'));
log('\n ' + passed + ' of ' + total + ' tests passed in ' + (+new Date() - start) + ' ms \n');
return [passed, total];