From 0b79acd7aa7b4ce7cd2c76f7ea2879c19ca8d3f9 Mon Sep 17 00:00:00 2001 From: Michael Mclaughlin Date: Wed, 27 Sep 2017 22:14:56 +0100 Subject: [PATCH] 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. --- LICENCE | 2 +- README.md | 12 +- big.js | 2061 ++++++++++++++++------------------ big.min.js | 2 +- doc/big.js.map | 2 +- doc/bigAPI.html | 137 ++- test/abs.js | 11 +- test/browser/every-test.html | 2 +- test/cmp.js | 11 +- test/div.js | 11 +- test/every-test.js | 2 +- test/minus.js | 11 +- test/mod.js | 11 +- test/plus.js | 11 +- test/pow.js | 11 +- test/round.js | 66 +- test/sqrt.js | 11 +- test/times.js | 11 +- test/toExponential.js | 14 +- test/toFixed.js | 73 +- test/toPrecision.js | 13 +- test/toString.js | 21 +- 22 files changed, 1158 insertions(+), 1348 deletions(-) diff --git a/LICENCE b/LICENCE index a5d1b40..1d28066 100644 --- a/LICENCE +++ b/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 diff --git a/README.md b/README.md index ed381bb..b034a4c 100644 --- a/README.md +++ b/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 M8ch88l@gmail.com -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 diff --git a/big.js b/big.js index ff81111..f13eba5 100644 --- a/big.js +++ b/big.js @@ -1,1146 +1,973 @@ -/* big.js v3.1.3 https://github.com/MikeMcl/big.js/LICENCE */ +/* big.js v3.2.0 https://github.com/MikeMcl/big.js/LICENCE */ ;(function (global) { - 'use strict'; + 'use strict'; + /* - big.js v3.1.3 - A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic. - https://github.com/MikeMcl/big.js/ - Copyright (c) 2014 Michael Mclaughlin - MIT Expat Licence -*/ + * big.js v3.2.0 + * A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic. + * https://github.com/MikeMcl/big.js/ + * Copyright (c) 2014 Michael Mclaughlin + * MIT Expat Licence + */ -/***************************** EDITABLE DEFAULTS ******************************/ - // The default values below must be integers within the stated ranges. +/************************************** EDITABLE DEFAULTS *****************************************/ + + // The default values below must be integers within the stated ranges. + + /* + * The maximum number of decimal places (DP) of the results of operations involving division: div + * and sqrt, and pow with negative exponents. + */ + var DP = 20, // 0 to MAX_DP /* - * The maximum number of decimal places of the results of operations - * involving division: div and sqrt, and pow with negative exponents. - */ - var DP = 20, // 0 to MAX_DP - - /* - * 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 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 1000000 - - /* - * 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. - */ - E_NEG = -7, // 0 to -1000000 - - /* - * 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.) - */ - E_POS = 21, // 0 to 1000000 - -/******************************************************************************/ - - // The shared prototype object. - P = {}, - isValid = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i, - Big; - - - /* - * Create and return a Big constructor. + * The rounding mode (RM) 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) */ - function bigFactory() { + RM = 1, // 0, 1, 2 or 3 - /* - * 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; + // The maximum value of DP and Big.DP. + MAX_DP = 1E6, // 0 to 1000000 - // Enable constructor usage without new. - if (!(x instanceof Big)) { - return n === void 0 ? bigFactory() : new Big(n); - } + // The maximum magnitude of the exponent argument to the pow method. + MAX_POWER = 1E6, // 1 to 1000000 - // Duplicate. - if (n instanceof Big) { - x.s = n.s; - x.e = n.e; - x.c = n.c.slice(); - } else { - parse(x, n); - } + /* + * The negative exponent (NE) at and beneath which toString returns exponential notation. + * (JavaScript numbers: -7) + * -1000000 is the minimum recommended exponent value of a Big. + */ + NE = -7, // 0 to -1000000 - /* - * Retain a reference to this Big constructor, and shadow - * Big.prototype.constructor which points to Object. - */ - x.constructor = Big; - } + /* + * The positive exponent (PE) at and above which toString returns exponential notation. + * (JavaScript numbers: 21) + * 1000000 is the maximum recommended exponent value of a Big. + * (This limit is not enforced or checked.) + */ + PE = 21, // 0 to 1000000 - Big.prototype = P; - Big.DP = DP; - Big.RM = RM; - Big.E_NEG = E_NEG; - Big.E_POS = E_POS; +/**************************************************************************************************/ - return Big; + + // The shared prototype object. + P = {}, + isValid = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i, + bigError = '[BigError] ', + undef = void 0, + Big; + + + /* + * 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 === undef ? 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; + Big.NE = NE; + Big.PE = PE; - // Private functions + return Big; + } - /* - * Return a string representing the value of Big x in normal or exponential - * notation to dp fixed decimal places or significant digits. - * - * x {Big} The Big to format. - * dp {number} Integer, 0 to MAX_DP inclusive. - * toE {number} 1 (toExponential), 2 (toPrecision) or undefined (toFixed). - */ - function format(x, dp, toE) { - var Big = x.constructor, + // Private functions - // 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); - } + /* + * Return a string representing the value of Big x in normal or exponential notation to dp fixed + * decimal places or significant digits. + * + * x {Big} The Big to format. + * dp {number} Integer, 0 to MAX_DP inclusive. + * toE {number} 1 (toExponential), 2 (toPrecision) or undefined (toFixed). + */ + function format(x, dp, toE) { + var Big = x.constructor, - if (!c[0]) { - ++i; - } else if (toE) { - i = dp; + // The index (normal notation) of the digit that may be rounded up. + i = dp - (x = new Big(x)).e, + c = x.c; - // toFixed - } else { - c = x.c; + // Round? + if (c.length > ++dp) rnd(x, i, Big.RM); - // Recalculate i as x.e may have changed if value rounded up. - i = x.e + i + 1; - } + if (!c[0]) { + ++i; + } else if (toE) { + i = dp; - // 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 <= Big.E_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) { - n = '-0'; - - // 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; - - // Decimal point? - if ((e = n.indexOf('.')) > -1) { - n = n.replace('.', ''); - } - - // Exponential form? - if ((i = n.search(/e/i)) > 0) { - - // Determine exponent. - if (e < 0) { - e = i; - } - e += +n.slice(i + 1); - n = n.substring(0, i); - - } else if (e < 0) { - - // Integer. - e = n.length; - } - - nL = n.length; - - // Determine leading zeros. - for (i = 0; i < nL && n.charAt(i) == '0'; i++) { - } - - if (i == nL) { - - // Zero. - x.c = [ x.e = 0 ]; - } else { - - // Determine trailing zeros. - for (; nL > 0 && n.charAt(--nL) == '0';) { - } - - x.e = e - i - 1; - x.c = []; - - // Convert string to array of digits without leading/trailing zeros. - //for (e = 0; i <= nL; x.c[e++] = +n.charAt(i++)) { - for (; i <= nL; x.c.push(+n.charAt(i++))) { - } - } - - return x; - } - - - /* - * 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 (DOWN, HALF_UP, HALF_EVEN, UP) - * [more] {boolean} Whether the result of division was truncated. - */ - 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. - more = xc[i] >= 5; - } 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]) { - - 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 { - - // Remove any digits after the required decimal places. - xc.length = i--; - - // Round up? - if (more) { - - // Rounding up may mean the previous digit has to be rounded up. - for (; ++xc[i] > 9;) { - xc[i] = 0; - - if (!i--) { - ++x.e; - xc.unshift(1); - } - } - } - - // Remove trailing zeros. - for (i = xc.length; !xc[--i]; xc.pop()) { - } - } - - return x; - } - - - /* - * Throw a BigError. - * - * message {string} The error message. - */ - function throwErr(message) { - var err = new Error(message); - err.name = 'BigError'; - - throw err; - } - - - // Prototype/instance methods - - - /* - * Return a new Big whose value is the absolute value of this Big. - */ - P.abs = function () { - var x = new this.constructor(this); - x.s = 1; - - return x; - }; - - - /* - * 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 - * 0 if they have the same value. - */ - P.cmp = function (y) { - var xNeg, - x = this, - xc = x.c, - yc = (y = new x.constructor(y)).c, - i = x.s, - j = y.s, - k = x.e, - l = y.e; - - // Either zero? - if (!xc[0] || !yc[0]) { - return !xc[0] ? !yc[0] ? 0 : -j : i; - } - - // Signs differ? - if (i != j) { - return i; - } - xNeg = i < 0; - - // Compare exponents. - 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 < j;) { - - if (xc[i] != yc[i]) { - return xc[i] > yc[i] ^ xNeg ? 1 : -1; - } - } - - // Compare lengths. - return k == l ? 0 : k > l ^ xNeg ? 1 : -1; - }; - - - /* - * 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. - */ - P.div = function (y) { - var x = this, - Big = x.constructor, - // dividend - dvd = x.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!'); - } - - // Either 0? - if (!dvd[0] || !dvs[0]) { - - // If both are 0, throw NaN - if (dvd[0] == dvs[0]) { - throwErr(NaN); - } - - // If dvs is 0, throw +-Infinity. - if (!dvs[0]) { - throwErr(s / 0); - } - - // dvd is 0, return +-0. - return new Big(s * 0); - } - - var dvsL, dvsT, next, cmp, remI, u, - dvsZ = dvs.slice(), - dvdI = dvsL = dvs.length, - dvdL = dvd.length, - // remainder - rem = dvd.slice(0, dvsL), - remL = rem.length, - // quotient - q = y, - qc = q.c = [], - qi = 0, - digits = dp + (q.e = x.e - y.e) + 1; - - q.s = s; - s = digits < 0 ? 0 : digits; - - // Create version of divisor with leading zero. - dvsZ.unshift(0); - - // Add zeros to make remainder as long as divisor. - for (; remL++ < dvsL; rem.push(0)) { - } - - do { - - // '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)) { - cmp = dvsL > remL ? 1 : -1; - } else { - - for (remI = -1, cmp = 0; ++remI < dvsL;) { - - if (dvs[remI] != rem[remI]) { - cmp = dvs[remI] > rem[remI] ? 1 : -1; - break; - } - } - } - - // If divisor < remainder, subtract divisor from remainder. - if (cmp < 0) { - - // 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;) { - - if (rem[--remL] < dvsT[remL]) { - remI = remL; - - for (; remI && !rem[--remI]; rem[remI] = 9) { - } - --rem[remI]; - rem[remL] += 10; - } - rem[remL] -= dvsT[remL]; - } - for (; !rem[0]; rem.shift()) { - } - } else { - break; - } - } - - // Add the 'next' digit to the result array. - qc[qi++] = cmp ? next : ++next; - - // Update the remainder. - if (rem[0] && cmp) { - rem[remL] = dvd[dvdI] || 0; - } else { - rem = [ dvd[dvdI] ]; - } - - } while ((dvdI++ < dvdL || rem[0] !== u) && s--); - - // Leading zero? Do not remove if result is simply zero (qi == 1). - if (!qc[0] && qi != 1) { - - // There can't be more than one zero. - qc.shift(); - q.e--; - } - - // Round? - if (qi > digits) { - rnd(q, dp, Big.RM, rem[0] !== u); - } - - return q; - }; - - - /* - * 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); - }; - - - /* - * 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; - }; - - - /* - * Return true if the value of this Big is greater than or equal to the - * value of Big y, otherwise returns false. - */ - P.gte = function (y) { - return this.cmp(y) > -1; - }; - - - /* - * 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; - }; - - - /* - * Return true if the value of this Big is less than or equal to the value - * of Big y, otherwise returns false. - */ - P.lte = function (y) { - return this.cmp(y) < 1; - }; - - - /* - * Return a new Big whose value is the value of this Big minus the value - * of Big y. - */ - P.sub = P.minus = function (y) { - var i, j, t, xLTy, - x = this, - Big = x.constructor, - a = x.s, - b = (y = new Big(y)).s; - - // Signs differ? - if (a != b) { - y.s = -b; - return x.plus(y); - } - - var xc = x.c.slice(), - xe = x.e, - yc = y.c, - ye = y.e; - - // Either zero? - if (!xc[0] || !yc[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); - } - - // Determine which is the bigger number. - // Prepend zeros to equalise exponents. - if (a = xe - ye) { - - if (xLTy = a < 0) { - a = -a; - t = xc; - } else { - ye = xe; - t = yc; - } - - 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; - - for (a = b = 0; b < j; b++) { - - if (xc[b] != yc[b]) { - xLTy = xc[b] < yc[b]; - break; - } - } - } - - // x < y? Point xc to the array of the bigger number. - if (xLTy) { - t = xc; - xc = yc; - yc = t; - y.s = -y.s; - } - - /* - * 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 = yc.length) - (i = xc.length) ) > 0) { - - for (; b--; xc[i++] = 0) { - } - } - - // Subtract yc from xc. - for (b = i; j > a;){ - - if (xc[--j] < yc[j]) { - - for (i = j; i && !xc[--i]; xc[i] = 9) { - } - --xc[i]; - xc[j] += 10; - } - xc[j] -= yc[j]; - } - - // Remove trailing zeros. - for (; xc[--b] === 0; xc.pop()) { - } - - // Remove leading zeros and adjust exponent accordingly. - for (; xc[0] === 0;) { - xc.shift(); - --ye; - } - - if (!xc[0]) { - - // n - n = +0 - y.s = 1; - - // Result must be zero. - xc = [ye = 0]; - } - - y.c = xc; - y.e = ye; - - return y; - }; - - - /* - * Return a new Big whose value is the value of this Big modulo the - * value of Big y. - */ - P.mod = function (y) { - var yGTx, - x = this, - Big = x.constructor, - a = x.s, - b = (y = new Big(y)).s; - - if (!y.c[0]) { - throwErr(NaN); - } - - x.s = y.s = 1; - yGTx = y.cmp(x) == 1; - x.s = a; - y.s = b; - - 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) ); - }; - - - /* - * Return a new Big whose value is the value of this Big plus the value - * of Big y. - */ - P.add = P.plus = function (y) { - var t, - x = this, - Big = x.constructor, - a = x.s, - b = (y = new Big(y)).s; - - // Signs differ? - if (a != b) { - y.s = -b; - return x.minus(y); - } - - var xe = x.e, - xc = x.c, - ye = y.e, - yc = y.c; - - // Either zero? - if (!xc[0] || !yc[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 (a = xe - ye) { - - if (a > 0) { - ye = xe; - t = yc; - } else { - a = -a; - t = xc; - } - - t.reverse(); - for (; a--; t.push(0)) { - } - t.reverse(); - } - - // 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. - */ - for (b = 0; a;) { - b = (xc[--a] = xc[a] + yc[a] + b) / 10 | 0; - xc[a] %= 10; - } - - // No need to check for zero, as +x + +y != 0 && -x + -y != 0 - - if (b) { - xc.unshift(b); - ++ye; - } - - // Remove trailing zeros. - for (a = xc.length; xc[--a] === 0; xc.pop()) { - } - - y.c = xc; - y.e = ye; - - return y; - }; - - - /* - * 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. - * - * n {number} Integer, -MAX_POWER to MAX_POWER inclusive. - */ - P.pow = function (n) { - var x = this, - one = new x.constructor(1), - y = one, - isNeg = n < 0; - - if (n !== ~~n || n < -MAX_POWER || n > MAX_POWER) { - throwErr('!pow!'); - } - - n = isNeg ? -n : n; - - for (;;) { - - if (n & 1) { - y = y.times(x); - } - n >>= 1; - - if (!n) { - break; - } - x = x.times(x); - } - - return isNeg ? one.div(y) : y; - }; - - - /* - * 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) - */ - P.round = function (dp, rm) { - var x = this, - Big = x.constructor; - - if (dp == null) { - dp = 0; - } else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) { - throwErr('!round!'); - } - rnd(x = new Big(x), dp, rm == null ? Big.RM : rm); - - 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. - */ - P.sqrt = function () { - var estimate, r, approx, - x = this, - Big = x.constructor, - xc = x.c, - i = x.s, - e = x.e, - half = new Big('0.5'); - - // Zero? - if (!xc[0]) { - return new Big(x); - } - - // If negative, throw NaN. - if (i < 0) { - throwErr(NaN); - } - - // Estimate. - i = Math.sqrt(x.toString()); - - // Math.sqrt underflow/overflow? - // 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)) { - estimate += '0'; - } - - r = new Big( Math.sqrt(estimate).toString() ); - r.e = ((e + 1) / 2 | 0) - (e < 0 || e & 1); - } else { - r = new Big(i.toString()); - } - - i = r.e + (Big.DP += 4); - - // 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('') ); - - rnd(r, Big.DP -= 4, Big.RM); - - return r; - }; - - - /* - * Return a new Big whose value is the value of this Big times the value of - * Big y. - */ - P.mul = P.times = function (y) { - var c, - x = this, - Big = x.constructor, - xc = x.c, - yc = (y = new Big(y)).c, - a = xc.length, - b = yc.length, - i = x.e, - j = y.e; - - // Determine sign of result. - y.s = x.s == y.s ? 1 : -1; - - // 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 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; - } - - // Initialise coefficient array of result with zeros. - for (c = new Array(j = a + b); j--; c[j] = 0) { - } - - // Multiply. - - // i is initially xc.length. - for (i = b; i--;) { - b = 0; - - // 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; - } - - // Increment result exponent if there is a final carry. - if (b) { - ++y.e; - } - - // Remove any leading zero. - if (!c[0]) { - c.shift(); - } - - // Remove trailing zeros. - for (i = c.length; !c[--i]; c.pop()) { - } - y.c = c; - - return y; - }; - - - /* - * Return a string representing the value of this Big. - * Return exponential notation if this Big has a positive exponent equal to - * or greater than Big.E_POS, or a negative exponent equal to or less than - * Big.E_NEG. - */ - P.toString = P.valueOf = P.toJSON = function () { - var x = this, - Big = x.constructor, - e = x.e, - str = x.c.join(''), - strL = str.length; - - // Exponential notation? - if (e <= Big.E_NEG || e >= Big.E_POS) { - str = str.charAt(0) + (strL > 1 ? '.' + str.slice(1) : '') + - (e < 0 ? 'e' : 'e+') + e; - - // Negative exponent? - } else if (e < 0) { - - // Prepend zeros. - for (; ++e; str = '0' + str) { - } - str = '0.' + str; - - // Positive exponent? - } else if (e > 0) { - - if (++e > strL) { - - // Append zeros. - for (e -= strL; e-- ; str += '0') { - } - } else if (e < strL) { - str = str.slice(0, e) + '.' + str.slice(e); - } - - // Exponent zero. - } else if (strL > 1) { - str = str.charAt(0) + '.' + str.slice(1); - } - - // Avoid '-0' - return x.s < 0 && x.c[0] ? '-' + str : str; - }; - - - /* - *************************************************************************** - * 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. - *************************************************************************** - */ - - - /* - * Return a string representing the value of this Big in exponential - * 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) { - - if (dp == null) { - dp = this.c.length - 1; - } else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) { - throwErr('!toExp!'); - } - - return format(this, dp, 1); - }; - - - /* - * Return a string representing the value of this Big in normal notation - * to dp fixed decimal places and rounded, if necessary, using Big.RM. - * - * [dp] {number} Integer, 0 to MAX_DP inclusive. - */ - P.toFixed = function (dp) { - var str, - x = this, - Big = x.constructor, - neg = Big.E_NEG, - pos = Big.E_POS; - - // Prevent the possibility of exponential notation. - Big.E_NEG = -(Big.E_POS = 1 / 0); - - if (dp == null) { - str = x.toString(); - } 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) { - //E.g. -0.5 if rounded to -0 will cause toString to omit the minus sign. - str = '-' + str; - } - } - Big.E_NEG = neg; - Big.E_POS = pos; - - if (!str) { - throwErr('!toFix!'); - } - - return str; - }; - - - /* - * 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) { - - if (sd == null) { - return this.toString(); - } else if (sd !== ~~sd || sd < 1 || sd > MAX_DP) { - throwErr('!toPre!'); - } - - return format(this, sd - 1, 2); - }; - - - // Export - - - Big = bigFactory(); - - //AMD. - 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; - module.exports.Big = Big; - - //Browser. + // toFixed } else { - global.Big = Big; + 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 <= Big.NE) ? (x.s < 0 && c[0] ? '-' : '') + + (c.length > 1 ? c[0] + '.' + c.join('').slice(1) : c[0]) + (i < 0 ? 'e' : 'e+') + i + : 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) n = '-0'; + else if (!isValid.test(n += '')) throw Error(bigError + NaN); + + // Determine sign. + x.s = n.charAt(0) == '-' ? (n = n.slice(1), -1) : 1; + + // Decimal point? + if ((e = n.indexOf('.')) > -1) n = n.replace('.', ''); + + // Exponential form? + if ((i = n.search(/e/i)) > 0) { + + // Determine exponent. + if (e < 0) e = i; + e += +n.slice(i + 1); + n = n.substring(0, i); + } else if (e < 0) { + + // Integer. + e = n.length; + } + + nL = n.length; + + // Determine leading zeros. + for (i = 0; i < nL && n.charAt(i) == '0';) ++i; + + if (i == nL) { + + // Zero. + x.c = [x.e = 0]; + } else { + + // Determine trailing zeros. + for (; nL > 0 && n.charAt(--nL) == '0';); + x.e = e - i - 1; + x.c = []; + + // Convert string to array of digits without leading/trailing zeros. + for (e = 0; i <= nL;) x.c[e++] = +n.charAt(i++); + } + + return x; + } + + + /* + * 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 (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, + i = x.e + dp + 1; + + 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] !== undef || xc[i - 1] & 1); + } else if (rm === 3) { + more = more || xc[i] !== undef || i < 0; + } else { + more = false; + if (rm !== 0) throw Error(bigError + 'RM: ' + rm); + } + + 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 { + + // Remove any digits after the required decimal places. + xc.length = i--; + + // Round up? + if (more) { + + // Rounding up may mean the previous digit has to be rounded up. + for (; ++xc[i] > 9;) { + xc[i] = 0; + if (!i--) { + ++x.e; + xc.unshift(1); + } + } + } + + // Remove trailing zeros. + for (i = xc.length; !xc[--i];) xc.pop(); + } + + return x; + } + + + // Prototype/instance methods + + + /* + * Return a new Big whose value is the absolute value of this Big. + */ + P.abs = function () { + var x = new this.constructor(this); + x.s = 1; + return x; + }; + + + /* + * 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 + * 0 if they have the same value. + */ + P.cmp = function (y) { + var xNeg, + x = this, + xc = x.c, + yc = (y = new x.constructor(y)).c, + i = x.s, + j = y.s, + k = x.e, + l = y.e; + + // Either zero? + if (!xc[0] || !yc[0]) return !xc[0] ? !yc[0] ? 0 : -j : i; + + // Signs differ? + if (i != j) return i; + + xNeg = i < 0; + + // Compare exponents. + 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 < j;) { + if (xc[i] != yc[i]) return xc[i] > yc[i] ^ xNeg ? 1 : -1; + } + + // Compare lengths. + return k == l ? 0 : k > l ^ xNeg ? 1 : -1; + }; + + + /* + * 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. + */ + P.div = function (y) { + var x = this, + Big = x.constructor, + dvd = x.c, // dividend + dvs = (y = new Big(y)).c, // divisor + s = x.s == y.s ? 1 : -1, + dp = Big.DP; + + if (dp !== ~~dp || dp < 0 || dp > MAX_DP) throw Error(bigError + 'DP: ' + dp); + + // Either 0? + if (!dvd[0] || !dvs[0]) { + + // If both are 0, throw NaN + if (dvd[0] == dvs[0]) throw Error(bigError + NaN); + + // If dvs is 0, throw +-Infinity. + if (!dvs[0]) throw Error(bigError + s / 0); + + // dvd is 0, return +-0. + return new Big(s * 0); + } + + var dvsL, dvsT, next, cmp, remI, + dvsZ = dvs.slice(), + dvdI = dvsL = dvs.length, + dvdL = dvd.length, + rem = dvd.slice(0, dvsL), // remainder + remL = rem.length, + q = y, // quotient + qc = q.c = [], + qi = 0, + digits = dp + (q.e = x.e - y.e) + 1; + + q.s = s; + s = digits < 0 ? 0 : digits; + + // Create version of divisor with leading zero. + dvsZ.unshift(0); + + // Add zeros to make remainder as long as divisor. + for (; remL++ < dvsL;) rem.push(0); + + do { + + // '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)) { + cmp = dvsL > remL ? 1 : -1; + } else { + for (remI = -1, cmp = 0; ++remI < dvsL;) { + if (dvs[remI] != rem[remI]) { + cmp = dvs[remI] > rem[remI] ? 1 : -1; + break; + } + } + } + + // If divisor < remainder, subtract divisor from remainder. + if (cmp < 0) { + + // 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;) { + if (rem[--remL] < dvsT[remL]) { + remI = remL; + for (; remI && !rem[--remI];) rem[remI] = 9; + --rem[remI]; + rem[remL] += 10; + } + + rem[remL] -= dvsT[remL]; + } + + for (; !rem[0];) rem.shift(); + } else { + break; + } + } + + // Add the 'next' digit to the result array. + qc[qi++] = cmp ? next : ++next; + + // Update the remainder. + if (rem[0] && cmp) rem[remL] = dvd[dvdI] || 0; + else rem = [dvd[dvdI]]; + + } while ((dvdI++ < dvdL || rem[0] !== undef) && s--); + + // Leading zero? Do not remove if result is simply zero (qi == 1). + if (!qc[0] && qi != 1) { + + // There can't be more than one zero. + qc.shift(); + q.e--; + } + + // Round? + if (qi > digits) rnd(q, dp, Big.RM, rem[0] !== undef); + + return q; + }; + + + /* + * Return true if the value of this Big is equal to the value of Big y, otherwise return false. + */ + P.eq = function (y) { + return !this.cmp(y); + }; + + + /* + * Return true if the value of this Big is greater than the value of Big y, otherwise return + * false. + */ + P.gt = function (y) { + return this.cmp(y) > 0; + }; + + + /* + * Return true if the value of this Big is greater than or equal to the value of Big y, otherwise + * return false. + */ + P.gte = function (y) { + return this.cmp(y) > -1; + }; + + + /* + * Return true if the value of this Big is less than the value of Big y, otherwise return false. + */ + P.lt = function (y) { + return this.cmp(y) < 0; + }; + + + /* + * Return true if the value of this Big is less than or equal to the value of Big y, otherwise + * return false. + */ + P.lte = function (y) { + return this.cmp(y) < 1; + }; + + + /* + * Return a new Big whose value is the value of this Big minus the value of Big y. + */ + P.sub = P.minus = function (y) { + var i, j, t, xLTy, + x = this, + Big = x.constructor, + a = x.s, + b = (y = new Big(y)).s; + + // Signs differ? + if (a != b) { + y.s = -b; + return x.plus(y); + } + + var xc = x.c.slice(), + xe = x.e, + yc = y.c, + ye = y.e; + + // Either zero? + if (!xc[0] || !yc[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); + } + + // Determine which is the bigger number. Prepend zeros to equalise exponents. + if (a = xe - ye) { + + if (xLTy = a < 0) { + a = -a; + t = xc; + } else { + ye = xe; + t = yc; + } + + 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; + + for (a = b = 0; b < j; b++) { + if (xc[b] != yc[b]) { + xLTy = xc[b] < yc[b]; + break; + } + } + } + + // x < y? Point xc to the array of the bigger number. + if (xLTy) { + t = xc; + xc = yc; + yc = t; + y.s = -y.s; + } + + /* + * 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 = yc.length) - (i = xc.length)) > 0) for (; b--;) xc[i++] = 0; + + // Subtract yc from xc. + for (b = i; j > a;) { + if (xc[--j] < yc[j]) { + for (i = j; i && !xc[--i];) xc[i] = 9; + --xc[i]; + xc[j] += 10; + } + + xc[j] -= yc[j]; + } + + // Remove trailing zeros. + for (; xc[--b] === 0;) xc.pop(); + + // Remove leading zeros and adjust exponent accordingly. + for (; xc[0] === 0;) { + xc.shift(); + --ye; + } + + if (!xc[0]) { + + // n - n = +0 + y.s = 1; + + // Result must be zero. + xc = [ye = 0]; + } + + y.c = xc; + y.e = ye; + + return y; + }; + + + /* + * Return a new Big whose value is the value of this Big modulo the value of Big y. + */ + P.mod = function (y) { + var yGTx, + x = this, + Big = x.constructor, + a = x.s, + b = (y = new Big(y)).s; + + if (!y.c[0]) throw Error(bigError + NaN); + x.s = y.s = 1; + yGTx = y.cmp(x) == 1; + x.s = a; + y.s = b; + + 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)); + }; + + + /* + * Return a new Big whose value is the value of this Big plus the value of Big y. + */ + P.add = P.plus = function (y) { + var t, + x = this, + Big = x.constructor, + a = x.s, + b = (y = new Big(y)).s; + + // Signs differ? + if (a != b) { + y.s = -b; + return x.minus(y); + } + + var xe = x.e, + xc = x.c, + ye = y.e, + yc = y.c; + + // Either zero? y is non-zero? x is non-zero? Or both are zero. + if (!xc[0] || !yc[0]) 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 (a = xe - ye) { + if (a > 0) { + ye = xe; + t = yc; + } else { + a = -a; + t = xc; + } + + t.reverse(); + for (; a--;) t.push(0); + t.reverse(); + } + + // 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. + for (b = 0; a; xc[a] %= 10) b = (xc[--a] = xc[a] + yc[a] + b) / 10 | 0; + + // No need to check for zero, as +x + +y != 0 && -x + -y != 0 + + if (b) { + xc.unshift(b); + ++ye; + } + + // Remove trailing zeros. + for (a = xc.length; xc[--a] === 0;) xc.pop(); + + y.c = xc; + y.e = ye; + + return y; + }; + + + /* + * 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. + * + * n {number} Integer, -MAX_POWER to MAX_POWER inclusive. + */ + P.pow = function (n) { + var x = this, + one = new x.constructor(1), + y = one, + isNeg = n < 0; + + if (n !== ~~n || n < -MAX_POWER || n > MAX_POWER) throw Error(bigError + n); + n = isNeg ? -n : n; + + for (;;) { + if (n & 1) y = y.times(x); + n >>= 1; + if (!n) break; + x = x.times(x); + } + + return isNeg ? one.div(y) : y; + }; + + + /* + * 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) + */ + P.round = function (dp, rm) { + var x = this, + Big = x.constructor; + + if (dp === undef) dp = 0; + else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) throw Error(bigError + dp); + + return rnd(new Big(x), dp, rm === undef ? Big.RM : 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. + */ + P.sqrt = function () { + var estimate, r, approx, + x = this, + Big = x.constructor, + xc = x.c, + i = x.s, + e = x.e, + half = new Big('0.5'); + + // Zero? + if (!xc[0]) return new Big(x); + + // If negative, throw NaN. + if (i < 0) throw Error(bigError + NaN); + + // Estimate. + i = Math.sqrt(x.toString()); + + // Math.sqrt underflow/overflow? + // 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)) estimate += '0'; + r = new Big(Math.sqrt(estimate).toString()); + r.e = ((e + 1) / 2 | 0) - (e < 0 || e & 1); + } else { + r = new Big(i.toString()); + } + + i = r.e + (Big.DP += 4); + + // 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('')); + + return rnd(r, Big.DP -= 4, Big.RM); + }; + + + /* + * Return a new Big whose value is the value of this Big times the value of Big y. + */ + P.mul = P.times = function (y) { + var c, + x = this, + Big = x.constructor, + xc = x.c, + yc = (y = new Big(y)).c, + a = xc.length, + b = yc.length, + i = x.e, + j = y.e; + + // Determine sign of result. + y.s = x.s == y.s ? 1 : -1; + + // 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 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; + } + + // Initialise coefficient array of result with zeros. + for (c = new Array(j = a + b); j--;) c[j] = 0; + + // Multiply. + + // i is initially xc.length. + for (i = b; i--;) { + b = 0; + + // 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; + } + + // Increment result exponent if there is a final carry, otherwise remove leading zero. + if (b) ++y.e; + else c.shift(); + + // Remove trailing zeros. + for (i = c.length; !c[--i];) c.pop(); + y.c = c; + + return y; + }; + + + /* + * Return a string representing the value of this Big. + * Return exponential notation if this Big has a positive exponent equal to or greater than + * Big.PE, or a negative exponent equal to or less than Big.NE. + */ + P.toString = P.valueOf = P.toJSON = function () { + var x = this, + Big = x.constructor, + e = x.e, + str = x.c.join(''), + strL = str.length; + + // Exponential notation? + if (e <= Big.NE || e >= Big.PE) { + str = str.charAt(0) + (strL > 1 ? '.' + str.slice(1) : '') + (e < 0 ? 'e' : 'e+') + e; + } else if (e < 0) { + for (; ++e;) str = '0' + str; + str = '0.' + str; + } else if (e > 0) { + if (++e > strL) for (e -= strL; e--;) str += '0'; + else if (e < strL) str = str.slice(0, e) + '.' + str.slice(e); + + // Exponent is zero. + } else if (strL > 1) { + str = str.charAt(0) + '.' + str.slice(1); + } + + // Avoid '-0' + return x.s < 0 && x.c[0] ? '-' + str : str; + }; + + + /* + * If toExponential, toFixed, toPrecision and format are not required they can safely be + * commented-out or deleted. No redundant code will be left. + * The format function is used only by toExponential, toFixed and toPrecision. + */ + + + /* + * Return a string representing the value of this Big in exponential 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) { + if (dp === undef) dp = this.c.length - 1; + else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) throw Error(bigError + dp); + return format(this, dp, 1); + }; + + + /* + * Return a string representing the value of this Big in normal notation to dp fixed decimal + * places and rounded, if necessary, using Big.RM. + * + * [dp] {number} Integer, 0 to MAX_DP inclusive. + */ + P.toFixed = function (dp) { + var str, + x = this, + Big = x.constructor, + ne = Big.NE, + pe = Big.PE; + + // Prevent the possibility of exponential notation. + Big.NE = -(Big.PE = 1 / 0); + + if (dp === undef) { + str = x.toString(); + } 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) { + + //E.g. -0.5 if rounded to -0 will cause toString to omit the minus sign. + str = '-' + str; + } + } + + Big.NE = ne; + Big.PE = pe; + + if (!str) throw Error(bigError + dp); + + return str; + }; + + + /* + * 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) { + if (sd === undef) return this.toString(); + else if (sd !== ~~sd || sd < 1 || sd > MAX_DP) throw Error(bigError + sd); + return format(this, sd - 1, 2); + }; + + + // Export + + + Big = bigFactory(); + + Big['default'] = Big.Big = Big; + + //AMD. + 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. + } else { + global.Big = Big; + } })(this); diff --git a/big.min.js b/big.min.js index 560f160..e12babe 100644 --- a/big.min.js +++ b/big.min.js @@ -1,3 +1,3 @@ /* big.js v3.2.0 https://github.com/MikeMcl/big.js/LICENCE */ -!function(e){"use strict";function t(){function e(r){var i=this;return i instanceof e?(r instanceof e?(i.s=r.s,i.e=r.e,i.c=r.c.slice()):n(i,r),void(i.constructor=e)):void 0===r?t():new e(r)}return e.prototype=g,e.DP=c,e.RM=u,e.E_NEG=l,e.E_POS=a,e}function r(e,t,r){var n=e.constructor,s=t-(e=new n(e)).e,o=e.c;for(o.length>++t&&i(e,s,n.RM),o[0]?r?s=t:(o=e.c,s=e.e+s+1):++s;o.length=t||s<=n.E_NEG)?(e.s<0&&o[0]?"-":"")+(o.length>1?o[0]+"."+o.join("").slice(1):o[0])+(0>s?"e":"e+")+s:e.toString()}function n(e,t){var r,n,i;for(0===t&&0>1/t?t="-0":p.test(t+="")||s(NaN),e.s="-"==t.charAt(0)?(t=t.slice(1),-1):1,(r=t.indexOf("."))>-1&&(t=t.replace(".","")),(n=t.search(/e/i))>0?(0>r&&(r=n),r+=+t.slice(n+1),t=t.substring(0,n)):0>r&&(r=t.length),i=t.length,n=0;i>n&&"0"==t.charAt(n);n++);if(n==i)e.c=[e.e=0];else{for(;i>0&&"0"==t.charAt(--i););for(e.e=r-n-1,e.c=[];i>=n;e.c.push(+t.charAt(n++)));}return e}function i(e,t,r,n){var i,o=e.c,c=e.e+t+1;if(1===r?n=o[c]>=5:2===r?n=o[c]>5||5==o[c]&&(n||0>c||o[c+1]!==i||1&o[c-1]):3===r?n=n||o[c]!==i||0>c:(n=!1,0!==r&&s("!Big.RM!")),1>c||!o[0])n?(e.e=-t,e.c=[1]):e.c=[e.e=0];else{if(o.length=c--,n)for(;++o[c]>9;)o[c]=0,c--||(++e.e,o.unshift(1));for(c=o.length;!o[--c];o.pop());}return e}function s(e){var t=new Error(e);throw t.name="BigError",t}var o,c=20,u=1,f=1e6,h=1e6,l=-7,a=21,g={},p=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;g.abs=function(){var e=new this.constructor(this);return e.s=1,e},g.cmp=function(e){var t,r=this,n=r.c,i=(e=new r.constructor(e)).c,s=r.s,o=e.s,c=r.e,u=e.e;if(!n[0]||!i[0])return n[0]?s:i[0]?-o:0;if(s!=o)return s;if(t=0>s,c!=u)return c>u^t?1:-1;for(s=-1,o=(c=n.length)<(u=i.length)?c:u;++si[s]^t?1:-1;return c==u?0:c>u^t?1:-1},g.div=function(e){var t=this,r=t.constructor,n=t.c,o=(e=new r(e)).c,c=t.s==e.s?1:-1,u=r.DP;if((u!==~~u||0>u||u>f)&&s("!Big.DP!"),!n[0]||!o[0])return n[0]==o[0]&&s(NaN),o[0]||s(c/0),new r(0*c);var h,l,a,g,p,v,d=o.slice(),w=h=o.length,m=n.length,E=n.slice(0,h),N=E.length,P=e,S=P.c=[],M=0,_=u+(P.e=t.e-e.e)+1;for(P.s=c,c=0>_?0:_,d.unshift(0);N++a;a++){if(h!=(N=E.length))g=h>N?1:-1;else for(p=-1,g=0;++pE[p]?1:-1;break}if(!(0>g))break;for(l=N==h?o:d;N;){if(E[--N]_&&i(P,u,r.RM,E[0]!==v),P},g.eq=function(e){return!this.cmp(e)},g.gt=function(e){return this.cmp(e)>0},g.gte=function(e){return this.cmp(e)>-1},g.lt=function(e){return this.cmp(e)<0},g.lte=function(e){return this.cmp(e)<1},g.sub=g.minus=function(e){var t,r,n,i,s=this,o=s.constructor,c=s.s,u=(e=new o(e)).s;if(c!=u)return e.s=-u,s.plus(e);var f=s.c.slice(),h=s.e,l=e.c,a=e.e;if(!f[0]||!l[0])return l[0]?(e.s=-u,e):new o(f[0]?s:0);if(c=h-a){for((i=0>c)?(c=-c,n=f):(a=h,n=l),n.reverse(),u=c;u--;n.push(0));n.reverse()}else for(r=((i=f.lengthu;u++)if(f[u]!=l[u]){i=f[u]0)for(;u--;f[t++]=0);for(u=t;r>c;){if(f[--r]0?(u=o,t=f):(i=-i,t=c),t.reverse();i--;t.push(0));t.reverse()}for(c.length-f.length<0&&(t=f,f=c,c=t),i=f.length,s=0;i;)s=(c[--i]=c[i]+f[i]+s)/10|0,c[i]%=10;for(s&&(c.unshift(s),++u),i=c.length;0===c[--i];c.pop());return e.c=c,e.e=u,e},g.pow=function(e){var t=this,r=new t.constructor(1),n=r,i=0>e;for((e!==~~e||-h>e||e>h)&&s("!pow!"),e=i?-e:e;1&e&&(n=n.times(t)),e>>=1,e;)t=t.times(t);return i?r.div(n):n},g.round=function(e,t){var r=this,n=r.constructor;return null==e?e=0:(e!==~~e||0>e||e>f)&&s("!round!"),i(r=new n(r),e,null==t?n.RM:t),r},g.sqrt=function(){var e,t,r,n=this,o=n.constructor,c=n.c,u=n.s,f=n.e,h=new o("0.5");if(!c[0])return new o(n);0>u&&s(NaN),u=Math.sqrt(n.toString()),0===u||u===1/0?(e=c.join(""),e.length+f&1||(e+="0"),t=new o(Math.sqrt(e).toString()),t.e=((f+1)/2|0)-(0>f||1&f)):t=new o(u.toString()),u=t.e+(o.DP+=4);do r=t,t=h.times(r.plus(n.div(r)));while(r.c.slice(0,u).join("")!==t.c.slice(0,u).join(""));return i(t,o.DP-=4,o.RM),t},g.mul=g.times=function(e){var t,r=this,n=r.constructor,i=r.c,s=(e=new n(e)).c,o=i.length,c=s.length,u=r.e,f=e.e;if(e.s=r.s==e.s?1:-1,!i[0]||!s[0])return new n(0*e.s);for(e.e=u+f,c>o&&(t=i,i=s,s=t,f=o,o=c,c=f),t=new Array(f=o+c);f--;t[f]=0);for(u=c;u--;){for(c=0,f=o+u;f>u;)c=t[f]+s[u]*i[f-u-1]+c,t[f--]=c%10,c=c/10|0;t[f]=(t[f]+c)%10}for(c&&++e.e,t[0]||t.shift(),u=t.length;!t[--u];t.pop());return e.c=t,e},g.toString=g.valueOf=g.toJSON=function(){var e=this,t=e.constructor,r=e.e,n=e.c.join(""),i=n.length;if(r<=t.E_NEG||r>=t.E_POS)n=n.charAt(0)+(i>1?"."+n.slice(1):"")+(0>r?"e":"e+")+r;else if(0>r){for(;++r;n="0"+n);n="0."+n}else if(r>0)if(++r>i)for(r-=i;r--;n+="0");else i>r&&(n=n.slice(0,r)+"."+n.slice(r));else i>1&&(n=n.charAt(0)+"."+n.slice(1));return e.s<0&&e.c[0]?"-"+n:n},g.toExponential=function(e){return null==e?e=this.c.length-1:(e!==~~e||0>e||e>f)&&s("!toExp!"),r(this,e,1)},g.toFixed=function(e){var t,n=this,i=n.constructor,o=i.E_NEG,c=i.E_POS;return i.E_NEG=-(i.E_POS=1/0),null==e?t=n.toString():e===~~e&&e>=0&&f>=e&&(t=r(n,n.e+e),n.s<0&&n.c[0]&&t.indexOf("-")<0&&(t="-"+t)),i.E_NEG=o,i.E_POS=c,t||s("!toFix!"),t},g.toPrecision=function(e){return null==e?this.toString():((e!==~~e||1>e||e>f)&&s("!toPre!"),r(this,e-1,2))},o=t(),"function"==typeof define&&define.amd?define(function(){return o}):"undefined"!=typeof module&&module.exports?(module.exports=o,module.exports.Big=o):e.Big=o}(this); +!function(r){"use strict";function e(){function r(t){var i=this;return i instanceof r?(t instanceof r?(i.s=t.s,i.e=t.e,i.c=t.c.slice()):n(i,t),void(i.constructor=r)):t===p?e():new r(t)}return r.prototype=a,r.DP=s,r.RM=f,r.NE=h,r.PE=l,r}function t(r,e,t){var n=r.constructor,o=e-(r=new n(r)).e,s=r.c;for(s.length>++e&&i(r,o,n.RM),s[0]?t?o=e:(s=r.c,o=r.e+o+1):++o;s.length=e||o<=n.NE)?(r.s<0&&s[0]?"-":"")+(s.length>1?s[0]+"."+s.join("").slice(1):s[0])+(0>o?"e":"e+")+o:r.toString()}function n(r,e){var t,n,i;if(0===e&&0>1/e)e="-0";else if(!g.test(e+=""))throw Error(w+NaN);for(r.s="-"==e.charAt(0)?(e=e.slice(1),-1):1,(t=e.indexOf("."))>-1&&(e=e.replace(".","")),(n=e.search(/e/i))>0?(0>t&&(t=n),t+=+e.slice(n+1),e=e.substring(0,n)):0>t&&(t=e.length),i=e.length,n=0;i>n&&"0"==e.charAt(n);)++n;if(n==i)r.c=[r.e=0];else{for(;i>0&&"0"==e.charAt(--i););for(r.e=t-n-1,r.c=[],t=0;i>=n;)r.c[t++]=+e.charAt(n++)}return r}function i(r,e,t,n){var i=r.c,o=r.e+e+1;if(1===t)n=i[o]>=5;else if(2===t)n=i[o]>5||5==i[o]&&(n||0>o||i[o+1]!==p||1&i[o-1]);else if(3===t)n=n||i[o]!==p||0>o;else if(n=!1,0!==t)throw Error(w+"RM: "+t);if(1>o||!i[0])n?(r.e=-e,r.c=[1]):r.c=[r.e=0];else{if(i.length=o--,n)for(;++i[o]>9;)i[o]=0,o--||(++r.e,i.unshift(1));for(o=i.length;!i[--o];)i.pop()}return r}var o,s=20,f=1,c=1e6,u=1e6,h=-7,l=21,a={},g=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,w="[BigError] ",p=void 0;a.abs=function(){var r=new this.constructor(this);return r.s=1,r},a.cmp=function(r){var e,t=this,n=t.c,i=(r=new t.constructor(r)).c,o=t.s,s=r.s,f=t.e,c=r.e;if(!n[0]||!i[0])return n[0]?o:i[0]?-s:0;if(o!=s)return o;if(e=0>o,f!=c)return f>c^e?1:-1;for(o=-1,s=(f=n.length)<(c=i.length)?f:c;++oi[o]^e?1:-1;return f==c?0:f>c^e?1:-1},a.div=function(r){var e=this,t=e.constructor,n=e.c,o=(r=new t(r)).c,s=e.s==r.s?1:-1,f=t.DP;if(f!==~~f||0>f||f>c)throw Error(w+"DP: "+f);if(!n[0]||!o[0]){if(n[0]==o[0])throw Error(w+NaN);if(!o[0])throw Error(w+s/0);return new t(0*s)}var u,h,l,a,g,v=o.slice(),d=u=o.length,E=n.length,m=n.slice(0,u),N=m.length,P=r,M=P.c=[],R=0,D=f+(P.e=e.e-r.e)+1;for(P.s=s,s=0>D?0:D,v.unshift(0);N++l;l++){if(u!=(N=m.length))a=u>N?1:-1;else for(g=-1,a=0;++gm[g]?1:-1;break}if(!(0>a))break;for(h=N==u?o:v;N;){if(m[--N]D&&i(P,f,t.RM,m[0]!==p),P},a.eq=function(r){return!this.cmp(r)},a.gt=function(r){return this.cmp(r)>0},a.gte=function(r){return this.cmp(r)>-1},a.lt=function(r){return this.cmp(r)<0},a.lte=function(r){return this.cmp(r)<1},a.sub=a.minus=function(r){var e,t,n,i,o=this,s=o.constructor,f=o.s,c=(r=new s(r)).s;if(f!=c)return r.s=-c,o.plus(r);var u=o.c.slice(),h=o.e,l=r.c,a=r.e;if(!u[0]||!l[0])return l[0]?(r.s=-c,r):new s(u[0]?o:0);if(f=h-a){for((i=0>f)?(f=-f,n=u):(a=h,n=l),n.reverse(),c=f;c--;)n.push(0);n.reverse()}else for(t=((i=u.lengthc;c++)if(u[c]!=l[c]){i=u[c]0)for(;c--;)u[e++]=0;for(c=e;t>f;){if(u[--t]0?(c=s,e=u):(i=-i,e=f),e.reverse();i--;)e.push(0);e.reverse()}for(f.length-u.length<0&&(e=u,u=f,f=e),i=u.length,o=0;i;f[i]%=10)o=(f[--i]=f[i]+u[i]+o)/10|0;for(o&&(f.unshift(o),++c),i=f.length;0===f[--i];)f.pop();return r.c=f,r.e=c,r},a.pow=function(r){var e=this,t=new e.constructor(1),n=t,i=0>r;if(r!==~~r||-u>r||r>u)throw Error(w+r);for(r=i?-r:r;1&r&&(n=n.times(e)),r>>=1,r;)e=e.times(e);return i?t.div(n):n},a.round=function(r,e){var t=this,n=t.constructor;if(r===p)r=0;else if(r!==~~r||0>r||r>c)throw Error(w+r);return i(new n(t),r,e===p?n.RM:e)},a.sqrt=function(){var r,e,t,n=this,o=n.constructor,s=n.c,f=n.s,c=n.e,u=new o("0.5");if(!s[0])return new o(n);if(0>f)throw Error(w+NaN);f=Math.sqrt(n.toString()),0===f||f===1/0?(r=s.join(""),r.length+c&1||(r+="0"),e=new o(Math.sqrt(r).toString()),e.e=((c+1)/2|0)-(0>c||1&c)):e=new o(f.toString()),f=e.e+(o.DP+=4);do t=e,e=u.times(t.plus(n.div(t)));while(t.c.slice(0,f).join("")!==e.c.slice(0,f).join(""));return i(e,o.DP-=4,o.RM)},a.mul=a.times=function(r){var e,t=this,n=t.constructor,i=t.c,o=(r=new n(r)).c,s=i.length,f=o.length,c=t.e,u=r.e;if(r.s=t.s==r.s?1:-1,!i[0]||!o[0])return new n(0*r.s);for(r.e=c+u,f>s&&(e=i,i=o,o=e,u=s,s=f,f=u),e=new Array(u=s+f);u--;)e[u]=0;for(c=f;c--;){for(f=0,u=s+c;u>c;)f=e[u]+o[c]*i[u-c-1]+f,e[u--]=f%10,f=f/10|0;e[u]=(e[u]+f)%10}for(f?++r.e:e.shift(),c=e.length;!e[--c];)e.pop();return r.c=e,r},a.toString=a.valueOf=a.toJSON=function(){var r=this,e=r.constructor,t=r.e,n=r.c.join(""),i=n.length;if(t<=e.NE||t>=e.PE)n=n.charAt(0)+(i>1?"."+n.slice(1):"")+(0>t?"e":"e+")+t;else if(0>t){for(;++t;)n="0"+n;n="0."+n}else if(t>0)if(++t>i)for(t-=i;t--;)n+="0";else i>t&&(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},a.toExponential=function(r){if(r===p)r=this.c.length-1;else if(r!==~~r||0>r||r>c)throw Error(w+r);return t(this,r,1)},a.toFixed=function(r){var e,n=this,i=n.constructor,o=i.NE,s=i.PE;if(i.NE=-(i.PE=1/0),r===p?e=n.toString():r===~~r&&r>=0&&c>=r&&(e=t(n,n.e+r),n.s<0&&n.c[0]&&e.indexOf("-")<0&&(e="-"+e)),i.NE=o,i.PE=s,!e)throw Error(w+r);return e},a.toPrecision=function(r){if(r===p)return this.toString();if(r!==~~r||1>r||r>c)throw Error(w+r);return t(this,r-1,2)},o=e(),o["default"]=o.Big=o,"function"==typeof define&&define.amd?define(function(){return o}):"undefined"!=typeof module&&module.exports?module.exports=o:r.Big=o}(this); //# sourceMappingURL=doc/big.js.map \ No newline at end of file diff --git a/doc/big.js.map b/doc/big.js.map index 025b5ba..be70b12 100644 --- a/doc/big.js.map +++ b/doc/big.js.map @@ -1 +1 @@ -{"version":3,"file":"big.min.js","sources":["big.js"],"names":["global","bigFactory","Big","n","x","this","s","e","c","slice","parse","constructor","prototype","P","DP","RM","E_NEG","E_POS","format","dp","toE","i","length","rnd","push","join","toString","nL","isValid","test","throwErr","NaN","charAt","indexOf","replace","search","substring","rm","more","u","xc","unshift","pop","message","err","Error","name","MAX_DP","MAX_POWER","abs","cmp","y","xNeg","yc","j","k","l","div","dvd","dvs","dvsL","dvsT","next","remI","dvsZ","dvdI","dvdL","rem","remL","q","qc","qi","digits","shift","eq","gt","gte","lt","lte","sub","minus","t","xLTy","a","b","plus","xe","ye","reverse","mod","yGTx","times","add","pow","one","isNeg","round","sqrt","estimate","r","approx","half","Math","mul","Array","valueOf","toJSON","str","strL","toExponential","toFixed","neg","pos","toPrecision","sd","define","amd","module","exports"],"mappings":";CACC,SAAWA,GACR,YAiEA,SAASC,KAQL,QAASC,GAAIC,GACT,GAAIC,GAAIC,IAGR,OAAMD,aAAaF,IAKfC,YAAaD,IACbE,EAAEE,EAAIH,EAAEG,EACRF,EAAEG,EAAIJ,EAAEI,EAC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IACjCwF,EAAMzF,EAAOd,EAAGA,EAAEG,EAAIY,GAIlBf,EAAEE,EAAI,GAAKF,EAAEI,EAAE,IAAMmG,EAAI1E,QAAQ,KAAO,IAExC0E,EAAM,IAAMA,IAGpBzG,EAAIc,MAAQ+F,EACZ7G,EAAIe,MAAQ+F,EAEPL,GACD7E,EAAS,WAGN6E,GAYX9F,EAAEoG,YAAc,SAAUC,GAEtB,MAAU,OAANA,EACO7G,KAAKqB,aACLwF,MAASA,GAAW,EAALA,GAAUA,EAAKnE,IACrCjB,EAAS,WAGNZ,EAAOb,KAAM6G,EAAK,EAAG,KAOhChH,EAAMD,IAGgB,kBAAXkH,SAAyBA,OAAOC,IACvCD,OAAO,WACH,MAAOjH,KAIc,mBAAXmH,SAA0BA,OAAOC,SAC/CD,OAAOC,QAAUpH,EACjBmH,OAAOC,QAAQpH,IAAMA,GAIrBF,EAAOE,IAAMA,GAElBG"} \ No newline at end of file +{"version":3,"file":"big.min.js","sources":["big.js"],"names":["global","bigFactory","Big","n","x","this","s","e","c","slice","parse","constructor","undef","prototype","P","DP","RM","NE","PE","format","dp","toE","i","length","rnd","push","join","toString","nL","isValid","test","Error","bigError","NaN","charAt","indexOf","replace","search","substring","rm","more","xc","unshift","pop","MAX_DP","MAX_POWER","abs","cmp","y","xNeg","yc","j","k","l","div","dvd","dvs","dvsL","dvsT","next","remI","dvsZ","dvdI","dvdL","rem","remL","q","qc","qi","digits","shift","eq","gt","gte","lt","lte","sub","minus","t","xLTy","a","b","plus","xe","ye","reverse","mod","yGTx","times","add","pow","one","isNeg","round","sqrt","estimate","r","approx","half","Math","mul","Array","valueOf","toJSON","str","strL","toExponential","toFixed","ne","pe","toPrecision","sd","define","amd","module","exports"],"mappings":";CACC,SAAWA,GACV,YAoEA,SAASC,KAQP,QAASC,GAAIC,GACX,GAAIC,GAAIC,IAGR,OAAMD,aAAaF,IAGfC,YAAaD,IACfE,EAAEE,EAAIH,EAAEG,EACRF,EAAEG,EAAIJ,EAAEI,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C,KACJH,EAAME,EAAEO,YACRiG,EAAK1G,EAAIe,GACT4F,EAAK3G,EAAIgB,EAsBX,IAnBAhB,EAAIe,KAAOf,EAAIgB,GAAK,EAAI,GAEpBE,IAAOR,EACT4F,EAAMpG,EAAEuB,WACCP,MAASA,GAAMA,GAAM,GAAWwB,GAANxB,IACnCoF,EAAMrF,EAAOf,EAAGA,EAAEG,EAAIa,GAIlBhB,EAAEE,EAAI,GAAKF,EAAEI,EAAE,IAAMgG,EAAIrE,QAAQ,KAAO,IAG1CqE,EAAM,IAAMA,IAIhBtG,EAAIe,GAAK2F,EACT1G,EAAIgB,GAAK2F,GAEJL,EAAK,KAAMzE,OAAMC,EAAWZ,EAEjC,OAAOoF,IAWT1F,EAAEgG,YAAc,SAAUC,GACxB,GAAIA,IAAOnG,EAAO,MAAOP,MAAKsB,UACzB,IAAIoF,MAASA,GAAW,EAALA,GAAUA,EAAKnE,EAAQ,KAAMb,OAAMC,EAAW+E,EACtE,OAAO5F,GAAOd,KAAM0G,EAAK,EAAG,IAO9B7G,EAAMD,IAENC,EAAI,WAAaA,EAAIA,IAAMA,EAGL,kBAAX8G,SAAyBA,OAAOC,IACzCD,OAAO,WAAc,MAAO9G,KAGD,mBAAXgH,SAA0BA,OAAOC,QACjDD,OAAOC,QAAUjH,EAIjBF,EAAOE,IAAMA,GAEdG"} \ No newline at end of file diff --git a/doc/bigAPI.html b/doc/bigAPI.html index f0bb4a2..ffaae27 100644 --- a/doc/bigAPI.html +++ b/doc/bigAPI.html @@ -68,8 +68,8 @@ code,pre{font-family:Monaco,Consolas,"Lucida Console",monospace; INSTANCE @@ -191,8 +191,7 @@ new Big('-735.0918e-430') // '-7.350918e-428'

The value will be checked for validity when one of the above methods is - called.
!Big.DP! will be thrown if the - value is found to be invalid. + called.
An error will be thrown if the value is found to be invalid.

Big.DP = 40
@@ -248,14 +247,13 @@ new Big('-735.0918e-430') // '-7.350918e-428'

The value will be checked for validity when one of the above methods is - called.
!Big.RM! will be thrown if the - value is found to be invalid. + called.
An error will be thrown if the value is found to be invalid.

Big.RM = 0
- - - -
E_NEG
+ + + +
NE

number : integer, -1e+6 to 0 inclusive
Default value: -7 @@ -265,7 +263,7 @@ new Big('-735.0918e-430') // '-7.350918e-428' toString returns exponential notation.

-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'

@@ -273,7 +271,7 @@ x = new Big(0.000000123) // '1.23e-7' -7 and below.

- Regardless of the value of Big.E_NEG, the + Regardless of the value of Big.NE, the toFixed method will always return a value in normal notation and the toExponential method will always return a value in exponential form. @@ -281,7 +279,7 @@ x = new Big(0.000000123) // '1.23e-7' -

E_POS
+
PE

number : integer, 0 to 1e+6 inclusive
Default value: 21 @@ -291,7 +289,7 @@ x = new Big(0.000000123) // '1.23e-7' toString returns exponential notation.

-Big.E_POS = 2    
+Big.PE = 2
 x = new Big(12.3)                  // '12.3'        e is 1
 x = new Big(123)                   // '1.23e+2'

@@ -299,7 +297,7 @@ x = new Big(123) // '1.23e+2' 21 and above.

- Regardless of the value of Big.E_POS, the + Regardless of the value of Big.PE, the toFixed method will always return a value in normal notation and the toExponential method will always return a value in exponential form. @@ -556,7 +554,7 @@ Big(0.7).plus(x).plus(y) // '1.1' rounding mode Big.RM.

- Throws !pow! if exp is invalid. + Throws if exp is invalid.

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. decimal places.

- if dp is omitted or is null or undefined, the - return value is n rounded to a whole number.
- if rm is omitted or is null or - undefined, the current Big.RM setting is - used. + if dp is omitted or is undefined, the return value is + n rounded to a whole number.
+ if rm is omitted or is undefined, the current + Big.RM setting is used.

- Throws !round! if dp is invalid. -
- Throws !Big.RM! if rm is invalid. + Throws if dp or rm is invalid.

 x = 123.45
@@ -671,12 +666,12 @@ Big('7e+500').times(y)     // '1.26e+501'
the return value will be appended with zeros accordingly.

- If dp is omitted, or is null or undefined, the - number of digits after the decimal point defaults to the minimum number of - digits necessary to represent the value exactly. + If dp 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.

- Throws !toExp! if dp is invalid. + Throws if dp is invalid.

 x = 45.6
@@ -720,13 +715,13 @@ y.toExponential(3)         // '4.560e+1'
this method will always return normal notation.

- If dp is omitted, or is null or - undefined, then the return value is simply the value in normal notation. - This is also unlike Number.prototype.toFixed, which returns - the value to zero decimal places. + If dp is omitted or is undefined, the return value is + simply the value in normal notation. This is also unlike + Number.prototype.toFixed, which returns the value to zero + decimal places.

- Throws !toFix! if dp is invalid. + Throws if dp is invalid.

 x = 45.6
@@ -760,15 +755,15 @@ y.toFixed(3)               // '45.600'

If sd 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.

- If sd is omitted, or is null or undefined, then - the return value is the same as .toString(). + If sd is omitted or is undefined, the return value is + the same as .toString().

- Throws !toPre! if sd is invalid. + Throws if sd is invalid.

 x = 45.6
@@ -790,14 +785,14 @@ y.toPrecision(5)           // '45.600'

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.

The point at which toString returns exponential rather than normal notation can be adjusted by changing the value of - Big.E_POS and - Big.E_NEG. By default, Big numbers + Big.PE and + Big.NE. By default, Big numbers correspond to Javascript's number type in this regard.

@@ -929,9 +924,9 @@ y.s                        // -1

Errors

- The errors that are thrown are instances of Error with - name BigError and message as - shown in the table below. + The errors that are thrown are instances of Error.
+ The message of the errors always begins with + [BigError].

@@ -959,11 +954,11 @@ y.s // -1 - + - + @@ -973,24 +968,24 @@ y.s // -1 - + - + - + - + - + @@ -999,38 +994,38 @@ y.s // -1 - + - + - + - + - + - + - + - +
Division of zero by zero
!Big.DP!DP: invalidValue Invalid Big.DP
!Big.RM!RM: invalidValue Invalid Big.RM
pow!pow!invalidValue Invalid exponent
!Big.DP!DP: invalidValue Invalid Big.DP
!Big.RM!RM: invalidValue Invalid Big.RM
round!round!invalidValue Invalid dp
!Big.RM!RM: invalidValue Invalid rm/Big.RM
Negative number
!Big.DP!DP: invalidValue Invalid Big.DP
!Big.RM!RM: invalidValue Invalid Big.RM
toExponential!toExp!invalidValue Invalid dp
!Big.RM!RM: invalidValue Invalid Big.RM
toFixed!toFix!invalidValue Invalid dp
!Big.RM!RM: invalidValue Invalid Big.RM
toPrecision!toPre!invalidValue Invalid sd
!Big.RM!RM: invalidValue Invalid Big.RM
@@ -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

The Math methods can also be used. @@ -1070,10 +1065,10 @@ parseInt(x.round()) // 9.87654e+32

 x = new Big('1234.56')
 Math.floor(x)             // 1234
-Math.round(x)             // 1235 
+Math.round(x)             // 1235
 

- +
How can I round a Big number to a specified number of significant digits?
@@ -1087,11 +1082,11 @@ Math.round(x) // 1235
 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
 

- +
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.


- +
Why are trailing fractional zeros removed from Big numbers?

Many arbitrary-precision libraries retain trailing fractional zeros as @@ -1224,10 +1219,10 @@ z = x.multiply(y) // 4.1400000 Instead, the toExponential, toFixed and toPrecision methods enable trailing zeros to be added if and when required. -

+


- + diff --git a/test/abs.js b/test/abs.js index 746573a..4efef95 100644 --- a/test/abs.js +++ b/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); } diff --git a/test/browser/every-test.html b/test/browser/every-test.html index ecd385b..2c30302 100644 --- a/test/browser/every-test.html +++ b/test/browser/every-test.html @@ -35,7 +35,7 @@ script = document.createElement("script"); script.src = '../' + methods[i] + '.js'; if (!methods[i++]) { - document.body.innerHTML += '
IN TOTAL: ' + passed + ' of ' + total + + document.body.innerHTML += '
RESULTS: ' + passed + ' of ' + total + ' tests passed in ' + ( (+new Date() - start) / 1000 ) + ' secs.
'; document.body.scrollIntoView(false); return; diff --git a/test/cmp.js b/test/cmp.js index 1b78ccf..3aa2994 100644 --- a/test/cmp.js +++ b/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); } diff --git a/test/div.js b/test/div.js index c7d2608..0a88b00 100644 --- a/test/div.js +++ b/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); } diff --git a/test/every-test.js b/test/every-test.js index 3b1d172..d8d1384 100644 --- a/test/every-test.js +++ b/test/every-test.js @@ -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' ); \ No newline at end of file diff --git a/test/minus.js b/test/minus.js index 878a3e8..e39a2fb 100644 --- a/test/minus.js +++ b/test/minus.js @@ -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); } diff --git a/test/mod.js b/test/mod.js index 34c7282..374fe0b 100644 --- a/test/mod.js +++ b/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); } diff --git a/test/plus.js b/test/plus.js index 94ea8df..6d804cd 100644 --- a/test/plus.js +++ b/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); } diff --git a/test/pow.js b/test/pow.js index 6ae66cd..1155432 100644 --- a/test/pow.js +++ b/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); } diff --git a/test/round.js b/test/round.js index 03d88c4..9b6811d 100644 --- a/test/round.js +++ b/test/round.js @@ -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];; diff --git a/test/sqrt.js b/test/sqrt.js index 4448584..e7b31a8 100644 --- a/test/sqrt.js +++ b/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); } diff --git a/test/times.js b/test/times.js index 1798d65..44d4019 100644 --- a/test/times.js +++ b/test/times.js @@ -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); } diff --git a/test/toExponential.js b/test/toExponential.js index 7a60bc6..21282eb 100644 --- a/test/toExponential.js +++ b/test/toExponential.js @@ -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); diff --git a/test/toFixed.js b/test/toFixed.js index d70fe91..08516bf 100644 --- a/test/toFixed.js +++ b/test/toFixed.js @@ -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); diff --git a/test/toPrecision.js b/test/toPrecision.js index 29b4d50..9e29a0c 100644 --- a/test/toPrecision.js +++ b/test/toPrecision.js @@ -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([])}, "[]"); diff --git a/test/toString.js b/test/toString.js index ff9855e..35fe650 100644 --- a/test/toString.js +++ b/test/toString.js @@ -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; \ No newline at end of file +if (typeof module !== 'undefined' && module.exports) module.exports = count;