mirror of
https://github.com/MikeMcl/big.js.git
synced 2026-01-25 16:04:15 +00:00
Rename Big.E_POS to Big.PE, Big.E_NEG to Big.NE.
Refactor error messaging. Throw if null is passed to toFixed etc. and amend tests accordingly. Clean-up and reformat.
This commit is contained in:
parent
c6fadd083a
commit
0b79acd7aa
2
LICENCE
2
LICENCE
@ -1,6 +1,6 @@
|
||||
The MIT Expat Licence.
|
||||
|
||||
Copyright (c) 2012 Michael Mclaughlin
|
||||
Copyright (c) 2017 Michael Mclaughlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
12
README.md
12
README.md
@ -150,8 +150,6 @@ For Node, if uglify-js is installed globally ( `npm install uglify-js -g` ) then
|
||||
|
||||
will create *big.min.js*.
|
||||
|
||||
The *big.min.js* already present was created with *Microsoft Ajax Minifier 5.11*.
|
||||
|
||||
## TypeScript
|
||||
|
||||
The [DefinitelyTyped](https://github.com/borisyankov/DefinitelyTyped) project has a TypeScript [definitions file](https://github.com/borisyankov/DefinitelyTyped/blob/master/big.js/big.js.d.ts) for big.js.
|
||||
@ -172,9 +170,7 @@ Open an issue, or email
|
||||
Michael
|
||||
<a href="mailto:M8ch88l@gmail.com">M8ch88l@gmail.com</a>
|
||||
|
||||
Bitcoin donation to:
|
||||
**1DppGRQSjVSMgGxuygDEHQuWEdTiVEzJYG**
|
||||
Thank you
|
||||
BTC **1DppGRQSjVSMgGxuygDEHQuWEdTiVEzJYG**
|
||||
|
||||
## Licence
|
||||
|
||||
@ -200,8 +196,7 @@ See LICENCE.
|
||||
|
||||
####3.1.0
|
||||
|
||||
* Renamed and exposed `TO_EXP_NEG` and `TO_EXP_POS` as `Big.E_NEG` and
|
||||
`Big.E_POS`.
|
||||
* Renamed and exposed `TO_EXP_NEG` and `TO_EXP_POS` as `Big.E_NEG` and `Big.E_POS`.
|
||||
|
||||
####3.0.2
|
||||
|
||||
@ -215,8 +210,7 @@ See LICENCE.
|
||||
####3.0.0
|
||||
|
||||
* 10/12/14 Added [multiple constructor functionality](http://mikemcl.github.io/big.js/#faq).
|
||||
* No breaking changes or other additions, but a major code reorganisation,
|
||||
so *v3* seemed appropriate.
|
||||
* No breaking changes or other additions, but a major code reorganisation, so *v3* seemed appropiate.
|
||||
|
||||
####2.5.2
|
||||
|
||||
|
||||
2
big.min.js
vendored
2
big.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
137
doc/bigAPI.html
137
doc/bigAPI.html
@ -68,8 +68,8 @@ code,pre{font-family:Monaco,Consolas,"Lucida Console",monospace;
|
||||
<ul>
|
||||
<li><a href="#dp" >DP</a></li>
|
||||
<li><a href="#rm" >RM</a></li>
|
||||
<li><a href="#eneg">E_NEG</a></li>
|
||||
<li><a href="#epos">E_POS</a></li>
|
||||
<li><a href="#eneg">NE</a></li>
|
||||
<li><a href="#epos">PE</a></li>
|
||||
</ul>
|
||||
|
||||
<b> INSTANCE </b>
|
||||
@ -191,8 +191,7 @@ new Big('-735.0918e-430') // '-7.350918e-428'</pre>
|
||||
</p>
|
||||
<p>
|
||||
The value will be checked for validity when one of the above methods is
|
||||
called.<br /> <code class='error'>!Big.DP!</code> will be thrown if the
|
||||
value is found to be invalid.
|
||||
called.<br /> An error will be thrown if the value is found to be invalid.
|
||||
</p>
|
||||
<pre>Big.DP = 40</pre>
|
||||
|
||||
@ -248,14 +247,13 @@ new Big('-735.0918e-430') // '-7.350918e-428'</pre>
|
||||
</table>
|
||||
<p>
|
||||
The value will be checked for validity when one of the above methods is
|
||||
called.<br /> <code class='error'>!Big.RM!</code> will be thrown if the
|
||||
value is found to be invalid.
|
||||
called.<br /> An error will be thrown if the value is found to be invalid.
|
||||
</p>
|
||||
<pre>Big.RM = 0</pre>
|
||||
|
||||
|
||||
|
||||
<h5 id="eneg">E_NEG</h5>
|
||||
|
||||
|
||||
|
||||
<h5 id="eneg">NE</h5>
|
||||
<p>
|
||||
<i>number</i> : integer, -1e+6 to 0 inclusive<br />
|
||||
Default value: <code>-7</code>
|
||||
@ -265,7 +263,7 @@ new Big('-735.0918e-430') // '-7.350918e-428'</pre>
|
||||
<a href='#toS'><code>toString</code></a> returns exponential notation.
|
||||
</p>
|
||||
<pre>
|
||||
Big.E_NEG = -7
|
||||
Big.NE = -7
|
||||
x = new Big(0.00000123) // '0.00000123' e is -6
|
||||
x = new Big(0.000000123) // '1.23e-7'</pre>
|
||||
<p>
|
||||
@ -273,7 +271,7 @@ x = new Big(0.000000123) // '1.23e-7'</pre>
|
||||
<code>-7</code> and below.
|
||||
</p>
|
||||
<p>
|
||||
Regardless of the value of <code>Big.E_NEG</code>, the
|
||||
Regardless of the value of <code>Big.NE</code>, the
|
||||
<a href='#toF'><code>toFixed</code></a> method will always return a value
|
||||
in normal notation and the <a href='#toE'><code>toExponential</code></a>
|
||||
method will always return a value in exponential form.
|
||||
@ -281,7 +279,7 @@ x = new Big(0.000000123) // '1.23e-7'</pre>
|
||||
|
||||
|
||||
|
||||
<h5 id="epos">E_POS</h5>
|
||||
<h5 id="epos">PE</h5>
|
||||
<p>
|
||||
<i>number</i> : integer, 0 to 1e+6 inclusive<br />
|
||||
Default value: <code>21</code>
|
||||
@ -291,7 +289,7 @@ x = new Big(0.000000123) // '1.23e-7'</pre>
|
||||
<a href='#toS'><code>toString</code></a> returns exponential notation.
|
||||
</p>
|
||||
<pre>
|
||||
Big.E_POS = 2
|
||||
Big.PE = 2
|
||||
x = new Big(12.3) // '12.3' e is 1
|
||||
x = new Big(123) // '1.23e+2'</pre>
|
||||
<p>
|
||||
@ -299,7 +297,7 @@ x = new Big(123) // '1.23e+2'</pre>
|
||||
<code>21</code> and above.
|
||||
</p>
|
||||
<p>
|
||||
Regardless of the value of <code>Big.E_POS</code>, the
|
||||
Regardless of the value of <code>Big.PE</code>, the
|
||||
<a href='#toF'><code>toFixed</code></a> method will always return a value
|
||||
in normal notation and the <a href='#toE'><code>toExponential</code></a>
|
||||
method will always return a value in exponential form.
|
||||
@ -556,7 +554,7 @@ Big(0.7).plus(x).plus(y) // '1.1'</pre>
|
||||
rounding mode <a href='#rm'><code>Big.RM</code></a>.
|
||||
</p>
|
||||
<p>
|
||||
Throws <code class='error'>!pow!</code> if <code>exp</code> is invalid.
|
||||
Throws if <code>exp</code> is invalid.
|
||||
</p>
|
||||
<p>
|
||||
Note: High value exponents may cause this method to be slow to return.
|
||||
@ -588,16 +586,13 @@ new Big(2).pow(1e+6) // Time taken (Node.js): 9 minutes 34 secs.</pre>
|
||||
decimal places.
|
||||
</p>
|
||||
<p>
|
||||
if <code>dp</code> is omitted or is <code>null</code> or undefined, the
|
||||
return value is <code>n</code> rounded to a whole number.<br />
|
||||
if <code>rm</code> is omitted or is <code>null</code> or
|
||||
undefined, the current <a href='#rm'><code>Big.RM</code></a> setting is
|
||||
used.
|
||||
if <code>dp</code> is omitted or is undefined, the return value is
|
||||
<code>n</code> rounded to a whole number.<br />
|
||||
if <code>rm</code> is omitted or is undefined, the current
|
||||
<a href='#rm'><code>Big.RM</code></a> setting is used.
|
||||
</p>
|
||||
<p>
|
||||
Throws <code class='error'>!round!</code> if <code>dp</code> is invalid.
|
||||
<br />
|
||||
Throws <code class='error'>!Big.RM!</code> if <code>rm</code> is invalid.
|
||||
Throws if <code>dp</code> or <code>rm</code> is invalid.
|
||||
</p>
|
||||
<pre>
|
||||
x = 123.45
|
||||
@ -671,12 +666,12 @@ Big('7e+500').times(y) // '1.26e+501'</pre>
|
||||
the return value will be appended with zeros accordingly.
|
||||
</p>
|
||||
<p>
|
||||
If <code>dp</code> is omitted, or is <code>null</code> or undefined, the
|
||||
number of digits after the decimal point defaults to the minimum number of
|
||||
digits necessary to represent the value exactly.
|
||||
If <code>dp</code> is omitted or is undefined, the number of digits
|
||||
after the decimal point defaults to the minimum number of digits
|
||||
necessary to represent the value exactly.
|
||||
</p>
|
||||
<p>
|
||||
Throws <code class='error'>!toExp!</code> if <code>dp</code> is invalid.
|
||||
Throws if <code>dp</code> is invalid.
|
||||
</p>
|
||||
<pre>
|
||||
x = 45.6
|
||||
@ -720,13 +715,13 @@ y.toExponential(3) // '4.560e+1'</pre>
|
||||
this method will always return normal notation.
|
||||
</p>
|
||||
<p>
|
||||
If <code>dp</code> is omitted, or is <code>null</code> or
|
||||
undefined, then the return value is simply the value in normal notation.
|
||||
This is also unlike <code>Number.prototype.toFixed</code>, which returns
|
||||
the value to zero decimal places.
|
||||
If <code>dp</code> is omitted or is undefined, the return value is
|
||||
simply the value in normal notation. This is also unlike
|
||||
<code>Number.prototype.toFixed</code>, which returns the value to zero
|
||||
decimal places.
|
||||
</p>
|
||||
<p>
|
||||
Throws <code class='error'>!toFix!</code> if <code>dp</code> is invalid.
|
||||
Throws if <code>dp</code> is invalid.
|
||||
</p>
|
||||
<pre>
|
||||
x = 45.6
|
||||
@ -760,15 +755,15 @@ y.toFixed(3) // '45.600'</pre>
|
||||
</p>
|
||||
<p>
|
||||
If <code>sd</code> is less than the number of digits necessary to
|
||||
represent the integer part of the value in normal notation, then
|
||||
represent the integer part of the value in normal notation,
|
||||
exponential notation is used.
|
||||
</p>
|
||||
<p>
|
||||
If <code>sd</code> is omitted, or is <code>null</code> or undefined, then
|
||||
the return value is the same as <code>.toString()</code>.
|
||||
If <code>sd</code> is omitted or is undefined, the return value is
|
||||
the same as <code>.toString()</code>.
|
||||
</p>
|
||||
<p>
|
||||
Throws <code class='error'>!toPre!</code> if <code>sd</code> is invalid.
|
||||
Throws if <code>sd</code> is invalid.
|
||||
</p>
|
||||
<pre>
|
||||
x = 45.6
|
||||
@ -790,14 +785,14 @@ y.toPrecision(5) // '45.600'</pre>
|
||||
</p>
|
||||
<p>
|
||||
If this Big number has a positive exponent that is equal to or greater
|
||||
than 21, or a negative exponent equal to or less than -7, then exponential
|
||||
than 21, or a negative exponent equal to or less than -7, exponential
|
||||
notation is returned.
|
||||
</p>
|
||||
<p>
|
||||
The point at which <code>toString</code> returns exponential rather than
|
||||
normal notation can be adjusted by changing the value of
|
||||
<a href='#epos'><code>Big.E_POS</code></a> and
|
||||
<a href='#eneg'><code>Big.E_NEG</code></a>. By default, Big numbers
|
||||
<a href='#epos'><code>Big.PE</code></a> and
|
||||
<a href='#eneg'><code>Big.NE</code></a>. By default, Big numbers
|
||||
correspond to Javascript's number type in this regard.
|
||||
</p>
|
||||
<pre>
|
||||
@ -929,9 +924,9 @@ y.s // -1</pre>
|
||||
|
||||
<h4 id='Errors'>Errors</h4>
|
||||
<p>
|
||||
The errors that are thrown are instances of <code>Error</code> with
|
||||
<code>name</code> <code class='error'>BigError</code> and message as
|
||||
shown in the table below.
|
||||
The errors that are thrown are instances of <code>Error</code>.<br />
|
||||
The <code>message</code> of the errors always begins with
|
||||
<code class='error'>[BigError]</code>.
|
||||
</p>
|
||||
<table>
|
||||
<tr>
|
||||
@ -959,11 +954,11 @@ y.s // -1</pre>
|
||||
<td>Division of zero by zero</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>!Big.DP!</td>
|
||||
<td>DP: <i>invalidValue</i></td>
|
||||
<td>Invalid Big.DP</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>!Big.RM!</td>
|
||||
<td>RM: <i>invalidValue</i></td>
|
||||
<td>Invalid Big.RM</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -973,24 +968,24 @@ y.s // -1</pre>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=3><code>pow</code></td>
|
||||
<td>!pow!</td>
|
||||
<td><i>invalidValue</i></td>
|
||||
<td>Invalid exponent</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>!Big.DP!</td>
|
||||
<td>DP: <i>invalidValue</i></td>
|
||||
<td>Invalid Big.DP</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>!Big.RM!</td>
|
||||
<td>RM: <i>invalidValue</i></td>
|
||||
<td>Invalid Big.RM</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=2><code>round</code></td>
|
||||
<td>!round!</td>
|
||||
<td><i>invalidValue</i></td>
|
||||
<td>Invalid dp</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>!Big.RM!</td>
|
||||
<td>RM: <i>invalidValue</i></td>
|
||||
<td>Invalid rm/Big.RM</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -999,38 +994,38 @@ y.s // -1</pre>
|
||||
<td>Negative number</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>!Big.DP!</td>
|
||||
<td>DP: <i>invalidValue</i></td>
|
||||
<td>Invalid Big.DP</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>!Big.RM!</td>
|
||||
<td>RM: <i>invalidValue</i></td>
|
||||
<td>Invalid Big.RM</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=2><code>toExponential</code></td>
|
||||
<td>!toExp!</td>
|
||||
<td><i>invalidValue</i></td>
|
||||
<td>Invalid dp</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>!Big.RM!</td>
|
||||
<td>RM: <i>invalidValue</i></td>
|
||||
<td>Invalid Big.RM</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=2><code>toFixed</code></td>
|
||||
<td>!toFix!</td>
|
||||
<td><i>invalidValue</i></td>
|
||||
<td>Invalid dp</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>!Big.RM!</td>
|
||||
<td>RM: <i>invalidValue</i></td>
|
||||
<td>Invalid Big.RM</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=2><code>toPrecision</code></td>
|
||||
<td>!toPre!</td>
|
||||
<td><i>invalidValue</i></td>
|
||||
<td>Invalid sd</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>!Big.RM!</td>
|
||||
<td>RM: <i>invalidValue</i></td>
|
||||
<td>Invalid Big.RM</td>
|
||||
</tr>
|
||||
</table>
|
||||
@ -1061,8 +1056,8 @@ x + 0 // '12345.67890' (string concatenation, do not use!)
|
||||
x = new Big('9.87654e+32')
|
||||
parseInt(x) // 9
|
||||
parseInt(+x) // 9
|
||||
parseInt(x.toFixed()) // 9.87654e+32
|
||||
parseInt(x.round()) // 9.87654e+32
|
||||
parseInt(x.toFixed()) // 9.87654e+32
|
||||
parseInt(x.round()) // 9.87654e+32
|
||||
</pre>
|
||||
<p>
|
||||
The <code>Math</code> methods can also be used.
|
||||
@ -1070,10 +1065,10 @@ parseInt(x.round()) // 9.87654e+32
|
||||
<pre>
|
||||
x = new Big('1234.56')
|
||||
Math.floor(x) // 1234
|
||||
Math.round(x) // 1235
|
||||
Math.round(x) // 1235
|
||||
</pre>
|
||||
<br />
|
||||
|
||||
|
||||
<h6>
|
||||
How can I round a Big number to a specified number of significant digits?
|
||||
</h6>
|
||||
@ -1087,11 +1082,11 @@ Math.round(x) // 1235
|
||||
<pre>
|
||||
x = new Big('987.654321')
|
||||
len = x.c.length // 9
|
||||
if (len > 6) x.c.length = 6
|
||||
x // 987.654
|
||||
if (len > 6) x.c.length = 6
|
||||
x // 987.654
|
||||
</pre>
|
||||
<br />
|
||||
|
||||
|
||||
<h6>
|
||||
How can I set the decimal places and/or rounding mode for just one
|
||||
operation?
|
||||
@ -1126,12 +1121,12 @@ Big.prototype.div = (function () {
|
||||
Big = this.constructor,
|
||||
_dp = Big.DP,
|
||||
_rm = Big.RM;
|
||||
if (dp != null) Big.DP = dp;
|
||||
if (rm != null) Big.RM = rm;
|
||||
if (dp != undefined) Big.DP = dp;
|
||||
if (rm != undefined) Big.RM = rm;
|
||||
result = div.call(this, n);
|
||||
Big.DP = _dp;
|
||||
Big.RM = _rm;
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
})();
|
||||
|
||||
@ -1179,7 +1174,7 @@ y.div(3) // 1.6666666667
|
||||
isolated and untouchable by another, its prototype methods are not.
|
||||
</p>
|
||||
<br />
|
||||
|
||||
|
||||
<h6>Why are trailing fractional zeros removed from Big numbers?</h6>
|
||||
<p>
|
||||
Many arbitrary-precision libraries retain trailing fractional zeros as
|
||||
@ -1224,10 +1219,10 @@ z = x.multiply(y) // 4.1400000
|
||||
Instead, the <code>toExponential</code>, <code>toFixed</code> and
|
||||
<code>toPrecision</code> methods enable trailing zeros to be added if and
|
||||
when required.
|
||||
</p>
|
||||
</p>
|
||||
<br />
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
11
test/abs.js
11
test/abs.js
@ -19,12 +19,11 @@ var count = (function abs(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
script = document.createElement("script");
|
||||
script.src = '../' + methods[i] + '.js';
|
||||
if (!methods[i++]) {
|
||||
document.body.innerHTML += '<br>IN TOTAL: ' + passed + ' of ' + total +
|
||||
document.body.innerHTML += '<br>RESULTS: ' + passed + ' of ' + total +
|
||||
' tests passed in ' + ( (+new Date() - start) / 1000 ) + ' secs.<br>';
|
||||
document.body.scrollIntoView(false);
|
||||
return;
|
||||
|
||||
11
test/cmp.js
11
test/cmp.js
@ -20,12 +20,11 @@ var count = (function cmp(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
|
||||
11
test/div.js
11
test/div.js
@ -20,12 +20,11 @@ var count = (function div(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
|
||||
@ -27,5 +27,5 @@ console.log( '\n STARTING TESTS...\n' );
|
||||
total += arr[1];
|
||||
});
|
||||
|
||||
console.log( '\n IN TOTAL: ' + passed + ' of ' + total + ' tests passed in ' +
|
||||
console.log( '\n RESULTS: ' + passed + ' of ' + total + ' tests passed in ' +
|
||||
( (+new Date() - start) / 1000 ) + ' secs.\n' );
|
||||
@ -20,12 +20,11 @@ var count = (function minus(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
|
||||
11
test/mod.js
11
test/mod.js
@ -20,12 +20,11 @@ var count = (function mod(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
|
||||
11
test/plus.js
11
test/plus.js
@ -20,12 +20,11 @@ var count = (function plus(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
|
||||
11
test/pow.js
11
test/pow.js
@ -21,12 +21,11 @@ var count = (function pow(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
|
||||
@ -20,12 +20,11 @@ var count = (function round(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
@ -351,57 +350,24 @@ var count = (function round(Big) {
|
||||
T('-0.519371276718530514624846800754582116141529266132757', '-0.5193712767185305146248468007545821161415292661327570320784267894852821486214528653', 51, 0);
|
||||
|
||||
T(1, 1.23, u, u);
|
||||
T(1, 1.23, null, u);
|
||||
T(1, 1.23, u, null);
|
||||
T(1, 1.23, null, null);
|
||||
T(-1, -1.23, u, u);
|
||||
T(-1, -1.23, null, u);
|
||||
T(-1, -1.23, u, null);
|
||||
T(-1, -1.23, null, null);
|
||||
T(568, '567.89', u, u);
|
||||
T(568, '567.89', null, u);
|
||||
T(568, '567.89', u, null);
|
||||
T(568, '567.89', null, null);
|
||||
T(-568, -'567.89', u, u);
|
||||
T(-568, -'567.89', null, u);
|
||||
T(-568, -'567.89', u, null);
|
||||
T(-568, -'567.89', null, null);
|
||||
T('12.35', '12.345', 2);
|
||||
T('12', '12.345', u);
|
||||
T('12', '12.345', null);
|
||||
|
||||
Big.DP = 20;
|
||||
Big.RM = 2;
|
||||
|
||||
T(1, 1.23, u, u);
|
||||
T(1, 1.23, null, u);
|
||||
T(1, 1.23, u, null);
|
||||
T(1, 1.23, null, null);
|
||||
T(-1, -1.23, u, u);
|
||||
T(-1, -1.23, null, u);
|
||||
T(-1, -1.23, u, null);
|
||||
T(-1, -1.23, null, null);
|
||||
T('4', 4.5, u, u);
|
||||
T('4', 4.5, null, u);
|
||||
T('4', 4.5, u, null);
|
||||
T('4', 4.5, null, null);
|
||||
T('-4', -4.5, u, u);
|
||||
T('-4', -4.5, null, u);
|
||||
T('-4', -4.5, u, null);
|
||||
T('-4', -4.5, null, null);
|
||||
T(569, '568.9', u, u);
|
||||
T(569, '568.9', null, u);
|
||||
T(569, '568.9', u, null);
|
||||
T(569, '568.9', null, null);
|
||||
T(-569, -'568.9', u, u);
|
||||
T(-569, -'568.9', null, u);
|
||||
T(-569, -'568.9', u, null);
|
||||
T(-569, -'568.9', null, null);
|
||||
T('12.34', '12.345', 2);
|
||||
T('12', '12.345', u);
|
||||
T('12', '12.345', null);
|
||||
T('12', '12.345', u, 2);
|
||||
T('12', '12.345', u, null);
|
||||
|
||||
T('3', '3', 0, 0);
|
||||
T('3.4157', '3.41571', 4, 0);
|
||||
@ -5021,6 +4987,7 @@ var count = (function round(Big) {
|
||||
T('-3.59089828969834447089866670409563698613796519920887260893628116796219699700295155566574700974305862881829539116842175156625589321038153746830136335430975180117738583836263157892672949110363994957437257028596753086911681027493231687723660583340473066987864559390829822248332270981499602035052694294589999780431928143466271681066767593313168237835986350589527099528400107655526657067e+260', '-359089828969834447089866670409563698613796519920887260893628116796219699700295155566574700974305862881829539116842175156625589321038153746830136335430975180117738583836263157892672949110363994957437257028596753086911681027493231687723660583340473066987864559390.829822248332270981499602035052694294589999780431928143466271681066767593313168237835986350589527099528400107655526657067124497659393816422837799218949133277601595497917912674114827477096642873285066389309250196072308994823837109436543139707', 120, 2);
|
||||
T('8.9952767699784490329238753106556088240055363532827226609029521944449657384883384170667072930734367679170716914947678038820950440722219201194e+43', '89952767699784490329238753106556088240055363.53282722660902952194444965738488338417066707293073436767917071691494767803882095044072221920119400608976324854', 97, 2);
|
||||
|
||||
assertException(function () {new Big('12.345').round(null)}, ".round(null)");
|
||||
assertException(function () {new Big('12.345').round(NaN)}, ".round(NaN)");
|
||||
assertException(function () {new Big('12.345').round('NaN')}, ".round('NaN')");
|
||||
assertException(function () {new Big('12.345').round([])}, ".round([])");
|
||||
@ -5049,6 +5016,7 @@ var count = (function round(Big) {
|
||||
assertException(function () {new Big('12.345').round('-Infinity')}, ".round('-Infinity')");
|
||||
assertException(function () {new Big('12.345').round(new Big('2'))}, ".round(new Big('2'))");
|
||||
|
||||
assertException(function () {new Big('12.345').round(u, null)}, ".round(u, null)");
|
||||
assertException(function () {new Big('12.345').round(u, NaN)}, ".round(u, NaN)");
|
||||
assertException(function () {new Big('12.345').round(u, 'NaN')}, ".round(u, 'NaN')");
|
||||
assertException(function () {new Big('12.345').round(u, [])}, ".round(u, [])");
|
||||
@ -5138,34 +5106,14 @@ var count = (function round(Big) {
|
||||
|
||||
T(2, 1.23);
|
||||
T(2, 1.23, u, u);
|
||||
T(2, 1.23, null, u);
|
||||
T(2, 1.23, u, null);
|
||||
T(2, 1.23, null, null);
|
||||
T(-2, -1.23, u, u);
|
||||
T(-2, -1.23, null, u);
|
||||
T(-2, -1.23, u, null);
|
||||
T(-2, -1.23, null, null);
|
||||
T('5', 4.5, u, u);
|
||||
T('5', 4.5, null, u);
|
||||
T('5', 4.5, u, null);
|
||||
T('5', 4.5, null, null);
|
||||
T('-5', -4.5, u, u);
|
||||
T('-5', -4.5, null, u);
|
||||
T('-5', -4.5, u, null);
|
||||
T('-5', -4.5, null, null);
|
||||
T(569, '568.9', u, u);
|
||||
T(569, '568.9', null, u);
|
||||
T(569, '568.9', u, null);
|
||||
T(569, '568.9', null, null);
|
||||
T(-569, -'568.9', u, u);
|
||||
T(-569, -'568.9', null, u);
|
||||
T(-569, -'568.9', u, null);
|
||||
T(-569, -'568.9', null, null);
|
||||
T('12.35', '12.345', 2);
|
||||
T('13', '12.345', u);
|
||||
T('13', '12.345', null);
|
||||
T('12', '12.345', u, 2);
|
||||
T('13', '12.345', u, null);
|
||||
|
||||
log('\n ' + passed + ' of ' + total + ' tests passed in ' + (+new Date() - start) + ' ms \n');
|
||||
return [passed, total];;
|
||||
|
||||
11
test/sqrt.js
11
test/sqrt.js
@ -20,12 +20,11 @@ var count = (function sqrt(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
|
||||
@ -20,12 +20,11 @@ var count = (function times(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
|
||||
@ -20,12 +20,11 @@ var count = (function toExponential(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
@ -396,11 +395,11 @@ var count = (function toExponential(Big) {
|
||||
T('-3.00e+0', '-3', 2);
|
||||
T('-5.00e-2', '-0.05', 2);
|
||||
T('1.00e-2', '0.01', 2);
|
||||
T('1.23e+2', '12.3e1', null);
|
||||
T('1.23e+2', '12.3e1', undefined);
|
||||
T('1e+2', '12.3e1', 0);
|
||||
T('1e+2', '12.3e1', -0);
|
||||
|
||||
assertException(function () {new Big(1.23).toExponential(null)}, "null");
|
||||
assertException(function () {new Big(1.23).toExponential(NaN)}, "NaN");
|
||||
assertException(function () {new Big(1.23).toExponential('NaN')}, "'NaN'");
|
||||
assertException(function () {new Big(1.23).toExponential([])}, "[]");
|
||||
@ -460,7 +459,6 @@ var count = (function toExponential(Big) {
|
||||
T('-3.00e+0', '-3', 2);
|
||||
T('-5.00e-2', '-0.05', 2);
|
||||
T('1.00e-2', '0.01', 2);
|
||||
T('1.23e+2', '12.3e1', null);
|
||||
T('1.23e+2', '12.3e1', undefined);
|
||||
T('2e+2', '12.3e1', 0);
|
||||
T('-2e+2', '-12.3e1', 0);
|
||||
|
||||
@ -20,12 +20,11 @@ var count = (function toFixed(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
@ -969,11 +968,11 @@ var count = (function toFixed(Big) {
|
||||
'353090531769.175603436034231639743395165930222246484607747046044079492519304034422365673974111568710016025760763' +
|
||||
'83664408162624867351605015229777701990865326902932136430587015275752666401315258528531504569482239').toFixed(100));
|
||||
|
||||
T('123.45', '12.345e1', null);
|
||||
T('123.45', '12.345e1', u);
|
||||
T('123', '12.345e1', 0);
|
||||
T('123', '12.345e1', -0);
|
||||
|
||||
assertException(function () {new Big(1.23).toFixed(null)}, "null");
|
||||
assertException(function () {new Big(1.23).toFixed(NaN)}, "NaN");
|
||||
assertException(function () {new Big(1.23).toFixed('NaN')}, "'NaN'");
|
||||
assertException(function () {new Big(1.23).toFixed([])}, "[]");
|
||||
@ -1006,6 +1005,7 @@ var count = (function toFixed(Big) {
|
||||
|
||||
// ROUND_UP
|
||||
Big.RM = 3
|
||||
|
||||
T('0.0', '0', 1);
|
||||
T('0.1', '0.1', 1);
|
||||
T('-0.1', '-0.1', 1);
|
||||
@ -1024,6 +1024,65 @@ var count = (function toFixed(Big) {
|
||||
T('1000.00', '999.9901', 2);
|
||||
T('-1000.00', '-999.9901', 2);
|
||||
|
||||
/*
|
||||
Big.DP = 20;
|
||||
Big.RM = 1;
|
||||
|
||||
Big.DS = '.'; // decimal separator
|
||||
Big.TS = ','; // thousands separator
|
||||
|
||||
T('0', 0);
|
||||
T('1', 1);
|
||||
T('-1', -1);
|
||||
T('123.456', 123.456);
|
||||
|
||||
T('1', 1, undefined);
|
||||
T('-1', -1, 0);
|
||||
T('123.456', 123.456, 3);
|
||||
|
||||
T('0.0', 0, 1);
|
||||
T('1.00', 1, 2);
|
||||
T('-1.000', -1, 3);
|
||||
T('123.4560', 123.456, 4);
|
||||
|
||||
T('9,876.54321', 9876.54321);
|
||||
T('4,018,736,400,000,000,000,000', '4.0187364e+21');
|
||||
|
||||
T('999,999,999,999,999', 999999999999999);
|
||||
T('99,999,999,999,999', 99999999999999);
|
||||
T('9,999,999,999,999', 9999999999999);
|
||||
T('999,999,999,999', 999999999999);
|
||||
T('99,999,999,999', 99999999999);
|
||||
T('9,999,999,999', 9999999999);
|
||||
T('999,999,999', 999999999);
|
||||
T('99,999,999', 99999999);
|
||||
T('9,999,999', 9999999);
|
||||
T('999,999', 999999);
|
||||
T('99,999', 99999);
|
||||
T('9,999', 9999);
|
||||
T('999', 999);
|
||||
T('99', 99);
|
||||
T('9', 9);
|
||||
|
||||
T('76,852.342091', '7.6852342091e+4');
|
||||
|
||||
Big.TS = ' ';
|
||||
|
||||
T('76 852.34', '7.6852342091e+4', 2);
|
||||
T('-76 852.342091', '-7.6852342091e+4');
|
||||
T('76 852.3420910871', '7.6852342091087145832640897e+4', 10);
|
||||
T('4 018 736 400 000 000 000 000', '4.0187364e+21');
|
||||
|
||||
Big.DS = ',';
|
||||
Big.TS = '.';
|
||||
|
||||
T('-1.234.560.000,000000000008', '-1.23456000000000000000789e+9', 12);
|
||||
|
||||
Big.TS = '';
|
||||
|
||||
T('10000000000123456789000000,0000000001', '10000000000123456789000000.000000000100000001', 10);
|
||||
*/
|
||||
|
||||
log('\n ' + passed + ' of ' + total + ' tests passed in ' + (+new Date() - start) + ' ms \n');
|
||||
return [passed, total];;
|
||||
})(this.Big);
|
||||
|
||||
@ -20,12 +20,11 @@ var count = (function toPrecision(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
@ -411,9 +410,9 @@ var count = (function toPrecision(Big) {
|
||||
T('243028.94040290384317164750687246', '243028.940402903843171647506872458168411478', 32);
|
||||
T('5313610990.737', '5313610990.7373810218', 13);
|
||||
T('-3.56e+4', '-35566.4678487', 3);
|
||||
T('123.45', '12.345e1', null);
|
||||
T('123.45', '12.345e1', undefined);
|
||||
|
||||
assertException(function () {new Big(1.23).toPrecision(null)}, "null");
|
||||
assertException(function () {new Big(1.23).toPrecision(NaN)}, "NaN");
|
||||
assertException(function () {new Big(1.23).toPrecision('NaN')}, "'NaN'");
|
||||
assertException(function () {new Big(1.23).toPrecision([])}, "[]");
|
||||
|
||||
@ -19,12 +19,11 @@ var count = (function toString(Big) {
|
||||
function assert(expected, actual) {
|
||||
total++;
|
||||
if (expected !== actual) {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
}
|
||||
else {
|
||||
error('\n Test number: ' + total + ' failed');
|
||||
error(' Expected: ' + expected);
|
||||
error(' Actual: ' + actual);
|
||||
//process.exit();
|
||||
} else {
|
||||
passed++;
|
||||
//log('\n Expected and actual: ' + actual);
|
||||
}
|
||||
@ -50,8 +49,8 @@ var count = (function toString(Big) {
|
||||
|
||||
log('\n Testing toString...');
|
||||
|
||||
Big.E_NEG = -7;
|
||||
Big.E_POS = 21;
|
||||
Big.NE = -7;
|
||||
Big.PE = 21;
|
||||
|
||||
// ---------------------------------------------------------------------- v8
|
||||
|
||||
@ -1065,8 +1064,8 @@ var count = (function toString(Big) {
|
||||
assertException(function () {Big(Infinity)}, "new Big(Infinity)");
|
||||
assertException(function () {new Big('-Infinity')}, "new Big('-Infinity')");
|
||||
|
||||
Big.E_NEG = -10;
|
||||
Big.E_POS = 10;
|
||||
Big.NE = -10;
|
||||
Big.PE = 10;
|
||||
|
||||
T('1234567890', '1234567890');
|
||||
T('1.2345678901e+10', '12345678901');
|
||||
@ -1076,4 +1075,4 @@ var count = (function toString(Big) {
|
||||
log('\n ' + passed + ' of ' + total + ' tests passed in ' + (+new Date() - start) + ' ms \n');
|
||||
return [passed, total];;
|
||||
})(this.Big);
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = count;
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = count;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user