Replace BigNumber.isBigNumber with isBigNumber prototype property
This commit is contained in:
parent
2ccc3a7d28
commit
18bbdc8836
19
bignumber.js
19
bignumber.js
|
@ -38,7 +38,7 @@
|
|||
/*
|
||||
* Create and return a BigNumber constructor.
|
||||
*/
|
||||
function constructorFactory(configObj) {
|
||||
function constructorFactory(config) {
|
||||
var div, parseNumeric,
|
||||
|
||||
// id tracks the caller function, so its name can be included in error messages.
|
||||
|
@ -493,14 +493,6 @@
|
|||
};
|
||||
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
|
@ -2557,7 +2549,9 @@
|
|||
};
|
||||
|
||||
|
||||
if ( configObj != null ) BigNumber.config(configObj);
|
||||
P.isBigNumber = true;
|
||||
|
||||
if ( config != null ) BigNumber.config(config);
|
||||
|
||||
return BigNumber;
|
||||
}
|
||||
|
@ -2648,11 +2642,6 @@
|
|||
}
|
||||
|
||||
|
||||
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].
|
||||
|
|
52
doc/API.html
52
doc/API.html
|
@ -83,9 +83,8 @@ li span{float:right;margin-right:10px;color:#c0c0c0}
|
|||
<li><a href="#format" >FORMAT</a></li>
|
||||
</ul>
|
||||
</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="#max" >max</a></li>
|
||||
<li><a href="#min" >min</a></li>
|
||||
<li><a href="#random">random</a></li>
|
||||
</ul>
|
||||
|
||||
|
@ -151,6 +150,7 @@ li span{float:right;margin-right:10px;color:#c0c0c0}
|
|||
<li><a href="#coefficient">c: coefficient</a></li>
|
||||
<li><a href="#exponent" >e: exponent</a></li>
|
||||
<li><a href="#sign" >s: sign</a></li>
|
||||
<li><a href="#isbig" >isBigNumber</a></li>
|
||||
</ul>
|
||||
|
||||
<a href="#zero-nan-infinity">Zero, NaN & Infinity</a>
|
||||
|
@ -671,27 +671,6 @@ obj.RANGE // [-500, 500]</pre>
|
|||
|
||||
|
||||
|
||||
<h5 id="is-bignumber">
|
||||
isBigNumber<code class='inset'>.isBigNumber(n) <i>⇒ boolean</i></code>
|
||||
</h5>
|
||||
<p><code>n</code>: <i>any</i></p>
|
||||
<p>
|
||||
Returns <code>true</code> if <code>n</code> is a BigNumber instance, otherwise returns
|
||||
<code>false</code>.
|
||||
</p>
|
||||
<pre>
|
||||
x = 42
|
||||
y = new BigNumber(x)
|
||||
BigNumber.isBigNumber(x) // false
|
||||
BigNumber.isBigNumber(y) // true
|
||||
|
||||
BN = BigNumber.another();
|
||||
z = new BN(x)
|
||||
|
||||
BigNumber.isBigNumber(z) // true</pre>
|
||||
|
||||
|
||||
|
||||
<h5 id="max">
|
||||
max<code class='inset'>.max([arg1 [, arg2, ...]]) <i>⇒ BigNumber</i></code>
|
||||
</h5>
|
||||
|
@ -1798,7 +1777,7 @@ y.valueOf() // '1.777e+457'</pre>
|
|||
|
||||
|
||||
<h4 id="instance-properties">Properties</h4>
|
||||
<p>A BigNumber is an object with three properties:</p>
|
||||
<p>The properties of a BigNumber instance:</p>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Property</th>
|
||||
|
@ -1824,9 +1803,18 @@ y.valueOf() // '1.777e+457'</pre>
|
|||
<td><i>number</i></td>
|
||||
<td><code>-1</code> or <code>1</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class='centre' id='isbig'><b>isBigNumber</b></td>
|
||||
<td>type identifier</td>
|
||||
<td><i>boolean</i></td>
|
||||
<td><code>true</code></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p><sup>*</sup>significand</p>
|
||||
<p>The value of any of the three properties may also be <code>null</code>. </p>
|
||||
<p>
|
||||
The value of any of the <code>c</code>, <code>e</code> and <code>s</code> properties may also
|
||||
be <code>null</code>.
|
||||
</p>
|
||||
<p>
|
||||
From v2.0.0 of this library, the value of the coefficient of a BigNumber is stored in a
|
||||
normalised base <code>100000000000000</code> floating point format, as opposed to the base
|
||||
|
@ -1856,6 +1844,18 @@ z.toExponential() // '-1.234567e+4'
|
|||
z.c // '1,2,3,4,5,6,7'
|
||||
z.e // 4
|
||||
z.s // -1</pre>
|
||||
<p>Checking if a value is a BigNumber instance:</p>
|
||||
<pre>
|
||||
x = new BigNumber(3)
|
||||
x instanceof BigNumber // true
|
||||
x.isBigNumber // true
|
||||
|
||||
BN = BigNumber.another();
|
||||
|
||||
y = new BN(3)
|
||||
y instanceof BigNumber // false
|
||||
y.isBigNumber // true</pre>
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
'divToInt',
|
||||
'dp',
|
||||
'floor',
|
||||
'isBigNumber',
|
||||
'minmax',
|
||||
'minus',
|
||||
'mod',
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
<!-- <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> -->
|
||||
|
|
|
@ -16,7 +16,6 @@ console.log( '\n STARTING TESTS...\n' );
|
|||
'divToInt',
|
||||
'dp',
|
||||
'floor',
|
||||
'isBigNumber',
|
||||
'minmax',
|
||||
'minus',
|
||||
'mod',
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
var count = (function isBigNumber(BigNumber) {
|
||||
var start = +new Date(),
|
||||
log,
|
||||
error,
|
||||
u,
|
||||
passed = 0,
|
||||
total = 0;
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
log = console.log;
|
||||
error = console.error;
|
||||
} else {
|
||||
log = function (str) { document.body.innerHTML += str.replace('\n', '<br>') };
|
||||
error = function (str) { document.body.innerHTML += '<div style="color: red">' +
|
||||
str.replace('\n', '<br>') + '</div>' };
|
||||
}
|
||||
|
||||
if (!BigNumber && typeof require === 'function') BigNumber = require('../bignumber');
|
||||
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
}
|
||||
|
||||
function T(expected, value){
|
||||
assert(expected, BigNumber.isBigNumber(value));
|
||||
}
|
||||
|
||||
log('\n Testing isBigNumber...');
|
||||
|
||||
T(false, u);
|
||||
T(false, void 0);
|
||||
T(false, null);
|
||||
T(false, '0');
|
||||
T(false, 0);
|
||||
T(false, 1);
|
||||
T(false, NaN);
|
||||
|
||||
T(true, new BigNumber(0));
|
||||
T(true, new BigNumber('0'));
|
||||
T(true, new BigNumber(1));
|
||||
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'));
|
||||
|
||||
log('\n ' + passed + ' of ' + total + ' tests passed in ' + (+new Date() - start) + ' ms \n');
|
||||
return [passed, total];
|
||||
})(this.BigNumber);
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = count;
|
Loading…
Reference in New Issue