Socket
Socket
Sign inDemoInstall

big.js

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

big.js - npm Package Compare versions

Comparing version 2.5.1 to 3.0.0

bower.json

990

big.js

@@ -1,126 +0,214 @@

/* big.js v2.5.1 https://github.com/MikeMcl/big.js/LICENCE */
;(function ( global ) {
/* big.js v3.0.0 https://github.com/MikeMcl/big.js/LICENCE */
;(function (global) {
'use strict';
/*
big.js v2.5.1
A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
https://github.com/MikeMcl/big.js/
Copyright (c) 2012 Michael Mclaughlin <M8ch88l@gmail.com>
MIT Expat Licence
*/
/*
big.js v3.0.0
A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
https://github.com/MikeMcl/big.js/
Copyright (c) 2014 Michael Mclaughlin <M8ch88l@gmail.com>
MIT Expat Licence
*/
/****************************** EDITABLE DEFAULTS **********************************/
/***************************** EDITABLE DEFAULTS ******************************/
// The default values below must be integers within the stated ranges.
// The default values below must be integers within the stated ranges (inclusive).
/*
* The maximum number of decimal places of the results of methods involving
* division, i.e. 'div' and 'sqrt', and 'pow' with negative exponents.
* The maximum number of decimal places of the results of operations
* involving division: div and sqrt, and pow with negative exponents.
*/
Big['DP'] = 20; // 0 to MAX_DP
var DP = 20, // 0 to MAX_DP
/*
* The rounding mode used when rounding to the above decimal places.
*
* 0 Round towards zero (i.e. truncate, no rounding). (ROUND_DOWN)
* 1 Round to nearest neighbour. If equidistant, round up. (ROUND_HALF_UP)
* 2 Round to nearest neighbour. If equidistant, to even neighbour. (ROUND_HALF_EVEN)
* 3 Round away from zero. (ROUND_UP)
*/
Big['RM'] = 1; // 0, 1, 2 or 3
/*
* The rounding mode used when rounding to the above decimal places.
*
* 0 Towards zero (i.e. truncate, no rounding). (ROUND_DOWN)
* 1 To nearest neighbour. If equidistant, round up. (ROUND_HALF_UP)
* 2 To nearest neighbour. If equidistant, to even. (ROUND_HALF_EVEN)
* 3 Away from zero. (ROUND_UP)
*/
RM = 1, // 0, 1, 2 or 3
// The maximum value of 'Big.DP'.
var MAX_DP = 1E6, // 0 to 1e+6
// The maximum value of DP and Big.DP.
MAX_DP = 1E6, // 0 to 1000000
// The maximum magnitude of the exponent argument to the 'pow' method.
MAX_POWER = 1E6, // 1 to 1e+6
// The maximum magnitude of the exponent argument to the pow method.
MAX_POWER = 1E6, // 1 to 1000000
/*
* The exponent value at and beneath which 'toString' returns exponential notation.
* Javascript's Number type: -7
* -1e+6 is the minimum recommended exponent value of a Big.
* The exponent value at and beneath which toString returns exponential
* notation.
* JavaScript's Number type: -7
* -1000000 is the minimum recommended exponent value of a Big.
*/
TO_EXP_NEG = -7, // 0 to -1e+6
TO_EXP_NEG = -7, // 0 to -1000000
/*
* The exponent value at and above which 'toString' returns exponential notation.
* Javascript's Number type: 21
* 1e+6 is the maximum recommended exponent value of a Big, though there is no
* enforcing or checking of a limit.
* The exponent value at and above which toString returns exponential
* notation.
* JavaScript's Number type: 21
* 1000000 is the maximum recommended exponent value of a Big.
* (This limit is not enforced or checked.)
*/
TO_EXP_POS = 21, // 0 to 1e+6
TO_EXP_POS = 21, // 0 to 1000000
/******************************************************************************/
/***********************************************************************************/
P = Big.prototype,
// The shared prototype object.
P = {},
isValid = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,
ONE = new Big(1);
Big;
// CONSTRUCTOR
/*
* Create and return a Big constructor.
*
*/
function bigFactory() {
/*
* The Big constructor and exported function.
* Create and return a new instance of a Big number object.
*
* n {number|string|Big} A numeric value.
*/
function Big(n) {
var x = this;
// Enable constructor usage without new.
if (!(x instanceof Big)) {
return n === void 0 ? bigFactory() : new Big(n)
}
// Duplicate.
if (n instanceof Big) {
x['s'] = n['s'];
x['e'] = n['e'];
x['c'] = n['c'].slice();
} else {
parse(x, n)
}
/*
* Retain a reference to this Big constructor, and shadow
* Big.prototype.constructor which points to Object.
*/
x['constructor'] = Big
}
Big.prototype = P;
Big['DP'] = DP;
Big['RM'] = RM;
return Big
}
// Private functions
/*
* The exported function.
* Create and return a new instance of a Big object.
* Return a string representing the value of Big x in normal or exponential
* notation to dp fixed decimal places or significant digits.
*
* n {number|string|Big} A numeric value.
* x {Big} The Big to format.
* dp {number} Integer, 0 to MAX_DP inclusive.
* toE {number} 1 (toExponential), 2 (toPrecision) or undefined (toFixed).
*/
function Big( n ) {
var i, j, nL,
x = this;
function format(x, dp, toE) {
var Big = x['constructor'],
// Enable constructor usage without new.
if ( !(x instanceof Big) ) {
return new Big( n )
// The index (normal notation) of the digit that may be rounded up.
i = dp - (x = new Big(x))['e'],
c = x['c'];
// Round?
if (c.length > ++dp) {
rnd(x, i, Big['RM'])
}
// Duplicate.
if ( n instanceof Big ) {
x['s'] = n['s'];
x['e'] = n['e'];
x['c'] = n['c'].slice();
return
if (!c[0]) {
++i;
} else if (toE) {
i = dp;
// toFixed
} else {
c = x['c'];
// Recalculate i as x.e may have changed if value rounded up.
i = x['e'] + i + 1;
}
// Append zeros?
for (; c.length < i; c.push(0)) {
}
i = x['e'];
/*
* toPrecision returns exponential notation if the number of
* significant digits specified is less than the number of digits
* necessary to represent the integer part of the value in normal
* notation.
*/
return toE === 1 || toE && (dp <= i || i <= TO_EXP_NEG)
// Exponential notation.
? (x['s'] < 0 && c[0] ? '-' : '') +
(c.length > 1 ? c[0] + '.' + c.join('').slice(1) : c[0]) +
(i < 0 ? 'e' : 'e+') + i
// Normal notation.
: x.toString()
}
/*
* Parse the number or string value passed to a Big constructor.
*
* x {Big} A Big number instance.
* n {number|string} A numeric value.
*/
function parse(x, n) {
var e, i, nL;
// Minus zero?
if ( n === 0 && 1 / n < 0 ) {
if (n === 0 && 1 / n < 0) {
n = '-0'
// Ensure 'n' is string and check validity.
} else if ( !isValid.test(n += '') ) {
throwErr( NaN )
// Ensure n is string and check validity.
} else if (!isValid.test(n += '')) {
throwErr(NaN)
}
// Determine sign.
x['s'] = n.charAt(0) == '-' ? ( n = n.slice(1), -1 ) : 1;
x['s'] = n.charAt(0) == '-' ? (n = n.slice(1), -1) : 1;
// Decimal point?
if ( ( i = n.indexOf('.') ) > -1 ) {
n = n.replace( '.', '' )
if ((e = n.indexOf('.')) > -1) {
n = n.replace('.', '')
}
// Exponential form?
if ( ( j = n.search(/e/i) ) > 0 ) {
if ((i = n.search(/e/i)) > 0) {
// Determine exponent.
if ( i < 0 ) {
i = j
if (e < 0) {
e = i
}
i += +n.slice( j + 1 );
n = n.substring( 0, j )
e += +n.slice(i + 1);
n = n.substring(0, i)
} else if ( i < 0 ) {
} else if (e < 0) {
// Integer.
i = n.length
e = n.length
}
// Determine leading zeros.
for ( j = 0; n.charAt(j) == '0'; j++ ) {
for (i = 0; n.charAt(i) == '0'; i++) {
}
if ( j == ( nL = n.length ) ) {
if (i == (nL = n.length)) {

@@ -132,48 +220,60 @@ // Zero.

// Determine trailing zeros.
for ( ; n.charAt(--nL) == '0'; ) {
for (; n.charAt(--nL) == '0';) {
}
x['e'] = i - j - 1;
x['e'] = e - i - 1;
x['c'] = [];
// Convert string to array of digits (without leading and trailing zeros).
for ( i = 0; j <= nL; x['c'][i++] = +n.charAt(j++) ) {
// Convert string to array of digits without leading/trailing zeros.
for (e = 0; i <= nL; x['c'][e++] = +n.charAt(i++)) {
}
}
return x
}
// PRIVATE FUNCTIONS
/*
* Round Big 'x' to a maximum of 'dp' decimal places using rounding mode
* 'rm'. (Called by 'div', 'sqrt' and 'round'.)
* Round Big x to a maximum of dp decimal places using rounding mode rm.
* Called by div, sqrt and round.
*
* x {Big} The Big to round.
* dp {number} Integer, 0 to MAX_DP inclusive.
* rm {number} 0, 1, 2 or 3 ( ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP )
* rm {number} 0, 1, 2 or 3 (DOWN, HALF_UP, HALF_EVEN, UP)
* [more] {boolean} Whether the result of division was truncated.
*/
function rnd( x, dp, rm, more ) {
var xc = x['c'],
function rnd(x, dp, rm, more) {
var u,
xc = x['c'],
i = x['e'] + dp + 1;
if ( rm === 1 ) {
// 'xc[i]' is the digit after the digit that may be rounded up.
if (rm === 1) {
// xc[i] is the digit after the digit that may be rounded up.
more = xc[i] >= 5
} else if ( rm === 2 ) {
more = xc[i] > 5 || xc[i] == 5 && ( more || i < 0 || xc[i + 1] != null || xc[i - 1] & 1 )
} else if ( rm === 3 ) {
more = more || xc[i] != null || i < 0
} else if ( more = false, rm !== 0 ) {
throwErr( '!Big.RM!' )
} else if (rm === 2) {
more = xc[i] > 5 || xc[i] == 5 &&
(more || i < 0 || xc[i + 1] !== u || xc[i - 1] & 1)
} else if (rm === 3) {
more = more || xc[i] !== u || i < 0
} else {
more = false;
if (rm !== 0) {
throwErr('!Big.RM!')
}
}
if ( i < 1 || !xc[0] ) {
x['c'] = more
// 1, 0.1, 0.01, 0.001, 0.0001 etc.
? ( x['e'] = -dp, [1] )
// Zero.
: [ x['e'] = 0 ];
if (i < 1 || !xc[0]) {
if (more) {
// 1, 0.1, 0.01, 0.001, 0.0001 etc.
x['e'] = -dp;
x['c'] = [1]
} else {
// Zero.
x['c'] = [x['e'] = 0]
}
} else {

@@ -185,9 +285,9 @@

// Round up?
if ( more ) {
if (more) {
// Rounding up may mean the previous digit has to be rounded up and so on.
for ( ; ++xc[i] > 9; ) {
// Rounding up may mean the previous digit has to be rounded up.
for (; ++xc[i] > 9;) {
xc[i] = 0;
if ( !i-- ) {
if (!i--) {
++x['e'];

@@ -200,3 +300,3 @@ xc.unshift(1)

// Remove trailing zeros.
for ( i = xc.length; !xc[--i]; xc.pop() ) {
for (i = xc.length; !xc[--i]; xc.pop()) {
}

@@ -214,4 +314,4 @@ }

*/
function throwErr( message ) {
var err = new Error( message );
function throwErr(message) {
var err = new Error(message);
err['name'] = 'BigError';

@@ -223,3 +323,3 @@

// PROTOTYPE/INSTANCE METHODS
// Prototype/instance methods

@@ -231,3 +331,3 @@

P['abs'] = function () {
var x = new Big(this);
var x = new this['constructor'](this);
x['s'] = 1;

@@ -241,11 +341,11 @@

* Return
* 1 if the value of this 'Big' is greater than the value of 'Big' 'y',
* -1 if the value of this 'Big' is less than the value of 'Big' 'y', or
* 1 if the value of this Big is greater than the value of Big y,
* -1 if the value of this Big is less than the value of Big y, or
* 0 if they have the same value.
*/
P['cmp'] = function ( y ) {
P['cmp'] = function (y) {
var xNeg,
x = this,
xc = x['c'],
yc = ( y = new Big( y ) )['c'],
yc = (y = new x['constructor'](y))['c'],
i = x['s'],

@@ -257,3 +357,3 @@ j = y['s'],

// Either zero?
if ( !xc[0] || !yc[0] ) {
if (!xc[0] || !yc[0]) {
return !xc[0] ? !yc[0] ? 0 : -j : i

@@ -263,3 +363,3 @@ }

// Signs differ?
if ( i != j ) {
if (i != j) {
return i

@@ -270,12 +370,13 @@ }

// Compare exponents.
if ( k != l ) {
if (k != l) {
return k > l ^ xNeg ? 1 : -1
}
i = -1;
j = (k = xc.length) < (l = yc.length) ? k : l;
// Compare digit by digit.
for ( i = -1,
j = ( k = xc.length ) < ( l = yc.length ) ? k : l;
++i < j; ) {
for (; ++i < j;) {
if ( xc[i] != yc[i] ) {
if (xc[i] != yc[i]) {
return xc[i] > yc[i] ^ xNeg ? 1 : -1

@@ -292,46 +393,50 @@ }

* Return a new Big whose value is the value of this Big divided by the
* value of Big 'y', rounded, if necessary, to a maximum of 'Big.DP'
* decimal places using rounding mode 'Big.RM'.
* value of Big y, rounded, if necessary, to a maximum of Big.DP decimal
* places using rounding mode Big.RM.
*/
P['div'] = function ( y ) {
P['div'] = function (y) {
var x = this,
Big = x['constructor'],
// dividend
dvd = x['c'],
dvs = ( y = new Big(y) )['c'],
//divisor
dvs = (y = new Big(y))['c'],
s = x['s'] == y['s'] ? 1 : -1,
dp = Big['DP'];
if ( dp !== ~~dp || dp < 0 || dp > MAX_DP ) {
throwErr( '!Big.DP!' )
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
throwErr('!Big.DP!')
}
// Either 0?
if ( !dvd[0] || !dvs[0] ) {
if (!dvd[0] || !dvs[0]) {
// Both 0?
if ( dvd[0] == dvs[0] ) {
throwErr( NaN )
// If both are 0, throw NaN
if (dvd[0] == dvs[0]) {
throwErr(NaN)
}
// 'dvs' is 0?
if ( !dvs[0] ) {
// Throw +-Infinity.
throwErr( s / 0 )
// If dvs is 0, throw +-Infinity.
if (!dvs[0]) {
throwErr(s / 0)
}
// 'dvd' is 0. Return +-0.
return new Big( s * 0 )
// dvd is 0, return +-0.
return new Big(s * 0)
}
var dvsL, dvsT, next, cmp, remI,
var dvsL, dvsT, next, cmp, remI, u,
dvsZ = dvs.slice(),
dvdI = dvsL = dvs.length,
dvdL = dvd.length,
rem = dvd.slice( 0, dvsL ),
// remainder
rem = dvd.slice(0, dvsL),
remL = rem.length,
quo = new Big(ONE),
qc = quo['c'] = [],
// quotient
q = y,
qc = q['c'] = [],
qi = 0,
digits = dp + ( quo['e'] = x['e'] - y['e'] ) + 1;
digits = dp + (q['e'] = x['e'] - y['e']) + 1;
quo['s'] = s;
q['s'] = s;
s = digits < 0 ? 0 : digits;

@@ -343,3 +448,3 @@

// Add zeros to make remainder as long as divisor.
for ( ; remL++ < dvsL; rem.push(0) ) {
for (; remL++ < dvsL; rem.push(0)) {
}

@@ -349,12 +454,13 @@

// 'next' is how many times the divisor goes into the current remainder.
for ( next = 0; next < 10; next++ ) {
// 'next' is how many times the divisor goes into current remainder.
for (next = 0; next < 10; next++) {
// Compare divisor and remainder.
if ( dvsL != ( remL = rem.length ) ) {
if (dvsL != (remL = rem.length)) {
cmp = dvsL > remL ? 1 : -1
} else {
for ( remI = -1, cmp = 0; ++remI < dvsL; ) {
if ( dvs[remI] != rem[remI] ) {
for (remI = -1, cmp = 0; ++remI < dvsL;) {
if (dvs[remI] != rem[remI]) {
cmp = dvs[remI] > rem[remI] ? 1 : -1;

@@ -366,14 +472,13 @@ break

// Subtract divisor from remainder (if divisor < remainder).
if ( cmp < 0 ) {
// If divisor < remainder, subtract divisor from remainder.
if (cmp < 0) {
// Remainder cannot be more than one digit longer than divisor.
// Remainder can't be more than 1 digit longer than divisor.
// Equalise lengths using divisor with extra leading zero?
for ( dvsT = remL == dvsL ? dvs : dvsZ; remL; ) {
for (dvsT = remL == dvsL ? dvs : dvsZ; remL;) {
if ( rem[--remL] < dvsT[remL] ) {
if (rem[--remL] < dvsT[remL]) {
remI = remL;
for ( remI = remL;
remI && !rem[--remI];
rem[remI] = 9 ) {
for (; remI && !rem[--remI]; rem[remI] = 9) {
}

@@ -385,3 +490,3 @@ --rem[remI];

}
for ( ; !rem[0]; rem.shift() ) {
for (; !rem[0]; rem.shift()) {
}

@@ -397,31 +502,33 @@ } else {

// Update the remainder.
rem[0] && cmp
? ( rem[remL] = dvd[dvdI] || 0 )
: ( rem = [ dvd[dvdI] ] )
if (rem[0] && cmp) {
rem[remL] = dvd[dvdI] || 0
} else {
rem = [ dvd[dvdI] ]
}
} while ( ( dvdI++ < dvdL || rem[0] != null ) && s-- );
} while ((dvdI++ < dvdL || rem[0] !== u) && s--);
// Leading zero? Do not remove if result is simply zero (qi == 1).
if ( !qc[0] && qi != 1) {
if (!qc[0] && qi != 1) {
// There can't be more than one zero.
qc.shift();
quo['e']--;
q['e']--
}
// Round?
if ( qi > digits ) {
rnd( quo, dp, Big['RM'], rem[0] != null )
if (qi > digits) {
rnd(q, dp, Big['RM'], rem[0] !== u)
}
return quo
}
return q
};
/*
* Return true if the value of this Big is equal to the value of Big 'y',
* Return true if the value of this Big is equal to the value of Big y,
* otherwise returns false.
*/
P['eq'] = function ( y ) {
return !this.cmp( y )
P['eq'] = function (y) {
return !this.cmp(y)
};

@@ -431,7 +538,7 @@

/*
* Return true if the value of this Big is greater than the value of Big 'y',
* Return true if the value of this Big is greater than the value of Big y,
* otherwise returns false.
*/
P['gt'] = function ( y ) {
return this.cmp( y ) > 0
P['gt'] = function (y) {
return this.cmp(y) > 0
};

@@ -442,6 +549,6 @@

* Return true if the value of this Big is greater than or equal to the
* value of Big 'y', otherwise returns false.
* value of Big y, otherwise returns false.
*/
P['gte'] = function ( y ) {
return this.cmp( y ) > -1
P['gte'] = function (y) {
return this.cmp(y) > -1
};

@@ -451,7 +558,7 @@

/*
* Return true if the value of this Big is less than the value of Big 'y',
* Return true if the value of this Big is less than the value of Big y,
* otherwise returns false.
*/
P['lt'] = function ( y ) {
return this.cmp( y ) < 0
P['lt'] = function (y) {
return this.cmp(y) < 0
};

@@ -462,6 +569,6 @@

* Return true if the value of this Big is less than or equal to the value
* of Big 'y', otherwise returns false.
* of Big y, otherwise returns false.
*/
P['lte'] = function ( y ) {
return this.cmp( y ) < 1
P['lte'] = function (y) {
return this.cmp(y) < 1
};

@@ -472,13 +579,15 @@

* Return a new Big whose value is the value of this Big minus the value
* of Big 'y'.
* of Big y.
*/
P['minus'] = function ( y ) {
var d, i, j, xLTy,
P['minus'] = function (y) {
var i, j, t, xLTy,
x = this,
Big = x['constructor'],
a = x['s'],
b = ( y = new Big( y ) )['s'];
b = (y = new Big(y))['s'];
// Signs differ?
if ( a != b ) {
return y['s'] = -b, x['plus'](y)
if (a != b) {
y['s'] = -b;
return x['plus'](y)
}

@@ -492,12 +601,6 @@

// Either zero?
if ( !xc[0] || !yc[0] ) {
if (!xc[0] || !yc[0]) {
// 'y' is non-zero?
return yc[0]
? ( y['s'] = -b, y )
// 'x' is non-zero?
: new Big( xc[0]
? x
// Both are zero.
: 0 )
// y is non-zero? x is non-zero? Or both are zero.
return yc[0] ? (y['s'] = -b, y) : new Big(xc[0] ? x : 0)
}

@@ -507,16 +610,24 @@

// Prepend zeros to equalise exponents.
if ( a = xe - ye ) {
d = ( xLTy = a < 0 ) ? ( a = -a, xc ) : ( ye = xe, yc );
if (a = xe - ye) {
for ( d.reverse(), b = a; b--; d.push(0) ) {
if (xLTy = a < 0) {
a = -a;
t = xc
} else {
ye = xe;
t = yc
}
d.reverse()
t.reverse();
for (b = a; b--; t.push(0)) {
}
t.reverse()
} else {
// Exponents equal. Check digit by digit.
j = ( ( xLTy = xc.length < yc.length ) ? xc : yc ).length;
j = ((xLTy = xc.length < yc.length) ? xc : yc).length;
for ( a = b = 0; b < j; b++ ) {
for (a = b = 0; b < j; b++) {
if ( xc[b] != yc[b] ) {
if (xc[b] != yc[b]) {
xLTy = xc[b] < yc[b];

@@ -528,5 +639,7 @@ break

// 'x' < 'y'? Point 'xc' to the array of the bigger number.
if ( xLTy ) {
d = xc, xc = yc, yc = d;
// x < y? Point xc to the array of the bigger number.
if (xLTy) {
t = xc;
xc = yc;
yc = t;
y['s'] = -y['s']

@@ -536,33 +649,35 @@ }

/*
* Append zeros to 'xc' if shorter. No need to add zeros to 'yc' if shorter
* as subtraction only needs to start at 'yc.length'.
* Append zeros to xc if shorter. No need to add zeros to yc if shorter
* as subtraction only needs to start at yc.length.
*/
if ( ( b = -( ( j = xc.length ) - yc.length ) ) > 0 ) {
if (( b = (j = yc.length) - (i = xc.length) ) > 0) {
for ( ; b--; xc[j++] = 0 ) {
for (; b--; xc[i++] = 0) {
}
}
// Subtract 'yc' from 'xc'.
for ( b = yc.length; b > a; ){
// Subtract yc from xc.
for (b = i; j > a;){
if ( xc[--b] < yc[b] ) {
if (xc[--j] < yc[j]) {
for ( i = b; i && !xc[--i]; xc[i] = 9 ) {
for (i = j; i && !xc[--i]; xc[i] = 9) {
}
--xc[i];
xc[b] += 10
xc[j] += 10
}
xc[b] -= yc[b]
xc[j] -= yc[j]
}
// Remove trailing zeros.
for ( ; xc[--j] == 0; xc.pop() ) {
for (; xc[--b] == 0; xc.pop()) {
}
// Remove leading zeros and adjust exponent accordingly.
for ( ; xc[0] == 0; xc.shift(), --ye ) {
for (; xc[0] == 0;) {
xc.shift();
--ye
}
if ( !xc[0] ) {
if (!xc[0]) {

@@ -576,3 +691,6 @@ // n - n = +0

return y['c'] = xc, y['e'] = ye, y
y['c'] = xc;
y['e'] = ye;
return y
};

@@ -583,26 +701,32 @@

* Return a new Big whose value is the value of this Big modulo the
* value of Big 'y'.
* value of Big y.
*/
P['mod'] = function ( y ) {
y = new Big( y );
var c,
P['mod'] = function (y) {
var yGTx,
x = this,
i = x['s'],
j = y['s'];
Big = x['constructor'],
a = x['s'],
b = (y = new Big(y))['s'];
if ( !y['c'][0] ) {
throwErr( NaN )
if (!y['c'][0]) {
throwErr(NaN)
}
x['s'] = y['s'] = 1;
c = y.cmp( x ) == 1;
x['s'] = i, y['s'] = j;
yGTx = y.cmp(x) == 1;
x['s'] = a;
y['s'] = b;
return c
? new Big(x)
: ( i = Big['DP'], j = Big['RM'],
Big['DP'] = Big['RM'] = 0,
x = x['div'](y),
Big['DP'] = i, Big['RM'] = j,
this['minus']( x['times'](y) ) )
if (yGTx) {
return new Big(x)
}
a = Big['DP'];
b = Big['RM'];
Big['DP'] = Big['RM'] = 0;
x = x['div'](y);
Big['DP'] = a;
Big['RM'] = b;
return this['minus']( x['times'](y) )
};

@@ -613,13 +737,15 @@

* Return a new Big whose value is the value of this Big plus the value
* of Big 'y'.
* of Big y.
*/
P['plus'] = function ( y ) {
var d,
P['plus'] = function (y) {
var t,
x = this,
Big = x['constructor'],
a = x['s'],
b = ( y = new Big( y ) )['s'];
b = (y = new Big(y))['s'];
// Signs differ?
if ( a != b ) {
return y['s'] = -b, x['minus'](y)
if (a != b) {
y['s'] = -b;
return x['minus'](y)
}

@@ -633,37 +759,42 @@

// Either zero?
if ( !xc[0] || !yc[0] ) {
if (!xc[0] || !yc[0]) {
// 'y' is non-zero?
return yc[0]
? y
: new Big( xc[0]
// 'x' is non-zero?
? x
// Both are zero. Return zero.
: a * 0 )
// y is non-zero? x is non-zero? Or both are zero.
return yc[0] ? y : new Big(xc[0] ? x : a * 0)
}
xc = xc.slice();
// Prepend zeros to equalise exponents.
// Note: Faster to use reverse then do unshifts.
if ( xc = xc.slice(), a = xe - ye ) {
d = a > 0 ? ( ye = xe, yc ) : ( a = -a, xc );
if (a = xe - ye) {
for ( d.reverse(); a--; d.push(0) ) {
if (a > 0) {
ye = xe;
t = yc
} else {
a = -a;
t = xc
}
d.reverse()
t.reverse();
for (; a--; t.push(0)) {
}
t.reverse()
}
// Point 'xc' to the longer array.
if ( xc.length - yc.length < 0 ) {
d = yc, yc = xc, xc = d
// Point xc to the longer array.
if (xc.length - yc.length < 0) {
t = yc;
yc = xc;
xc = t
}
a = yc.length;
/*
* Only start adding at 'yc.length - 1' as the
* further digits of 'xc' can be left as they are.
* Only start adding at yc.length - 1 as the further digits of xc can be
* left as they are.
*/
for ( a = yc.length, b = 0; a;
b = ( xc[--a] = xc[a] + yc[a] + b ) / 10 ^ 0, xc[a] %= 10 ) {
for (b = 0; a;) {
b = (xc[--a] = xc[a] + yc[a] + b) / 10 | 0;
xc[a] %= 10
}

@@ -673,3 +804,3 @@

if ( b ) {
if (b) {
xc.unshift(b);

@@ -680,6 +811,9 @@ ++ye

// Remove trailing zeros.
for ( a = xc.length; xc[--a] == 0; xc.pop() ) {
for (a = xc.length; xc[--a] == 0; xc.pop()) {
}
return y['c'] = xc, y['e'] = ye, y
y['c'] = xc;
y['e'] = ye;
return y
};

@@ -689,25 +823,28 @@

/*
* Return a Big whose value is the value of this Big raised to the power
* 'e'. If 'e' is negative, round, if necessary, to a maximum of 'Big.DP'
* decimal places using rounding mode 'Big.RM'.
* Return a Big whose value is the value of this Big raised to the power n.
* If n is negative, round, if necessary, to a maximum of Big.DP decimal
* places using rounding mode Big.RM.
*
* e {number} Integer, -MAX_POWER to MAX_POWER inclusive.
* n {number} Integer, -MAX_POWER to MAX_POWER inclusive.
*/
P['pow'] = function ( e ) {
var isNeg = e < 0,
x = new Big(this),
y = ONE;
P['pow'] = function (n) {
var x = this,
one = new x['constructor'](1),
y = one,
isNeg = n < 0;
if ( e !== ~~e || e < -MAX_POWER || e > MAX_POWER ) {
throwErr( '!pow!' )
if (n !== ~~n || n < -MAX_POWER || n > MAX_POWER) {
throwErr('!pow!')
}
for ( e = isNeg ? -e : e; ; ) {
n = isNeg ? -n : n;
if ( e & 1 ) {
for (;;) {
if (n & 1) {
y = y['times'](x)
}
e >>= 1;
n >>= 1;
if ( !e ) {
if (!n) {
break

@@ -718,3 +855,3 @@ }

return isNeg ? ONE['div'](y) : y
return isNeg ? one['div'](y) : y
};

@@ -724,19 +861,20 @@

/*
* Return a new Big whose value is the value of this Big rounded, if
* necessary, to a maximum of 'dp' decimal places using rounding mode 'rm'.
* If 'dp' is not specified, round to 0 decimal places.
* If 'rm' is not specified, use 'Big.RM'.
* Return a new Big whose value is the value of this Big rounded to a
* maximum of dp decimal places using rounding mode rm.
* If dp is not specified, round to 0 decimal places.
* If rm is not specified, use Big.RM.
*
* [dp] {number} Integer, 0 to MAX_DP inclusive.
* [rm] 0, 1, 2 or 3 ( ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP )
* [rm] 0, 1, 2 or 3 (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP)
*/
P['round'] = function ( dp, rm ) {
var x = new Big(this);
P['round'] = function (dp, rm) {
var x = this,
Big = x['constructor'];
if ( dp == null ) {
if (dp == null) {
dp = 0
} else if ( dp !== ~~dp || dp < 0 || dp > MAX_DP ) {
throwErr( '!round!' )
} else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
throwErr('!round!')
}
rnd( x, dp, rm == null ? Big['RM'] : rm );
rnd(x = new Big(x), dp, rm == null ? Big['RM'] : rm);

@@ -748,5 +886,5 @@ return x

/*
* Return a new Big whose value is the square root of the value of this
* Big, rounded, if necessary, to a maximum of 'Big.DP' decimal places
* using rounding mode 'Big.RM'.
* Return a new Big whose value is the square root of the value of this Big,
* rounded, if necessary, to a maximum of Big.DP decimal places using
* rounding mode Big.RM.
*/

@@ -756,2 +894,3 @@ P['sqrt'] = function () {

x = this,
Big = x['constructor'],
xc = x['c'],

@@ -763,20 +902,20 @@ i = x['s'],

// Zero?
if ( !xc[0] ) {
if (!xc[0]) {
return new Big(x)
}
// Negative?
if ( i < 0 ) {
throwErr( NaN )
// If negative, throw NaN.
if (i < 0) {
throwErr(NaN)
}
// Estimate.
i = Math.sqrt( x.toString() );
i = Math.sqrt(x.toString());
// Math.sqrt underflow/overflow?
// Pass 'x' to Math.sqrt as integer, then adjust the exponent of the result.
if ( i == 0 || i == 1 / 0 ) {
// Pass x to Math.sqrt as integer, then adjust the result exponent.
if (i == 0 || i == 1 / 0) {
estimate = xc.join('');
if ( !( estimate.length + e & 1 ) ) {
if (!(estimate.length + e & 1)) {
estimate += '0'

@@ -786,17 +925,17 @@ }

r = new Big( Math.sqrt(estimate).toString() );
r['e'] = ( ( ( e + 1 ) / 2 ) | 0 ) - ( e < 0 || e & 1 )
r['e'] = ((e + 1) / 2 | 0) - (e < 0 || e & 1)
} else {
r = new Big( i.toString() )
r = new Big(i.toString())
}
i = r['e'] + ( Big['DP'] += 4 );
i = r['e'] + (Big['DP'] += 4);
// Newton-Raphson loop.
// Newton-Raphson iteration.
do {
approx = r;
r = half['times']( approx['plus']( x['div'](approx) ) )
} while ( approx['c'].slice( 0, i ).join('') !==
r['c'].slice( 0, i ).join('') );
} while ( approx['c'].slice(0, i).join('') !==
r['c'].slice(0, i).join('') );
rnd( r, Big['DP'] -= 4, Big['RM'] );
rnd(r, Big['DP'] -= 4, Big['RM']);

@@ -808,10 +947,11 @@ return r

/*
* Return a new Big whose value is the value of this Big times the value
* of Big 'y'.
* Return a new Big whose value is the value of this Big times the value of
* Big y.
*/
P['times'] = function ( y ) {
P['times'] = function (y) {
var c,
x = this,
Big = x['constructor'],
xc = x['c'],
yc = ( y = new Big( y ) )['c'],
yc = (y = new Big(y))['c'],
a = xc.length,

@@ -822,44 +962,62 @@ b = yc.length,

// Determine sign of result.
y['s'] = x['s'] == y['s'] ? 1 : -1;
// Either 0?
if ( !xc[0] || !yc[0] ) {
return new Big( y['s'] * 0 )
// Return signed 0 if either 0.
if (!xc[0] || !yc[0]) {
return new Big(y['s'] * 0)
}
// Initialise exponent of result as x.e + y.e.
y['e'] = i + j;
if ( a < b ) {
c = xc, xc = yc, yc = c, j = a, a = b, b = j
// If array xc has fewer digits than yc, swap xc and yc, and lengths.
if (a < b) {
c = xc;
xc = yc;
yc = c;
j = a;
a = b;
b = j
}
for ( j = a + b, c = []; j--; c.push(0) ) {
// Initialise coefficient array of result with zeros.
for (c = new Array(j = a + b); j--; c[j] = 0) {
}
// Multiply!
for ( i = b - 1; i > -1; i-- ) {
// Multiply.
for ( b = 0, j = a + i;
j > i;
b = c[j] + yc[i] * xc[j - i - 1] + b,
c[j--] = b % 10 | 0,
b = b / 10 | 0 ) {
}
// i is initially xc.length.
for (i = b; i--;) {
b = 0;
if ( b ) {
c[j] = ( c[j] + b ) % 10
// a is yc.length.
for (j = a + i; j > i;) {
// Current sum of products at this digit position, plus carry.
b = c[j] + yc[i] * xc[j - i - 1] + b;
c[j--] = b % 10;
// carry
b = b / 10 | 0
}
c[j] = (c[j] + b) % 10
}
b && ++y['e'];
// Increment result exponent if there is a final carry.
if (b) {
++y['e']
}
// Remove any leading zero.
!c[0] && c.shift();
if (!c[0]) {
c.shift()
}
// Remove trailing zeros.
for ( j = c.length; !c[--j]; c.pop() ) {
for (i = c.length; !c[--i]; c.pop()) {
}
y['c'] = c;
return y['c'] = c, y
return y
};

@@ -870,5 +1028,5 @@

* Return a string representing the value of this Big.
* Return exponential notation if this Big has a positive exponent equal
* to or greater than 'TO_EXP_POS', or a negative exponent equal to or less
* than 'TO_EXP_NEG'.
* Return exponential notation if this Big has a positive exponent equal to
* or greater than TO_EXP_POS, or a negative exponent equal to or less than
* TO_EXP_NEG.
*/

@@ -882,11 +1040,11 @@ P['toString'] = P['valueOf'] = P['toJSON'] = function () {

// Exponential notation?
if ( e <= TO_EXP_NEG || e >= TO_EXP_POS ) {
str = str.charAt(0) + ( strL > 1 ? '.' + str.slice(1) : '' ) +
( e < 0 ? 'e' : 'e+' ) + e
if (e <= TO_EXP_NEG || e >= TO_EXP_POS) {
str = str.charAt(0) + (strL > 1 ? '.' + str.slice(1) : '') +
(e < 0 ? 'e' : 'e+') + e
// Negative exponent?
} else if ( e < 0 ) {
} else if (e < 0) {
// Prepend zeros.
for ( ; ++e; str = '0' + str ) {
// Prepend zeros.
for (; ++e; str = '0' + str) {
}

@@ -896,15 +1054,15 @@ str = '0.' + str

// Positive exponent?
} else if ( e > 0 ) {
} else if (e > 0) {
if ( ++e > strL ) {
if (++e > strL) {
// Append zeros.
for ( e -= strL; e-- ; str += '0' ) {
for (e -= strL; e-- ; str += '0') {
}
} else if ( e < strL ) {
str = str.slice( 0, e ) + '.' + str.slice(e)
} else if (e < strL) {
str = str.slice(0, e) + '.' + str.slice(e)
}
// Exponent zero.
} else if ( strL > 1 ) {
} else if (strL > 1) {
str = str.charAt(0) + '.' + str.slice(1)

@@ -920,6 +1078,5 @@ }

***************************************************************************
* If 'toExponential', 'toFixed', 'toPrecision' and 'format' are not
* required they can safely be commented-out or deleted. No redundant code
* will be left. 'format' is used only by 'toExponential', 'toFixed' and
* 'toPrecision'.
* If toExponential, toFixed, toPrecision and format are not required they
* can safely be commented-out or deleted. No redundant code will be left.
* format is used only by toExponential, toFixed and toPrecision.
***************************************************************************

@@ -930,65 +1087,17 @@ */

/*
* PRIVATE FUNCTION
*
* Return a string representing the value of Big 'x' in normal or
* exponential notation to a fixed number of decimal places or significant
* digits 'dp'.
* (Called by toString, toExponential, toFixed and toPrecision.)
*
* x {Big} The Big to format.
* dp {number} Integer, 0 to MAX_DP inclusive.
* toE {number} undefined (toFixed), 1 (toExponential) or 2 (toPrecision).
*/
function format( x, dp, toE ) {
// The index (in normal notation) of the digit that may be rounded up.
var i = dp - ( x = new Big(x) )['e'],
c = x['c'];
// Round?
if ( c.length > ++dp ) {
rnd( x, i, Big['RM'] )
}
// Recalculate 'i' if toFixed as 'x.e' may have changed if value rounded up.
i = !c[0] ? i + 1 : toE ? dp : ( c = x['c'], x['e'] + i + 1 );
// Append zeros?
for ( ; c.length < i; c.push(0) ) {
}
i = x['e'];
/*
* 'toPrecision' returns exponential notation if the number of
* significant digits specified is less than the number of digits
* necessary to represent the integer part of the value in normal
* notation.
*/
return toE == 1 || toE == 2 && ( dp <= i || i <= TO_EXP_NEG )
// Exponential notation.
? ( x['s'] < 0 && c[0] ? '-' : '' ) + ( c.length > 1
? ( c.splice( 1, 0, '.' ), c.join('') )
: c[0] ) + ( i < 0 ? 'e' : 'e+' ) + i
// Normal notation.
: x.toString()
}
/*
* Return a string representing the value of this Big in exponential
* notation to 'dp' fixed decimal places and rounded, if necessary, using
* 'Big.RM'.
* notation to dp fixed decimal places and rounded, if necessary, using
* Big.RM.
*
* [dp] {number} Integer, 0 to MAX_DP inclusive.
*/
P['toExponential'] = function ( dp ) {
P['toExponential'] = function (dp) {
if ( dp == null ) {
if (dp == null) {
dp = this['c'].length - 1
} else if ( dp !== ~~dp || dp < 0 || dp > MAX_DP ) {
throwErr( '!toExp!' )
} else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
throwErr('!toExp!')
}
return format( this, dp, 1 )
return format(this, dp, 1)
};

@@ -999,7 +1108,7 @@

* Return a string representing the value of this Big in normal notation
* to 'dp' fixed decimal places and rounded, if necessary, using 'Big.RM'.
* to dp fixed decimal places and rounded, if necessary, using Big.RM.
*
* [dp] {number} Integer, 0 to MAX_DP inclusive.
*/
P['toFixed'] = function ( dp ) {
P['toFixed'] = function (dp) {
var str,

@@ -1010,20 +1119,22 @@ x = this,

TO_EXP_NEG = -( TO_EXP_POS = 1 / 0 );
// Prevent the possibility of exponential notation.
TO_EXP_NEG = -(TO_EXP_POS = 1 / 0);
if ( dp == null ) {
if (dp == null) {
str = x.toString()
} else if ( dp === ~~dp && dp >= 0 && dp <= MAX_DP ) {
str = format( x, x['e'] + dp );
} else if (dp === ~~dp && dp >= 0 && dp <= MAX_DP) {
str = format(x, x['e'] + dp);
// (-0).toFixed() is '0', but (-0.1).toFixed() is '-0'.
// (-0).toFixed(1) is '0.0', but (-0.01).toFixed(1) is '-0.0'.
if ( x['s'] < 0 && x['c'][0] && str.indexOf('-') < 0 ) {
// As e.g. -0.5 if rounded to -0 will cause toString to omit the minus sign.
if (x['s'] < 0 && x['c'][0] && str.indexOf('-') < 0) {
//E.g. -0.5 if rounded to -0 will cause toString to omit the minus sign.
str = '-' + str
}
}
TO_EXP_NEG = neg, TO_EXP_POS = pos;
TO_EXP_NEG = neg;
TO_EXP_POS = pos;
if ( !str ) {
throwErr( '!toFix!' )
if (!str) {
throwErr('!toFix!')
}

@@ -1036,34 +1147,36 @@

/*
* Return a string representing the value of this Big to 'sd' significant
* digits and rounded, if necessary, using 'Big.RM'. If 'sd' is less than
* the number of digits necessary to represent the integer part of the value
* in normal notation, then use exponential notation.
* Return a string representing the value of this Big rounded to sd
* significant digits using Big.RM. Use exponential notation if sd is less
* than the number of digits necessary to represent the integer part of the
* value in normal notation.
*
* sd {number} Integer, 1 to MAX_DP inclusive.
*/
P['toPrecision'] = function ( sd ) {
P['toPrecision'] = function (sd) {
if ( sd == null ) {
if (sd == null) {
return this.toString()
} else if ( sd !== ~~sd || sd < 1 || sd > MAX_DP ) {
throwErr( '!toPre!' )
} else if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
throwErr('!toPre!')
}
return format( this, sd - 1, 2 )
return format(this, sd - 1, 2)
};
// EXPORT
// Export
// Node and other CommonJS-like environments that support module.exports.
if ( typeof module !== 'undefined' && module.exports ) {
module.exports = Big
Big = bigFactory();
//AMD.
} else if ( typeof define == 'function' && define.amd ) {
define( function () {
if (typeof define === 'function' && define.amd) {
define(function () {
return Big
})
// Node and other CommonJS-like environments that support module.exports.
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = Big
//Browser.

@@ -1073,3 +1186,2 @@ } else {

}
})( this );
})(this);

@@ -1,1 +0,1 @@

/*big.js v2.5.1 https://github.com/MikeMcl/big.js/LICENCE*/(function(n){"use strict";function t(n){var f,i,e,u=this;if(!(u instanceof t))return new t(n);if(n instanceof t){u.s=n.s;u.e=n.e;u.c=n.c.slice();return}for(n===0&&1/n<0?n="-0":l.test(n+="")||r(NaN),u.s=n.charAt(0)=="-"?(n=n.slice(1),-1):1,(f=n.indexOf("."))>-1&&(n=n.replace(".","")),(i=n.search(/e/i))>0?(f<0&&(f=i),f+=+n.slice(i+1),n=n.substring(0,i)):f<0&&(f=n.length),i=0;n.charAt(i)=="0";i++);if(i==(e=n.length))u.c=[u.e=0];else{for(;n.charAt(--e)=="0";);for(u.e=f-i-1,u.c=[],f=0;i<=e;u.c[f++]=+n.charAt(i++));}}function o(n,t,i,u){var e=n.c,f=n.e+t+1;if(i===1?u=e[f]>=5:i===2?u=e[f]>5||e[f]==5&&(u||f<0||e[f+1]!=null||e[f-1]&1):i===3?u=u||e[f]!=null||f<0:(u=!1,i!==0)&&r("!Big.RM!"),f<1||!e[0])n.c=u?(n.e=-t,[1]):[n.e=0];else{if(e.length=f--,u)for(;++e[f]>9;)e[f]=0,f--||(++n.e,e.unshift(1));for(f=e.length;!e[--f];e.pop());}return n}function r(n){var t=new Error(n);t.name="BigError";throw t;}function h(n,i,r){var u=i-(n=new t(n)).e,e=n.c;for(e.length>++i&&o(n,u,t.RM),u=e[0]?r?i:(e=n.c,n.e+u+1):u+1;e.length<u;e.push(0));return u=n.e,r==1||r==2&&(i<=u||u<=f)?(n.s<0&&e[0]?"-":"")+(e.length>1?(e.splice(1,0,"."),e.join("")):e[0])+(u<0?"e":"e+")+u:n.toString()}t.DP=20;t.RM=1;var u=1e6,c=1e6,f=-7,e=21,i=t.prototype,l=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,s=new t(1);i.abs=function(){var n=new t(this);return n.s=1,n};i.cmp=function(n){var o,h=this,f=h.c,e=(n=new t(n)).c,i=h.s,s=n.s,r=h.e,u=n.e;if(!f[0]||!e[0])return f[0]?i:e[0]?-s:0;if(i!=s)return i;if(o=i<0,r!=u)return r>u^o?1:-1;for(i=-1,s=(r=f.length)<(u=e.length)?r:u;++i<s;)if(f[i]!=e[i])return f[i]>e[i]^o?1:-1;return r==u?0:r>u^o?1:-1};i.div=function(n){var b=this,l=b.c,h=(n=new t(n)).c,p=b.s==n.s?1:-1,a=t.DP;if((a!==~~a||a<0||a>u)&&r("!Big.DP!"),!l[0]||!h[0])return l[0]==h[0]&&r(NaN),h[0]||r(p/0),new t(p*0);var c,k,w,v,e,it=h.slice(),d=c=h.length,rt=l.length,i=l.slice(0,c),f=i.length,y=new t(s),g=y.c=[],nt=0,tt=a+(y.e=b.e-n.e)+1;for(y.s=p,p=tt<0?0:tt,it.unshift(0);f++<c;i.push(0));do{for(w=0;w<10;w++){if(c!=(f=i.length))v=c>f?1:-1;else for(e=-1,v=0;++e<c;)if(h[e]!=i[e]){v=h[e]>i[e]?1:-1;break}if(v<0){for(k=f==c?h:it;f;){if(i[--f]<k[f]){for(e=f;e&&!i[--e];i[e]=9);--i[e];i[f]+=10}i[f]-=k[f]}for(;!i[0];i.shift());}else break}g[nt++]=v?w:++w;i[0]&&v?i[f]=l[d]||0:i=[l[d]]}while((d++<rt||i[0]!=null)&&p--);return g[0]||nt==1||(g.shift(),y.e--),nt>tt&&o(y,a,t.RM,i[0]!=null),y};i.eq=function(n){return!this.cmp(n)};i.gt=function(n){return this.cmp(n)>0};i.gte=function(n){return this.cmp(n)>-1};i.lt=function(n){return this.cmp(n)<0};i.lte=function(n){return this.cmp(n)<1};i.minus=function(n){var e,o,s,l,h=this,f=h.s,r=(n=new t(n)).s;if(f!=r)return n.s=-r,h.plus(n);var i=h.c.slice(),a=h.e,u=n.c,c=n.e;if(!i[0]||!u[0])return u[0]?(n.s=-r,n):new t(i[0]?h:0);if(f=a-c){for(e=(l=f<0)?(f=-f,i):(c=a,u),e.reverse(),r=f;r--;e.push(0));e.reverse()}else for(s=((l=i.length<u.length)?i:u).length,f=r=0;r<s;r++)if(i[r]!=u[r]){l=i[r]<u[r];break}if(l&&(e=i,i=u,u=e,n.s=-n.s),(r=-((s=i.length)-u.length))>0)for(;r--;i[s++]=0);for(r=u.length;r>f;){if(i[--r]<u[r]){for(o=r;o&&!i[--o];i[o]=9);--i[o];i[r]+=10}i[r]-=u[r]}for(;i[--s]==0;i.pop());for(;i[0]==0;i.shift(),--c);return i[0]||(n.s=1,i=[c=0]),n.c=i,n.e=c,n};i.mod=function(n){n=new t(n);var e,i=this,u=i.s,f=n.s;return n.c[0]||r(NaN),i.s=n.s=1,e=n.cmp(i)==1,i.s=u,n.s=f,e?new t(i):(u=t.DP,f=t.RM,t.DP=t.RM=0,i=i.div(n),t.DP=u,t.RM=f,this.minus(i.times(n)))};i.plus=function(n){var e,o=this,r=o.s,f=(n=new t(n)).s;if(r!=f)return n.s=-f,o.minus(n);var h=o.e,i=o.c,s=n.e,u=n.c;if(!i[0]||!u[0])return u[0]?n:new t(i[0]?o:r*0);if(i=i.slice(),r=h-s){for(e=r>0?(s=h,u):(r=-r,i),e.reverse();r--;e.push(0));e.reverse()}for(i.length-u.length<0&&(e=u,u=i,i=e),r=u.length,f=0;r;f=(i[--r]=i[r]+u[r]+f)/10^0,i[r]%=10);for(f&&(i.unshift(f),++s),r=i.length;i[--r]==0;i.pop());return n.c=i,n.e=s,n};i.pow=function(n){var f=n<0,i=new t(this),u=s;for((n!==~~n||n<-c||n>c)&&r("!pow!"),n=f?-n:n;;){if(n&1&&(u=u.times(i)),n>>=1,!n)break;i=i.times(i)}return f?s.div(u):u};i.round=function(n,i){var f=new t(this);return n==null?n=0:(n!==~~n||n<0||n>u)&&r("!round!"),o(f,n,i==null?t.RM:i),f};i.sqrt=function(){var f,n,e,u=this,h=u.c,i=u.s,s=u.e,c=new t("0.5");if(!h[0])return new t(u);i<0&&r(NaN);i=Math.sqrt(u.toString());i==0||i==1/0?(f=h.join(""),f.length+s&1||(f+="0"),n=new t(Math.sqrt(f).toString()),n.e=((s+1)/2|0)-(s<0||s&1)):n=new t(i.toString());i=n.e+(t.DP+=4);do e=n,n=c.times(e.plus(u.div(e)));while(e.c.slice(0,i).join("")!==n.c.slice(0,i).join(""));return o(n,t.DP-=4,t.RM),n};i.times=function(n){var i,h=this,e=h.c,o=(n=new t(n)).c,s=e.length,r=o.length,f=h.e,u=n.e;if(n.s=h.s==n.s?1:-1,!e[0]||!o[0])return new t(n.s*0);for(n.e=f+u,s<r&&(i=e,e=o,o=i,u=s,s=r,r=u),u=s+r,i=[];u--;i.push(0));for(f=r-1;f>-1;f--){for(r=0,u=s+f;u>f;r=i[u]+o[f]*e[u-f-1]+r,i[u--]=r%10|0,r=r/10|0);r&&(i[u]=(i[u]+r)%10)}for(r&&++n.e,i[0]||i.shift(),u=i.length;!i[--u];i.pop());return n.c=i,n};i.toString=i.valueOf=i.toJSON=function(){var r=this,t=r.e,n=r.c.join(""),i=n.length;if(t<=f||t>=e)n=n.charAt(0)+(i>1?"."+n.slice(1):"")+(t<0?"e":"e+")+t;else if(t<0){for(;++t;n="0"+n);n="0."+n}else if(t>0)if(++t>i)for(t-=i;t--;n+="0");else t<i&&(n=n.slice(0,t)+"."+n.slice(t));else i>1&&(n=n.charAt(0)+"."+n.slice(1));return r.s<0&&r.c[0]?"-"+n:n};i.toExponential=function(n){return n==null?n=this.c.length-1:(n!==~~n||n<0||n>u)&&r("!toExp!"),h(this,n,1)};i.toFixed=function(n){var t,i=this,o=f,s=e;return f=-(e=1/0),n==null?t=i.toString():n===~~n&&n>=0&&n<=u&&(t=h(i,i.e+n),i.s<0&&i.c[0]&&t.indexOf("-")<0&&(t="-"+t)),f=o,e=s,t||r("!toFix!"),t};i.toPrecision=function(n){return n==null?this.toString():((n!==~~n||n<1||n>u)&&r("!toPre!"),h(this,n-1,2))};typeof module!="undefined"&&module.exports?module.exports=t:typeof define=="function"&&define.amd?define(function(){return t}):n.Big=t})(this)
/*big.js v3.0.0 https://github.com/MikeMcl/big.js/LICENCE*/(function(n){"use strict";function c(){function n(t){var i=this;if(!(i instanceof n))return t===void 0?c():new n(t);t instanceof n?(i.s=t.s,i.e=t.e,i.c=t.c.slice()):y(i,t);i.constructor=n}return n.prototype=t,n.DP=l,n.RM=a,n}function s(n,t,i){var e=n.constructor,r=t-(n=new e(n)).e,f=n.c;for(f.length>++t&&o(n,r,e.RM),f[0]?i?r=t:(f=n.c,r=n.e+r+1):++r;f.length<r;f.push(0));return r=n.e,i===1||i&&(t<=r||r<=u)?(n.s<0&&f[0]?"-":"")+(f.length>1?f[0]+"."+f.join("").slice(1):f[0])+(r<0?"e":"e+")+r:n.toString()}function y(n,t){var u,r,f;for(t===0&&1/t<0?t="-0":v.test(t+="")||i(NaN),n.s=t.charAt(0)=="-"?(t=t.slice(1),-1):1,(u=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(u<0&&(u=r),u+=+t.slice(r+1),t=t.substring(0,r)):u<0&&(u=t.length),r=0;t.charAt(r)=="0";r++);if(r==(f=t.length))n.c=[n.e=0];else{for(;t.charAt(--f)=="0";);for(n.e=u-r-1,n.c=[],u=0;r<=f;n.c[u++]=+t.charAt(r++));}return n}function o(n,t,r,u){var o,e=n.c,f=n.e+t+1;if(r===1?u=e[f]>=5:r===2?u=e[f]>5||e[f]==5&&(u||f<0||e[f+1]!==o||e[f-1]&1):r===3?u=u||e[f]!==o||f<0:(u=!1,r!==0&&i("!Big.RM!")),f<1||!e[0])u?(n.e=-t,n.c=[1]):n.c=[n.e=0];else{if(e.length=f--,u)for(;++e[f]>9;)e[f]=0,f--||(++n.e,e.unshift(1));for(f=e.length;!e[--f];e.pop());}return n}function i(n){var t=new Error(n);t.name="BigError";throw t;}var l=20,a=1,r=1e6,h=1e6,u=-7,f=21,t={},v=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,e;t.abs=function(){var n=new this.constructor(this);return n.s=1,n};t.cmp=function(n){var e,o=this,u=o.c,f=(n=new o.constructor(n)).c,t=o.s,s=n.s,i=o.e,r=n.e;if(!u[0]||!f[0])return u[0]?t:f[0]?-s:0;if(t!=s)return t;if(e=t<0,i!=r)return i>r^e?1:-1;for(t=-1,s=(i=u.length)<(r=f.length)?i:r;++t<s;)if(u[t]!=f[t])return u[t]>f[t]^e?1:-1;return i==r?0:i>r^e?1:-1};t.div=function(n){var p=this,w=p.constructor,h=p.c,e=(n=new w(n)).c,v=p.s==n.s?1:-1,c=w.DP;if((c!==~~c||c<0||c>r)&&i("!Big.DP!"),!h[0]||!e[0])return h[0]==e[0]&&i(NaN),e[0]||i(v/0),new w(v*0);var s,b,y,l,f,tt,it=e.slice(),k=s=e.length,rt=h.length,t=h.slice(0,s),u=t.length,a=n,d=a.c=[],g=0,nt=c+(a.e=p.e-n.e)+1;for(a.s=v,v=nt<0?0:nt,it.unshift(0);u++<s;t.push(0));do{for(y=0;y<10;y++){if(s!=(u=t.length))l=s>u?1:-1;else for(f=-1,l=0;++f<s;)if(e[f]!=t[f]){l=e[f]>t[f]?1:-1;break}if(l<0){for(b=u==s?e:it;u;){if(t[--u]<b[u]){for(f=u;f&&!t[--f];t[f]=9);--t[f];t[u]+=10}t[u]-=b[u]}for(;!t[0];t.shift());}else break}d[g++]=l?y:++y;t[0]&&l?t[u]=h[k]||0:t=[h[k]]}while((k++<rt||t[0]!==tt)&&v--);return d[0]||g==1||(d.shift(),a.e--),g>nt&&o(a,c,w.RM,t[0]!==tt),a};t.eq=function(n){return!this.cmp(n)};t.gt=function(n){return this.cmp(n)>0};t.gte=function(n){return this.cmp(n)>-1};t.lt=function(n){return this.cmp(n)<0};t.lte=function(n){return this.cmp(n)<1};t.minus=function(n){var f,u,o,c,s=this,l=s.constructor,e=s.s,i=(n=new l(n)).s;if(e!=i)return n.s=-i,s.plus(n);var t=s.c.slice(),a=s.e,r=n.c,h=n.e;if(!t[0]||!r[0])return r[0]?(n.s=-i,n):new l(t[0]?s:0);if(e=a-h){for((c=e<0)?(e=-e,o=t):(h=a,o=r),o.reverse(),i=e;i--;o.push(0));o.reverse()}else for(u=((c=t.length<r.length)?t:r).length,e=i=0;i<u;i++)if(t[i]!=r[i]){c=t[i]<r[i];break}if(c&&(o=t,t=r,r=o,n.s=-n.s),(i=(u=r.length)-(f=t.length))>0)for(;i--;t[f++]=0);for(i=f;u>e;){if(t[--u]<r[u]){for(f=u;f&&!t[--f];t[f]=9);--t[f];t[u]+=10}t[u]-=r[u]}for(;t[--i]==0;t.pop());for(;t[0]==0;)t.shift(),--h;return t[0]||(n.s=1,t=[h=0]),n.c=t,n.e=h,n};t.mod=function(n){var e,t=this,r=t.constructor,u=t.s,f=(n=new r(n)).s;return(n.c[0]||i(NaN),t.s=n.s=1,e=n.cmp(t)==1,t.s=u,n.s=f,e)?new r(t):(u=r.DP,f=r.RM,r.DP=r.RM=0,t=t.div(n),r.DP=u,r.RM=f,this.minus(t.times(n)))};t.plus=function(n){var u,e=this,s=e.constructor,i=e.s,f=(n=new s(n)).s;if(i!=f)return n.s=-f,e.minus(n);var h=e.e,t=e.c,o=n.e,r=n.c;if(!t[0]||!r[0])return r[0]?n:new s(t[0]?e:i*0);if(t=t.slice(),i=h-o){for(i>0?(o=h,u=r):(i=-i,u=t),u.reverse();i--;u.push(0));u.reverse()}for(t.length-r.length<0&&(u=r,r=t,t=u),i=r.length,f=0;i;)f=(t[--i]=t[i]+r[i]+f)/10|0,t[i]%=10;for(f&&(t.unshift(f),++o),i=t.length;t[--i]==0;t.pop());return n.c=t,n.e=o,n};t.pow=function(n){var t=this,u=new t.constructor(1),r=u,f=n<0;for((n!==~~n||n<-h||n>h)&&i("!pow!"),n=f?-n:n;;){if(n&1&&(r=r.times(t)),n>>=1,!n)break;t=t.times(t)}return f?u.div(r):r};t.round=function(n,t){var u=this,f=u.constructor;return n==null?n=0:(n!==~~n||n<0||n>r)&&i("!round!"),o(u=new f(u),n,t==null?f.RM:t),u};t.sqrt=function(){var f,n,e,r=this,u=r.constructor,h=r.c,t=r.s,s=r.e,c=new u("0.5");if(!h[0])return new u(r);t<0&&i(NaN);t=Math.sqrt(r.toString());t==0||t==1/0?(f=h.join(""),f.length+s&1||(f+="0"),n=new u(Math.sqrt(f).toString()),n.e=((s+1)/2|0)-(s<0||s&1)):n=new u(t.toString());t=n.e+(u.DP+=4);do e=n,n=c.times(e.plus(r.div(e)));while(e.c.slice(0,t).join("")!==n.c.slice(0,t).join(""));return o(n,u.DP-=4,u.RM),n};t.times=function(n){var t,s=this,h=s.constructor,f=s.c,e=(n=new h(n)).c,o=f.length,i=e.length,u=s.e,r=n.e;if(n.s=s.s==n.s?1:-1,!f[0]||!e[0])return new h(n.s*0);for(n.e=u+r,o<i&&(t=f,f=e,e=t,r=o,o=i,i=r),t=new Array(r=o+i);r--;t[r]=0);for(u=i;u--;){for(i=0,r=o+u;r>u;)i=t[r]+e[u]*f[r-u-1]+i,t[r--]=i%10,i=i/10|0;t[r]=(t[r]+i)%10}for(i&&++n.e,t[0]||t.shift(),u=t.length;!t[--u];t.pop());return n.c=t,n};t.toString=t.valueOf=t.toJSON=function(){var r=this,t=r.e,n=r.c.join(""),i=n.length;if(t<=u||t>=f)n=n.charAt(0)+(i>1?"."+n.slice(1):"")+(t<0?"e":"e+")+t;else if(t<0){for(;++t;n="0"+n);n="0."+n}else if(t>0)if(++t>i)for(t-=i;t--;n+="0");else t<i&&(n=n.slice(0,t)+"."+n.slice(t));else i>1&&(n=n.charAt(0)+"."+n.slice(1));return r.s<0&&r.c[0]?"-"+n:n};t.toExponential=function(n){return n==null?n=this.c.length-1:(n!==~~n||n<0||n>r)&&i("!toExp!"),s(this,n,1)};t.toFixed=function(n){var t,e=this,o=u,h=f;return u=-(f=1/0),n==null?t=e.toString():n===~~n&&n>=0&&n<=r&&(t=s(e,e.e+n),e.s<0&&e.c[0]&&t.indexOf("-")<0&&(t="-"+t)),u=o,f=h,t||i("!toFix!"),t};t.toPrecision=function(n){return n==null?this.toString():((n!==~~n||n<1||n>r)&&i("!toPre!"),s(this,n-1,2))};e=c();typeof define=="function"&&define.amd?define(function(){return e}):typeof module!="undefined"&&module.exports?module.exports=e:n.Big=e})(this)
{
"name": "big.js",
"description": "A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic",
"version": "2.5.1",
"version": "3.0.0",
"keywords": [

@@ -6,0 +6,0 @@ "arbitrary",

@@ -12,3 +12,3 @@

- Faster, smaller and easier-to-use than JavaScript versions of Java's BigDecimal
- Only 2.6 KB minified and gzipped
- Only 2.7 KB minified and gzipped
- Simple API

@@ -76,5 +76,8 @@ - Replicates the `toExponential`, `toFixed` and `toPrecision` methods of JavaScript's Number type

The maximum number of decimal places and the rounding mode used to round the results of the `div`, `sqrt` and `pow`
(with negative exponent) methods is determined by the value of the `DP` and `RM` properties of the `Big` number constructor.
The other methods always give the exact result.
(with negative exponent) methods is determined by the value of the `DP` and `RM` properties of the `Big` number constructor.
The other methods always give the exact result.
(From *v3.0.0*, multiple Big number constructors can be created, see Change Log below.)
Big.DP = 10

@@ -90,2 +93,3 @@ Big.RM = 1

z.times(z).round(10) // "0.4444444445"

@@ -156,4 +160,14 @@ The value of a Big number is stored in a decimal floating point format in terms of a coefficient, exponent and sign.

The *big.min.js* already present was created with *Microsoft Ajax Minifier 4.95*, as it produced a smaller file size.
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.
The definitions file can be added to your project via the [big.js.TypeScript.DefinitelyTyped](https://www.nuget.org/packages/big.js.TypeScript.DefinitelyTyped/0.0.1) NuGet package or via [tsd](http://definitelytyped.org/tsd/).
tsd query big.js --action install
Any questions about the TypeScript definitions file should be addressed to the DefinitelyTyped project.
## Feedback

@@ -179,2 +193,12 @@

####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 appropiate.
####2.5.2
* 1/11/14 Added bower.json.
####2.5.1

@@ -181,0 +205,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc