|
|
|
@ -25,14 +25,14 @@ var EXP_LIMIT = 9e15, // 0 to 9e15
|
|
|
|
|
NUMERALS = '0123456789abcdef',
|
|
|
|
|
|
|
|
|
|
// The natural logarithm of 10 (1025 digits).
|
|
|
|
|
ln10 = '2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058',
|
|
|
|
|
LN10 = '2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058',
|
|
|
|
|
|
|
|
|
|
// Pi (1025 digits).
|
|
|
|
|
pi = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789',
|
|
|
|
|
PI = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The initial configuration properties of the Decimal constructor.
|
|
|
|
|
defaults = {
|
|
|
|
|
DEFAULTS = {
|
|
|
|
|
|
|
|
|
|
// These values must be integers within the stated ranges (inclusive).
|
|
|
|
|
// Most of these values can be changed at run-time using the `Decimal.config` method.
|
|
|
|
@ -97,7 +97,7 @@ var EXP_LIMIT = 9e15, // 0 to 9e15
|
|
|
|
|
// ----------------------------------- END OF EDITABLE DEFAULTS ------------------------------- //
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Decimal, LN10, PI, inexact, quadrant,
|
|
|
|
|
Decimal, inexact, quadrant,
|
|
|
|
|
external = true,
|
|
|
|
|
|
|
|
|
|
decimalError = '[DecimalError] ',
|
|
|
|
@ -117,11 +117,11 @@ var EXP_LIMIT = 9e15, // 0 to 9e15
|
|
|
|
|
LOG_BASE = 7,
|
|
|
|
|
MAX_SAFE_INTEGER = 9007199254740991,
|
|
|
|
|
|
|
|
|
|
LN10_PRECISION = ln10.length - 1,
|
|
|
|
|
PI_PRECISION = pi.length - 1,
|
|
|
|
|
LN10_PRECISION = LN10.length - 1,
|
|
|
|
|
PI_PRECISION = PI.length - 1,
|
|
|
|
|
|
|
|
|
|
// Decimal.prototype object
|
|
|
|
|
P = {};
|
|
|
|
|
P = { name: '[object Decimal]' };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Decimal prototype methods
|
|
|
|
@ -4158,6 +4158,7 @@ function ceil(x) {
|
|
|
|
|
* minE {number}
|
|
|
|
|
* modulo {number}
|
|
|
|
|
* crypto {boolean|number}
|
|
|
|
|
* defaults {true}
|
|
|
|
|
*
|
|
|
|
|
* E.g. Decimal.config({ precision: 20, rounding: 4 })
|
|
|
|
|
*
|
|
|
|
@ -4165,6 +4166,7 @@ function ceil(x) {
|
|
|
|
|
function config(obj) {
|
|
|
|
|
if (!obj || typeof obj !== 'object') throw Error(decimalError + 'Object expected');
|
|
|
|
|
var i, p, v,
|
|
|
|
|
useDefaults = obj.defaults === true,
|
|
|
|
|
ps = [
|
|
|
|
|
'precision', 1, MAX_DIGITS,
|
|
|
|
|
'rounding', 0, 8,
|
|
|
|
@ -4176,13 +4178,15 @@ function config(obj) {
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ps.length; i += 3) {
|
|
|
|
|
if ((v = obj[p = ps[i]]) !== void 0) {
|
|
|
|
|
if (p = ps[i], useDefaults) this[p] = DEFAULTS[p];
|
|
|
|
|
if ((v = obj[p]) !== void 0) {
|
|
|
|
|
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2]) this[p] = v;
|
|
|
|
|
else throw Error(invalidArgument + p + ': ' + v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((v = obj[p = 'crypto']) !== void 0) {
|
|
|
|
|
if (p = 'crypto', useDefaults) this[p] = DEFAULTS[p];
|
|
|
|
|
if ((v = obj[p]) !== void 0) {
|
|
|
|
|
if (v === true || v === false || v === 0 || v === 1) {
|
|
|
|
|
if (v) {
|
|
|
|
|
if (typeof crypto != 'undefined' && crypto &&
|
|
|
|
@ -4325,6 +4329,7 @@ function clone(obj) {
|
|
|
|
|
|
|
|
|
|
Decimal.config = Decimal.set = config;
|
|
|
|
|
Decimal.clone = clone;
|
|
|
|
|
Decimal.isDecimal = isDecimalInstance;
|
|
|
|
|
|
|
|
|
|
Decimal.abs = abs;
|
|
|
|
|
Decimal.acos = acos;
|
|
|
|
@ -4365,8 +4370,10 @@ function clone(obj) {
|
|
|
|
|
|
|
|
|
|
if (obj === void 0) obj = {};
|
|
|
|
|
if (obj) {
|
|
|
|
|
ps = ['precision', 'rounding', 'toExpNeg', 'toExpPos', 'maxE', 'minE', 'modulo', 'crypto'];
|
|
|
|
|
for (i = 0; i < ps.length;) if (!obj.hasOwnProperty(p = ps[i++])) obj[p] = this[p];
|
|
|
|
|
if (obj.defaults !== true) {
|
|
|
|
|
ps = ['precision', 'rounding', 'toExpNeg', 'toExpPos', 'maxE', 'minE', 'modulo', 'crypto'];
|
|
|
|
|
for (i = 0; i < ps.length;) if (!obj.hasOwnProperty(p = ps[i++])) obj[p] = this[p];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Decimal.config(obj);
|
|
|
|
@ -4443,6 +4450,16 @@ function hypot() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return true if object is a Decimal instance (where Decimal is any Decimal constructor),
|
|
|
|
|
* otherwise return false.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function isDecimalInstance(obj) {
|
|
|
|
|
return obj instanceof Decimal || obj && obj.name === '[object Decimal]' || false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return a new Decimal whose value is the natural logarithm of `x`, rounded to `precision`
|
|
|
|
|
* significant digits using rounding mode `rounding`.
|
|
|
|
@ -4773,12 +4790,12 @@ function trunc(x) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create and configure initial Decimal constructor.
|
|
|
|
|
Decimal = clone(defaults);
|
|
|
|
|
Decimal = clone(DEFAULTS);
|
|
|
|
|
|
|
|
|
|
Decimal['default'] = Decimal.Decimal = Decimal;
|
|
|
|
|
|
|
|
|
|
// Create the internal constants from their string values.
|
|
|
|
|
LN10 = new Decimal(ln10);
|
|
|
|
|
PI = new Decimal(pi);
|
|
|
|
|
LN10 = new Decimal(LN10);
|
|
|
|
|
PI = new Decimal(PI);
|
|
|
|
|
|
|
|
|
|
export default Decimal;
|
|
|
|
|