@phensley/decimal
Advanced tools
Comparing version 1.5.2 to 1.6.0
@@ -52,4 +52,4 @@ import { add, divide, multiply, subtract, trimLeadingZeros, DivMod } from './math'; | ||
var size = function (n) { | ||
var q = (n / 7 /* RDIGITS */) | 0; | ||
var r = n - q * 7 /* RDIGITS */; | ||
var q = (n / 7 /* Constants.RDIGITS */) | 0; | ||
var r = n - q * 7 /* Constants.RDIGITS */; | ||
return r === 0 ? q : q + 1; | ||
@@ -67,3 +67,3 @@ }; | ||
this._exp = 0; | ||
this.flag = 0 /* NONE */; | ||
this.flag = 0 /* DecimalFlag.NONE */; | ||
if (typeof num === 'string' || typeof num === 'number') { | ||
@@ -89,3 +89,3 @@ this.parse(num); | ||
Decimal.prototype.isNaN = function () { | ||
return this.flag === 1 /* NAN */; | ||
return this.flag === 1 /* DecimalFlag.NAN */; | ||
}; | ||
@@ -102,3 +102,3 @@ /** | ||
Decimal.prototype.isInfinity = function () { | ||
return this.flag === 2 /* INFINITY */; | ||
return this.flag === 2 /* DecimalFlag.INFINITY */; | ||
}; | ||
@@ -122,3 +122,3 @@ /** | ||
// NAN is never equal to itself or any other value | ||
if (u.flag === 1 /* NAN */ || v.flag === 1 /* NAN */) { | ||
if (u.flag === 1 /* DecimalFlag.NAN */ || v.flag === 1 /* DecimalFlag.NAN */) { | ||
return -1; | ||
@@ -133,3 +133,3 @@ } | ||
// Positive infinity after all other values | ||
return u.flag === 2 /* INFINITY */ ? (u.sign === -1 ? -1 : 1) : v.sign === -1 ? 1 : -1; | ||
return u.flag === 2 /* DecimalFlag.INFINITY */ ? (u.sign === -1 ? -1 : 1) : v.sign === -1 ? 1 : -1; | ||
} | ||
@@ -234,3 +234,3 @@ u = u.stripTrailingZeros(); | ||
v = coerceDecimal(v); | ||
var r = this.handleFlags(0 /* ADDITION */, v); | ||
var r = this.handleFlags(0 /* Op.ADDITION */, v); | ||
if (r === undefined) { | ||
@@ -249,3 +249,3 @@ if (this.isZero()) { | ||
v = coerceDecimal(v); | ||
var r = this.handleFlags(1 /* SUBTRACTION */, v); | ||
var r = this.handleFlags(1 /* Op.SUBTRACTION */, v); | ||
if (r === undefined) { | ||
@@ -265,3 +265,3 @@ if (this.isZero()) { | ||
v = coerceDecimal(v); | ||
var r = this.handleFlags(2 /* MULTIPLICATION */, v); | ||
var r = this.handleFlags(2 /* Op.MULTIPLICATION */, v); | ||
if (r !== undefined) { | ||
@@ -302,3 +302,3 @@ return r; | ||
v = coerceDecimal(v); | ||
var r = this.handleFlags(3 /* DIVISION */, v); | ||
var r = this.handleFlags(3 /* Op.DIVISION */, v); | ||
if (r !== undefined) { | ||
@@ -352,5 +352,5 @@ return r; | ||
v = coerceDecimal(v); | ||
var rq = this.handleFlags(3 /* DIVISION */, v); | ||
var rq = this.handleFlags(3 /* Op.DIVISION */, v); | ||
if (rq !== undefined) { | ||
var rm = this.handleFlags(4 /* MOD */, v); | ||
var rm = this.handleFlags(4 /* Op.MOD */, v); | ||
return [rq, rm]; | ||
@@ -394,3 +394,3 @@ } | ||
v = coerceDecimal(v); | ||
var r = this.handleFlags(4 /* MOD */, v); | ||
var r = this.handleFlags(4 /* Op.MOD */, v); | ||
return r === undefined ? this.divmod(v)[1] : r; | ||
@@ -411,3 +411,3 @@ }; | ||
var n = d[i]; | ||
r = i * 7 /* RDIGITS */; | ||
r = i * 7 /* Constants.RDIGITS */; | ||
while (n % 10 === 0) { | ||
@@ -456,3 +456,3 @@ n /= 10 | 0; | ||
var len = this.data.length; | ||
return (len - 1) * 7 /* RDIGITS */ + digitCount(this.data[len - 1]); | ||
return (len - 1) * 7 /* Constants.RDIGITS */ + digitCount(this.data[len - 1]); | ||
}; | ||
@@ -654,3 +654,3 @@ /** | ||
var d = this.data[i]; | ||
var c = i === last ? digitCount(d) : 7 /* RDIGITS */; | ||
var c = i === last ? digitCount(d) : 7 /* Constants.RDIGITS */; | ||
// Loop over the decimal digits | ||
@@ -701,5 +701,5 @@ for (var j = 0; j < c; j++) { | ||
switch (this.flag) { | ||
case 1 /* NAN */: | ||
case 1 /* DecimalFlag.NAN */: | ||
return 'NaN'; | ||
case 2 /* INFINITY */: | ||
case 2 /* DecimalFlag.INFINITY */: | ||
default: | ||
@@ -711,5 +711,5 @@ return this.sign === 1 ? 'Infinity' : '-Infinity'; | ||
switch (this.flag) { | ||
case 1 /* NAN */: | ||
case 1 /* DecimalFlag.NAN */: | ||
return [{ type: 'nan', value: 'NaN' }]; | ||
case 2 /* INFINITY */: | ||
case 2 /* DecimalFlag.INFINITY */: | ||
default: | ||
@@ -754,11 +754,11 @@ var s = this.sign === 1 ? 'Infinity' : '-Infinity'; | ||
// Any operation involving a NAN returns a NAN | ||
if (uflag === 1 /* NAN */ || vflag === 1 /* NAN */) { | ||
if (uflag === 1 /* DecimalFlag.NAN */ || vflag === 1 /* DecimalFlag.NAN */) { | ||
return NAN; | ||
} | ||
var uinf = uflag === 2 /* INFINITY */; | ||
var vinf = vflag === 2 /* INFINITY */; | ||
var uinf = uflag === 2 /* DecimalFlag.INFINITY */; | ||
var vinf = vflag === 2 /* DecimalFlag.INFINITY */; | ||
var uzero = u.isZero(); | ||
var vzero = v.isZero(); | ||
switch (op) { | ||
case 0 /* ADDITION */: | ||
case 0 /* Op.ADDITION */: | ||
if (uinf && vinf) { | ||
@@ -771,3 +771,3 @@ return u.sign === v.sign ? (u.sign === 1 ? POSITIVE_INFINITY : NEGATIVE_INFINITY) : NAN; | ||
break; | ||
case 1 /* SUBTRACTION */: | ||
case 1 /* Op.SUBTRACTION */: | ||
if (uinf && vinf) { | ||
@@ -786,3 +786,3 @@ return u.sign === v.sign ? NAN : u.sign === 1 ? POSITIVE_INFINITY : NEGATIVE_INFINITY; | ||
break; | ||
case 2 /* MULTIPLICATION */: | ||
case 2 /* Op.MULTIPLICATION */: | ||
if (uinf) { | ||
@@ -795,3 +795,3 @@ return vzero ? NAN : u.sign === v.sign ? POSITIVE_INFINITY : NEGATIVE_INFINITY; | ||
break; | ||
case 3 /* DIVISION */: | ||
case 3 /* Op.DIVISION */: | ||
if (uinf && vinf) { | ||
@@ -816,3 +816,3 @@ return NAN; | ||
break; | ||
case 4 /* MOD */: | ||
case 4 /* Op.MOD */: | ||
if (uinf || vzero) { | ||
@@ -847,4 +847,4 @@ return NAN; | ||
// Compute the shift in terms of our radix. | ||
var q = (shift / 7 /* RDIGITS */) | 0; | ||
var r = shift - q * 7 /* RDIGITS */; | ||
var q = (shift / 7 /* Constants.RDIGITS */) | 0; | ||
var r = shift - q * 7 /* Constants.RDIGITS */; | ||
// Expand w to hold shifted result and zero all elements. | ||
@@ -863,3 +863,3 @@ var n = size(prec + shift); | ||
var powlo = POWERS10[r]; | ||
var powhi = POWERS10[7 /* RDIGITS */ - r]; | ||
var powhi = POWERS10[7 /* Constants.RDIGITS */ - r]; | ||
var hi = 0; | ||
@@ -912,3 +912,3 @@ var lo = 0; | ||
var div = new DivMod(); | ||
var _d = div.word(shift, 7 /* RDIGITS */), q = _d[0], r = _d[1]; | ||
var _d = div.word(shift, 7 /* Constants.RDIGITS */), q = _d[0], r = _d[1]; | ||
var data = w.data.slice(); | ||
@@ -921,3 +921,3 @@ w.data.fill(0); | ||
// q is always non-zero here, else there would be no shift | ||
_a = div.pow10(data[q - 1], 7 /* RDIGITS */ - 1), rnd = _a[0], rest = _a[1]; | ||
_a = div.pow10(data[q - 1], 7 /* Constants.RDIGITS */ - 1), rnd = _a[0], rest = _a[1]; | ||
if (rest === 0) { | ||
@@ -932,3 +932,3 @@ rest = allzero(data, q - 1) === 0 ? 1 : 0; | ||
var hiprev = 0; | ||
var ph = POWERS10[7 /* RDIGITS */ - r]; | ||
var ph = POWERS10[7 /* Constants.RDIGITS */ - r]; | ||
// q is always < data.length here; otherwise r == 0 | ||
@@ -998,3 +998,3 @@ _b = div.pow10(data[q], r), hiprev = _b[0], rest = _b[1]; | ||
s = d[i] + k; | ||
k = s === 10000000 /* RADIX */ ? 1 : 0; | ||
k = s === 10000000 /* Constants.RADIX */ ? 1 : 0; | ||
d[i] = k ? 0 : s; | ||
@@ -1094,7 +1094,7 @@ } | ||
if (isNaN(arg)) { | ||
this.flag = 1 /* NAN */; | ||
this.flag = 1 /* DecimalFlag.NAN */; | ||
return; | ||
} | ||
if (!isFinite(arg)) { | ||
this.flag = 2 /* INFINITY */; | ||
this.flag = 2 /* DecimalFlag.INFINITY */; | ||
this.sign = arg === Infinity ? 1 : -1; | ||
@@ -1121,7 +1121,7 @@ return; | ||
if (NAN_VALUES.has(str)) { | ||
this.flag = 1 /* NAN */; | ||
this.flag = 1 /* DecimalFlag.NAN */; | ||
return; | ||
} | ||
if (POS_INFINITY.has(str)) { | ||
this.flag = 2 /* INFINITY */; | ||
this.flag = 2 /* DecimalFlag.INFINITY */; | ||
this.sign = 1; | ||
@@ -1131,3 +1131,3 @@ return; | ||
if (NEG_INFINITY.has(str)) { | ||
this.flag = 2 /* INFINITY */; | ||
this.flag = 2 /* DecimalFlag.INFINITY */; | ||
this.sign = -1; | ||
@@ -1156,5 +1156,5 @@ return; | ||
switch (code) { | ||
case 69 /* ELOWER */: | ||
case 101 /* EUPPER */: | ||
if (flags & 4 /* EXP */) { | ||
case 69 /* Chars.ELOWER */: | ||
case 101 /* Chars.EUPPER */: | ||
if (flags & 4 /* ParseFlags.EXP */) { | ||
return "Extra exponent character at ".concat(i); | ||
@@ -1170,4 +1170,4 @@ } | ||
// Indicate we have an exponent, and clear the sign flag. | ||
flags |= 4 /* EXP */; | ||
flags &= ~1 /* SIGN */; | ||
flags |= 4 /* ParseFlags.EXP */; | ||
flags &= ~1 /* ParseFlags.SIGN */; | ||
// Copy the parsed number to the exponent and reset the digit count. | ||
@@ -1180,34 +1180,34 @@ dig = 0; | ||
break; | ||
case 45 /* MINUS */: | ||
case 43 /* PLUS */: | ||
case 45 /* Chars.MINUS */: | ||
case 43 /* Chars.PLUS */: | ||
if (dig === 0) { | ||
return 'Found a bare sign symbol'; | ||
} | ||
if (flags & 1 /* SIGN */) { | ||
if (flags & 1 /* ParseFlags.SIGN */) { | ||
return "Duplicate sign character at ".concat(i); | ||
} | ||
sign = code === 45 /* MINUS */ ? -1 : 1; | ||
flags |= 1 /* SIGN */; | ||
sign = code === 45 /* Chars.MINUS */ ? -1 : 1; | ||
flags |= 1 /* ParseFlags.SIGN */; | ||
break; | ||
case 46 /* DOT */: | ||
if (flags & 2 /* POINT */) { | ||
case 46 /* Chars.DOT */: | ||
if (flags & 2 /* ParseFlags.POINT */) { | ||
return "Extra radix point seen at ".concat(i); | ||
} | ||
flags |= 2 /* POINT */; | ||
flags |= 2 /* ParseFlags.POINT */; | ||
exp -= dig; | ||
break; | ||
case 48 /* DIGIT0 */: | ||
case 49 /* DIGIT1 */: | ||
case 50 /* DIGIT2 */: | ||
case 51 /* DIGIT3 */: | ||
case 52 /* DIGIT4 */: | ||
case 53 /* DIGIT5 */: | ||
case 54 /* DIGIT6 */: | ||
case 55 /* DIGIT7 */: | ||
case 56 /* DIGIT8 */: | ||
case 57 /* DIGIT9 */: | ||
n += (code - 48 /* DIGIT0 */) * POWERS10[z]; | ||
case 48 /* Chars.DIGIT0 */: | ||
case 49 /* Chars.DIGIT1 */: | ||
case 50 /* Chars.DIGIT2 */: | ||
case 51 /* Chars.DIGIT3 */: | ||
case 52 /* Chars.DIGIT4 */: | ||
case 53 /* Chars.DIGIT5 */: | ||
case 54 /* Chars.DIGIT6 */: | ||
case 55 /* Chars.DIGIT7 */: | ||
case 56 /* Chars.DIGIT8 */: | ||
case 57 /* Chars.DIGIT9 */: | ||
n += (code - 48 /* Chars.DIGIT0 */) * POWERS10[z]; | ||
z++; | ||
dig++; | ||
if (z === 7 /* RDIGITS */) { | ||
if (z === 7 /* Constants.RDIGITS */) { | ||
data.push(n); | ||
@@ -1214,0 +1214,0 @@ n = 0; |
@@ -19,5 +19,5 @@ import { POWERS10 } from './types'; | ||
var z = u[j] + vj + k; | ||
w[j] = z % 10000000 /* RADIX */; | ||
w[j] = z % 10000000 /* Constants.RADIX */; | ||
// .. k is being set to 1 or 0, to carry | ||
k = (z / 10000000 /* RADIX */) | 0; | ||
k = (z / 10000000 /* Constants.RADIX */) | 0; | ||
// A3. Loop on j | ||
@@ -46,3 +46,3 @@ j++; | ||
var z = u[j] - v[j] - k; | ||
w[j] = z < 0 ? z + 10000000 /* RADIX */ : z; | ||
w[j] = z < 0 ? z + 10000000 /* Constants.RADIX */ : z; | ||
// k is set to 1 or 0, indicating a borrow | ||
@@ -56,3 +56,3 @@ k = z < 0 ? 1 : 0; | ||
var z = u[j] - k; | ||
w[j] = z < 0 ? z + 10000000 /* RADIX */ : z; | ||
w[j] = z < 0 ? z + 10000000 /* Constants.RADIX */ : z; | ||
k = z < 0 ? 1 : 0; | ||
@@ -89,4 +89,4 @@ j++; | ||
var p = k + w[i + j] + u[i] * v[j]; | ||
k = (p / 10000000 /* RADIX */) | 0; | ||
w[i + j] = p - k * 10000000 /* RADIX */; | ||
k = (p / 10000000 /* Constants.RADIX */) | 0; | ||
w[i + j] = p - k * 10000000 /* Constants.RADIX */; | ||
// M5. Loop on i | ||
@@ -111,4 +111,4 @@ i++; | ||
var p = k + u[i] * v; | ||
k = (p / 10000000 /* RADIX */) | 0; | ||
w[i] = p - k * 10000000 /* RADIX */; | ||
k = (p / 10000000 /* Constants.RADIX */) | 0; | ||
w[i] = p - k * 10000000 /* Constants.RADIX */; | ||
} | ||
@@ -143,3 +143,3 @@ if (k > 0) { | ||
// D1. Normalize | ||
var d = (10000000 /* RADIX */ / (v[n - 1] + 1)) | 0; | ||
var d = (10000000 /* Constants.RADIX */ / (v[n - 1] + 1)) | 0; | ||
if (d !== 1) { | ||
@@ -156,3 +156,3 @@ multiplyword(u, uc, nplusm, d); | ||
// D3. Calculate q̂ and r̂. | ||
p = u[j + n - 1] + u[j + n] * 10000000 /* RADIX */; | ||
p = u[j + n - 1] + u[j + n] * 10000000 /* Constants.RADIX */; | ||
var qhat = (p / v[n - 1]) | 0; | ||
@@ -162,6 +162,6 @@ var rhat = p - qhat * v[n - 1]; | ||
// D3. Test if q̂ = radix ... | ||
if (qhat < 10000000 /* RADIX */) { | ||
if (qhat < 10000000 /* Constants.RADIX */) { | ||
var z = qhat * v[n - 2]; | ||
hi = (z / 10000000 /* RADIX */) | 0; | ||
lo = z - hi * 10000000 /* RADIX */; | ||
hi = (z / 10000000 /* Constants.RADIX */) | 0; | ||
lo = z - hi * 10000000 /* Constants.RADIX */; | ||
if (hi <= rhat) { | ||
@@ -176,3 +176,3 @@ if (hi !== rhat || lo <= u[j + n - 2]) { | ||
rhat += v[n - 1]; | ||
if (rhat >= 10000000 /* RADIX */) { | ||
if (rhat >= 10000000 /* Constants.RADIX */) { | ||
break; | ||
@@ -187,8 +187,8 @@ } | ||
p = qhat * v[i] + k; | ||
hi = (p / 10000000 /* RADIX */) | 0; | ||
lo = p - hi * 10000000 /* RADIX */; | ||
hi = (p / 10000000 /* Constants.RADIX */) | 0; | ||
lo = p - hi * 10000000 /* Constants.RADIX */; | ||
// Subtract and determine carry. | ||
var x = u[i + j] - lo; | ||
k = x < 0 ? 1 : 0; | ||
u[i + j] = k ? x + 10000000 /* RADIX */ : x; | ||
u[i + j] = k ? x + 10000000 /* Constants.RADIX */ : x; | ||
k += hi; | ||
@@ -212,3 +212,3 @@ } | ||
for (var i = n - 1; i >= 0; i--) { | ||
p = u[i] + k * 10000000 /* RADIX */; | ||
p = u[i] + k * 10000000 /* Constants.RADIX */; | ||
r[i] = (p / d) | 0; | ||
@@ -230,3 +230,3 @@ k = p - r[i] * d; | ||
for (var i = n - 1; i >= 0; i--) { | ||
var p = u[i] + r * 10000000 /* RADIX */; | ||
var p = u[i] + r * 10000000 /* Constants.RADIX */; | ||
q[i] = (p / v) | 0; | ||
@@ -246,4 +246,4 @@ r = p - q[i] * v; | ||
s = u[i + j] + (v[i] + k); | ||
k = s >= 10000000 /* RADIX */ ? 1 : 0; | ||
u[i + j] = k ? s - 10000000 /* RADIX */ : s; | ||
k = s >= 10000000 /* Constants.RADIX */ ? 1 : 0; | ||
u[i + j] = k ? s - 10000000 /* Constants.RADIX */ : s; | ||
i++; | ||
@@ -253,4 +253,4 @@ } | ||
s = u[i + j] + k; | ||
k = s === 10000000 /* RADIX */ ? 1 : /* istanbul ignore next */ 0; | ||
u[i + j] = k === 1 ? s - 10000000 /* RADIX */ : /* istanbul ignore next */ s; | ||
k = s === 10000000 /* Constants.RADIX */ ? 1 : /* istanbul ignore next */ 0; | ||
u[i + j] = k === 1 ? s - 10000000 /* Constants.RADIX */ : /* istanbul ignore next */ s; | ||
i++; | ||
@@ -257,0 +257,0 @@ } |
@@ -9,3 +9,3 @@ import { DivMod } from './math'; | ||
var m = b.length; | ||
var _c = div.word(shift, 7 /* RDIGITS */), q = _c[0], r = _c[1]; | ||
var _c = div.word(shift, 7 /* Constants.RDIGITS */), q = _c[0], r = _c[1]; | ||
if (r === 0) { | ||
@@ -27,3 +27,3 @@ while (--m >= 0) { | ||
--n; | ||
_a = div.pow10(b[m--], 7 /* RDIGITS */ - r), hi = _a[0], loprev = _a[1]; | ||
_a = div.pow10(b[m--], 7 /* Constants.RDIGITS */ - r), hi = _a[0], loprev = _a[1]; | ||
if (hi !== 0) { | ||
@@ -38,3 +38,3 @@ c = cmp(a[n], hi); | ||
for (; m >= 0; m--, n--) { | ||
_b = div.pow10(b[m], 7 /* RDIGITS */ - r), hi = _b[0], lo = _b[1]; | ||
_b = div.pow10(b[m], 7 /* Constants.RDIGITS */ - r), hi = _b[0], lo = _b[1]; | ||
x = ph * loprev + hi; | ||
@@ -69,13 +69,13 @@ c = cmp(a[n], x); | ||
export var digitCount = function (w) { | ||
if (w < 10000 /* P4 */) { | ||
if (w < 100 /* P2 */) { | ||
return w < 10 /* P1 */ ? 1 : 2; | ||
if (w < 10000 /* Constants.P4 */) { | ||
if (w < 100 /* Constants.P2 */) { | ||
return w < 10 /* Constants.P1 */ ? 1 : 2; | ||
} | ||
return w < 1000 /* P3 */ ? 3 : 4; | ||
return w < 1000 /* Constants.P3 */ ? 3 : 4; | ||
} | ||
if (w < 1000000 /* P6 */) { | ||
return w < 100000 /* P5 */ ? 5 : 6; | ||
if (w < 1000000 /* Constants.P6 */) { | ||
return w < 100000 /* Constants.P5 */ ? 5 : 6; | ||
} | ||
return w < 10000000 /* P7 */ ? 7 : 8; | ||
return w < 10000000 /* Constants.P7 */ ? 7 : 8; | ||
}; | ||
//# sourceMappingURL=operations.js.map |
export var POWERS10 = [ | ||
1 /* P0 */, | ||
10 /* P1 */, | ||
100 /* P2 */, | ||
1000 /* P3 */, | ||
10000 /* P4 */, | ||
100000 /* P5 */, | ||
1000000 /* P6 */, | ||
10000000 /* P7 */, | ||
100000000 /* P8 */, | ||
1 /* Constants.P0 */, | ||
10 /* Constants.P1 */, | ||
100 /* Constants.P2 */, | ||
1000 /* Constants.P3 */, | ||
10000 /* Constants.P4 */, | ||
100000 /* Constants.P5 */, | ||
1000000 /* Constants.P6 */, | ||
10000000 /* Constants.P7 */, | ||
100000000 /* Constants.P8 */, | ||
]; | ||
//# sourceMappingURL=types.js.map |
@@ -56,4 +56,4 @@ "use strict"; | ||
var size = function (n) { | ||
var q = (n / 7 /* RDIGITS */) | 0; | ||
var r = n - q * 7 /* RDIGITS */; | ||
var q = (n / 7 /* Constants.RDIGITS */) | 0; | ||
var r = n - q * 7 /* Constants.RDIGITS */; | ||
return r === 0 ? q : q + 1; | ||
@@ -71,3 +71,3 @@ }; | ||
this._exp = 0; | ||
this.flag = 0 /* NONE */; | ||
this.flag = 0 /* DecimalFlag.NONE */; | ||
if (typeof num === 'string' || typeof num === 'number') { | ||
@@ -93,3 +93,3 @@ this.parse(num); | ||
Decimal.prototype.isNaN = function () { | ||
return this.flag === 1 /* NAN */; | ||
return this.flag === 1 /* DecimalFlag.NAN */; | ||
}; | ||
@@ -106,3 +106,3 @@ /** | ||
Decimal.prototype.isInfinity = function () { | ||
return this.flag === 2 /* INFINITY */; | ||
return this.flag === 2 /* DecimalFlag.INFINITY */; | ||
}; | ||
@@ -126,3 +126,3 @@ /** | ||
// NAN is never equal to itself or any other value | ||
if (u.flag === 1 /* NAN */ || v.flag === 1 /* NAN */) { | ||
if (u.flag === 1 /* DecimalFlag.NAN */ || v.flag === 1 /* DecimalFlag.NAN */) { | ||
return -1; | ||
@@ -137,3 +137,3 @@ } | ||
// Positive infinity after all other values | ||
return u.flag === 2 /* INFINITY */ ? (u.sign === -1 ? -1 : 1) : v.sign === -1 ? 1 : -1; | ||
return u.flag === 2 /* DecimalFlag.INFINITY */ ? (u.sign === -1 ? -1 : 1) : v.sign === -1 ? 1 : -1; | ||
} | ||
@@ -238,3 +238,3 @@ u = u.stripTrailingZeros(); | ||
v = (0, exports.coerceDecimal)(v); | ||
var r = this.handleFlags(0 /* ADDITION */, v); | ||
var r = this.handleFlags(0 /* Op.ADDITION */, v); | ||
if (r === undefined) { | ||
@@ -253,3 +253,3 @@ if (this.isZero()) { | ||
v = (0, exports.coerceDecimal)(v); | ||
var r = this.handleFlags(1 /* SUBTRACTION */, v); | ||
var r = this.handleFlags(1 /* Op.SUBTRACTION */, v); | ||
if (r === undefined) { | ||
@@ -269,3 +269,3 @@ if (this.isZero()) { | ||
v = (0, exports.coerceDecimal)(v); | ||
var r = this.handleFlags(2 /* MULTIPLICATION */, v); | ||
var r = this.handleFlags(2 /* Op.MULTIPLICATION */, v); | ||
if (r !== undefined) { | ||
@@ -306,3 +306,3 @@ return r; | ||
v = (0, exports.coerceDecimal)(v); | ||
var r = this.handleFlags(3 /* DIVISION */, v); | ||
var r = this.handleFlags(3 /* Op.DIVISION */, v); | ||
if (r !== undefined) { | ||
@@ -356,5 +356,5 @@ return r; | ||
v = (0, exports.coerceDecimal)(v); | ||
var rq = this.handleFlags(3 /* DIVISION */, v); | ||
var rq = this.handleFlags(3 /* Op.DIVISION */, v); | ||
if (rq !== undefined) { | ||
var rm = this.handleFlags(4 /* MOD */, v); | ||
var rm = this.handleFlags(4 /* Op.MOD */, v); | ||
return [rq, rm]; | ||
@@ -398,3 +398,3 @@ } | ||
v = (0, exports.coerceDecimal)(v); | ||
var r = this.handleFlags(4 /* MOD */, v); | ||
var r = this.handleFlags(4 /* Op.MOD */, v); | ||
return r === undefined ? this.divmod(v)[1] : r; | ||
@@ -415,3 +415,3 @@ }; | ||
var n = d[i]; | ||
r = i * 7 /* RDIGITS */; | ||
r = i * 7 /* Constants.RDIGITS */; | ||
while (n % 10 === 0) { | ||
@@ -460,3 +460,3 @@ n /= 10 | 0; | ||
var len = this.data.length; | ||
return (len - 1) * 7 /* RDIGITS */ + (0, operations_1.digitCount)(this.data[len - 1]); | ||
return (len - 1) * 7 /* Constants.RDIGITS */ + (0, operations_1.digitCount)(this.data[len - 1]); | ||
}; | ||
@@ -658,3 +658,3 @@ /** | ||
var d = this.data[i]; | ||
var c = i === last ? (0, operations_1.digitCount)(d) : 7 /* RDIGITS */; | ||
var c = i === last ? (0, operations_1.digitCount)(d) : 7 /* Constants.RDIGITS */; | ||
// Loop over the decimal digits | ||
@@ -705,5 +705,5 @@ for (var j = 0; j < c; j++) { | ||
switch (this.flag) { | ||
case 1 /* NAN */: | ||
case 1 /* DecimalFlag.NAN */: | ||
return 'NaN'; | ||
case 2 /* INFINITY */: | ||
case 2 /* DecimalFlag.INFINITY */: | ||
default: | ||
@@ -715,5 +715,5 @@ return this.sign === 1 ? 'Infinity' : '-Infinity'; | ||
switch (this.flag) { | ||
case 1 /* NAN */: | ||
case 1 /* DecimalFlag.NAN */: | ||
return [{ type: 'nan', value: 'NaN' }]; | ||
case 2 /* INFINITY */: | ||
case 2 /* DecimalFlag.INFINITY */: | ||
default: | ||
@@ -758,11 +758,11 @@ var s = this.sign === 1 ? 'Infinity' : '-Infinity'; | ||
// Any operation involving a NAN returns a NAN | ||
if (uflag === 1 /* NAN */ || vflag === 1 /* NAN */) { | ||
if (uflag === 1 /* DecimalFlag.NAN */ || vflag === 1 /* DecimalFlag.NAN */) { | ||
return NAN; | ||
} | ||
var uinf = uflag === 2 /* INFINITY */; | ||
var vinf = vflag === 2 /* INFINITY */; | ||
var uinf = uflag === 2 /* DecimalFlag.INFINITY */; | ||
var vinf = vflag === 2 /* DecimalFlag.INFINITY */; | ||
var uzero = u.isZero(); | ||
var vzero = v.isZero(); | ||
switch (op) { | ||
case 0 /* ADDITION */: | ||
case 0 /* Op.ADDITION */: | ||
if (uinf && vinf) { | ||
@@ -775,3 +775,3 @@ return u.sign === v.sign ? (u.sign === 1 ? POSITIVE_INFINITY : NEGATIVE_INFINITY) : NAN; | ||
break; | ||
case 1 /* SUBTRACTION */: | ||
case 1 /* Op.SUBTRACTION */: | ||
if (uinf && vinf) { | ||
@@ -790,3 +790,3 @@ return u.sign === v.sign ? NAN : u.sign === 1 ? POSITIVE_INFINITY : NEGATIVE_INFINITY; | ||
break; | ||
case 2 /* MULTIPLICATION */: | ||
case 2 /* Op.MULTIPLICATION */: | ||
if (uinf) { | ||
@@ -799,3 +799,3 @@ return vzero ? NAN : u.sign === v.sign ? POSITIVE_INFINITY : NEGATIVE_INFINITY; | ||
break; | ||
case 3 /* DIVISION */: | ||
case 3 /* Op.DIVISION */: | ||
if (uinf && vinf) { | ||
@@ -820,3 +820,3 @@ return NAN; | ||
break; | ||
case 4 /* MOD */: | ||
case 4 /* Op.MOD */: | ||
if (uinf || vzero) { | ||
@@ -851,4 +851,4 @@ return NAN; | ||
// Compute the shift in terms of our radix. | ||
var q = (shift / 7 /* RDIGITS */) | 0; | ||
var r = shift - q * 7 /* RDIGITS */; | ||
var q = (shift / 7 /* Constants.RDIGITS */) | 0; | ||
var r = shift - q * 7 /* Constants.RDIGITS */; | ||
// Expand w to hold shifted result and zero all elements. | ||
@@ -867,3 +867,3 @@ var n = size(prec + shift); | ||
var powlo = types_1.POWERS10[r]; | ||
var powhi = types_1.POWERS10[7 /* RDIGITS */ - r]; | ||
var powhi = types_1.POWERS10[7 /* Constants.RDIGITS */ - r]; | ||
var hi = 0; | ||
@@ -916,3 +916,3 @@ var lo = 0; | ||
var div = new math_1.DivMod(); | ||
var _d = div.word(shift, 7 /* RDIGITS */), q = _d[0], r = _d[1]; | ||
var _d = div.word(shift, 7 /* Constants.RDIGITS */), q = _d[0], r = _d[1]; | ||
var data = w.data.slice(); | ||
@@ -925,3 +925,3 @@ w.data.fill(0); | ||
// q is always non-zero here, else there would be no shift | ||
_a = div.pow10(data[q - 1], 7 /* RDIGITS */ - 1), rnd = _a[0], rest = _a[1]; | ||
_a = div.pow10(data[q - 1], 7 /* Constants.RDIGITS */ - 1), rnd = _a[0], rest = _a[1]; | ||
if (rest === 0) { | ||
@@ -936,3 +936,3 @@ rest = (0, operations_1.allzero)(data, q - 1) === 0 ? 1 : 0; | ||
var hiprev = 0; | ||
var ph = types_1.POWERS10[7 /* RDIGITS */ - r]; | ||
var ph = types_1.POWERS10[7 /* Constants.RDIGITS */ - r]; | ||
// q is always < data.length here; otherwise r == 0 | ||
@@ -1002,3 +1002,3 @@ _b = div.pow10(data[q], r), hiprev = _b[0], rest = _b[1]; | ||
s = d[i] + k; | ||
k = s === 10000000 /* RADIX */ ? 1 : 0; | ||
k = s === 10000000 /* Constants.RADIX */ ? 1 : 0; | ||
d[i] = k ? 0 : s; | ||
@@ -1098,7 +1098,7 @@ } | ||
if (isNaN(arg)) { | ||
this.flag = 1 /* NAN */; | ||
this.flag = 1 /* DecimalFlag.NAN */; | ||
return; | ||
} | ||
if (!isFinite(arg)) { | ||
this.flag = 2 /* INFINITY */; | ||
this.flag = 2 /* DecimalFlag.INFINITY */; | ||
this.sign = arg === Infinity ? 1 : -1; | ||
@@ -1125,7 +1125,7 @@ return; | ||
if (NAN_VALUES.has(str)) { | ||
this.flag = 1 /* NAN */; | ||
this.flag = 1 /* DecimalFlag.NAN */; | ||
return; | ||
} | ||
if (POS_INFINITY.has(str)) { | ||
this.flag = 2 /* INFINITY */; | ||
this.flag = 2 /* DecimalFlag.INFINITY */; | ||
this.sign = 1; | ||
@@ -1135,3 +1135,3 @@ return; | ||
if (NEG_INFINITY.has(str)) { | ||
this.flag = 2 /* INFINITY */; | ||
this.flag = 2 /* DecimalFlag.INFINITY */; | ||
this.sign = -1; | ||
@@ -1160,5 +1160,5 @@ return; | ||
switch (code) { | ||
case 69 /* ELOWER */: | ||
case 101 /* EUPPER */: | ||
if (flags & 4 /* EXP */) { | ||
case 69 /* Chars.ELOWER */: | ||
case 101 /* Chars.EUPPER */: | ||
if (flags & 4 /* ParseFlags.EXP */) { | ||
return "Extra exponent character at ".concat(i); | ||
@@ -1174,4 +1174,4 @@ } | ||
// Indicate we have an exponent, and clear the sign flag. | ||
flags |= 4 /* EXP */; | ||
flags &= ~1 /* SIGN */; | ||
flags |= 4 /* ParseFlags.EXP */; | ||
flags &= ~1 /* ParseFlags.SIGN */; | ||
// Copy the parsed number to the exponent and reset the digit count. | ||
@@ -1184,34 +1184,34 @@ dig = 0; | ||
break; | ||
case 45 /* MINUS */: | ||
case 43 /* PLUS */: | ||
case 45 /* Chars.MINUS */: | ||
case 43 /* Chars.PLUS */: | ||
if (dig === 0) { | ||
return 'Found a bare sign symbol'; | ||
} | ||
if (flags & 1 /* SIGN */) { | ||
if (flags & 1 /* ParseFlags.SIGN */) { | ||
return "Duplicate sign character at ".concat(i); | ||
} | ||
sign = code === 45 /* MINUS */ ? -1 : 1; | ||
flags |= 1 /* SIGN */; | ||
sign = code === 45 /* Chars.MINUS */ ? -1 : 1; | ||
flags |= 1 /* ParseFlags.SIGN */; | ||
break; | ||
case 46 /* DOT */: | ||
if (flags & 2 /* POINT */) { | ||
case 46 /* Chars.DOT */: | ||
if (flags & 2 /* ParseFlags.POINT */) { | ||
return "Extra radix point seen at ".concat(i); | ||
} | ||
flags |= 2 /* POINT */; | ||
flags |= 2 /* ParseFlags.POINT */; | ||
exp -= dig; | ||
break; | ||
case 48 /* DIGIT0 */: | ||
case 49 /* DIGIT1 */: | ||
case 50 /* DIGIT2 */: | ||
case 51 /* DIGIT3 */: | ||
case 52 /* DIGIT4 */: | ||
case 53 /* DIGIT5 */: | ||
case 54 /* DIGIT6 */: | ||
case 55 /* DIGIT7 */: | ||
case 56 /* DIGIT8 */: | ||
case 57 /* DIGIT9 */: | ||
n += (code - 48 /* DIGIT0 */) * types_1.POWERS10[z]; | ||
case 48 /* Chars.DIGIT0 */: | ||
case 49 /* Chars.DIGIT1 */: | ||
case 50 /* Chars.DIGIT2 */: | ||
case 51 /* Chars.DIGIT3 */: | ||
case 52 /* Chars.DIGIT4 */: | ||
case 53 /* Chars.DIGIT5 */: | ||
case 54 /* Chars.DIGIT6 */: | ||
case 55 /* Chars.DIGIT7 */: | ||
case 56 /* Chars.DIGIT8 */: | ||
case 57 /* Chars.DIGIT9 */: | ||
n += (code - 48 /* Chars.DIGIT0 */) * types_1.POWERS10[z]; | ||
z++; | ||
dig++; | ||
if (z === 7 /* RDIGITS */) { | ||
if (z === 7 /* Constants.RDIGITS */) { | ||
data.push(n); | ||
@@ -1218,0 +1218,0 @@ n = 0; |
@@ -22,5 +22,5 @@ "use strict"; | ||
var z = u[j] + vj + k; | ||
w[j] = z % 10000000 /* RADIX */; | ||
w[j] = z % 10000000 /* Constants.RADIX */; | ||
// .. k is being set to 1 or 0, to carry | ||
k = (z / 10000000 /* RADIX */) | 0; | ||
k = (z / 10000000 /* Constants.RADIX */) | 0; | ||
// A3. Loop on j | ||
@@ -50,3 +50,3 @@ j++; | ||
var z = u[j] - v[j] - k; | ||
w[j] = z < 0 ? z + 10000000 /* RADIX */ : z; | ||
w[j] = z < 0 ? z + 10000000 /* Constants.RADIX */ : z; | ||
// k is set to 1 or 0, indicating a borrow | ||
@@ -60,3 +60,3 @@ k = z < 0 ? 1 : 0; | ||
var z = u[j] - k; | ||
w[j] = z < 0 ? z + 10000000 /* RADIX */ : z; | ||
w[j] = z < 0 ? z + 10000000 /* Constants.RADIX */ : z; | ||
k = z < 0 ? 1 : 0; | ||
@@ -94,4 +94,4 @@ j++; | ||
var p = k + w[i + j] + u[i] * v[j]; | ||
k = (p / 10000000 /* RADIX */) | 0; | ||
w[i + j] = p - k * 10000000 /* RADIX */; | ||
k = (p / 10000000 /* Constants.RADIX */) | 0; | ||
w[i + j] = p - k * 10000000 /* Constants.RADIX */; | ||
// M5. Loop on i | ||
@@ -117,4 +117,4 @@ i++; | ||
var p = k + u[i] * v; | ||
k = (p / 10000000 /* RADIX */) | 0; | ||
w[i] = p - k * 10000000 /* RADIX */; | ||
k = (p / 10000000 /* Constants.RADIX */) | 0; | ||
w[i] = p - k * 10000000 /* Constants.RADIX */; | ||
} | ||
@@ -150,3 +150,3 @@ if (k > 0) { | ||
// D1. Normalize | ||
var d = (10000000 /* RADIX */ / (v[n - 1] + 1)) | 0; | ||
var d = (10000000 /* Constants.RADIX */ / (v[n - 1] + 1)) | 0; | ||
if (d !== 1) { | ||
@@ -163,3 +163,3 @@ (0, exports.multiplyword)(u, uc, nplusm, d); | ||
// D3. Calculate q̂ and r̂. | ||
p = u[j + n - 1] + u[j + n] * 10000000 /* RADIX */; | ||
p = u[j + n - 1] + u[j + n] * 10000000 /* Constants.RADIX */; | ||
var qhat = (p / v[n - 1]) | 0; | ||
@@ -169,6 +169,6 @@ var rhat = p - qhat * v[n - 1]; | ||
// D3. Test if q̂ = radix ... | ||
if (qhat < 10000000 /* RADIX */) { | ||
if (qhat < 10000000 /* Constants.RADIX */) { | ||
var z = qhat * v[n - 2]; | ||
hi = (z / 10000000 /* RADIX */) | 0; | ||
lo = z - hi * 10000000 /* RADIX */; | ||
hi = (z / 10000000 /* Constants.RADIX */) | 0; | ||
lo = z - hi * 10000000 /* Constants.RADIX */; | ||
if (hi <= rhat) { | ||
@@ -183,3 +183,3 @@ if (hi !== rhat || lo <= u[j + n - 2]) { | ||
rhat += v[n - 1]; | ||
if (rhat >= 10000000 /* RADIX */) { | ||
if (rhat >= 10000000 /* Constants.RADIX */) { | ||
break; | ||
@@ -194,8 +194,8 @@ } | ||
p = qhat * v[i] + k; | ||
hi = (p / 10000000 /* RADIX */) | 0; | ||
lo = p - hi * 10000000 /* RADIX */; | ||
hi = (p / 10000000 /* Constants.RADIX */) | 0; | ||
lo = p - hi * 10000000 /* Constants.RADIX */; | ||
// Subtract and determine carry. | ||
var x = u[i + j] - lo; | ||
k = x < 0 ? 1 : 0; | ||
u[i + j] = k ? x + 10000000 /* RADIX */ : x; | ||
u[i + j] = k ? x + 10000000 /* Constants.RADIX */ : x; | ||
k += hi; | ||
@@ -219,3 +219,3 @@ } | ||
for (var i = n - 1; i >= 0; i--) { | ||
p = u[i] + k * 10000000 /* RADIX */; | ||
p = u[i] + k * 10000000 /* Constants.RADIX */; | ||
r[i] = (p / d) | 0; | ||
@@ -238,3 +238,3 @@ k = p - r[i] * d; | ||
for (var i = n - 1; i >= 0; i--) { | ||
var p = u[i] + r * 10000000 /* RADIX */; | ||
var p = u[i] + r * 10000000 /* Constants.RADIX */; | ||
q[i] = (p / v) | 0; | ||
@@ -254,4 +254,4 @@ r = p - q[i] * v; | ||
s = u[i + j] + (v[i] + k); | ||
k = s >= 10000000 /* RADIX */ ? 1 : 0; | ||
u[i + j] = k ? s - 10000000 /* RADIX */ : s; | ||
k = s >= 10000000 /* Constants.RADIX */ ? 1 : 0; | ||
u[i + j] = k ? s - 10000000 /* Constants.RADIX */ : s; | ||
i++; | ||
@@ -261,4 +261,4 @@ } | ||
s = u[i + j] + k; | ||
k = s === 10000000 /* RADIX */ ? 1 : /* istanbul ignore next */ 0; | ||
u[i + j] = k === 1 ? s - 10000000 /* RADIX */ : /* istanbul ignore next */ s; | ||
k = s === 10000000 /* Constants.RADIX */ ? 1 : /* istanbul ignore next */ 0; | ||
u[i + j] = k === 1 ? s - 10000000 /* Constants.RADIX */ : /* istanbul ignore next */ s; | ||
i++; | ||
@@ -265,0 +265,0 @@ } |
@@ -12,3 +12,3 @@ "use strict"; | ||
var m = b.length; | ||
var _c = div.word(shift, 7 /* RDIGITS */), q = _c[0], r = _c[1]; | ||
var _c = div.word(shift, 7 /* Constants.RDIGITS */), q = _c[0], r = _c[1]; | ||
if (r === 0) { | ||
@@ -30,3 +30,3 @@ while (--m >= 0) { | ||
--n; | ||
_a = div.pow10(b[m--], 7 /* RDIGITS */ - r), hi = _a[0], loprev = _a[1]; | ||
_a = div.pow10(b[m--], 7 /* Constants.RDIGITS */ - r), hi = _a[0], loprev = _a[1]; | ||
if (hi !== 0) { | ||
@@ -41,3 +41,3 @@ c = cmp(a[n], hi); | ||
for (; m >= 0; m--, n--) { | ||
_b = div.pow10(b[m], 7 /* RDIGITS */ - r), hi = _b[0], lo = _b[1]; | ||
_b = div.pow10(b[m], 7 /* Constants.RDIGITS */ - r), hi = _b[0], lo = _b[1]; | ||
x = ph * loprev + hi; | ||
@@ -74,14 +74,14 @@ c = cmp(a[n], x); | ||
var digitCount = function (w) { | ||
if (w < 10000 /* P4 */) { | ||
if (w < 100 /* P2 */) { | ||
return w < 10 /* P1 */ ? 1 : 2; | ||
if (w < 10000 /* Constants.P4 */) { | ||
if (w < 100 /* Constants.P2 */) { | ||
return w < 10 /* Constants.P1 */ ? 1 : 2; | ||
} | ||
return w < 1000 /* P3 */ ? 3 : 4; | ||
return w < 1000 /* Constants.P3 */ ? 3 : 4; | ||
} | ||
if (w < 1000000 /* P6 */) { | ||
return w < 100000 /* P5 */ ? 5 : 6; | ||
if (w < 1000000 /* Constants.P6 */) { | ||
return w < 100000 /* Constants.P5 */ ? 5 : 6; | ||
} | ||
return w < 10000000 /* P7 */ ? 7 : 8; | ||
return w < 10000000 /* Constants.P7 */ ? 7 : 8; | ||
}; | ||
exports.digitCount = digitCount; | ||
//# sourceMappingURL=operations.js.map |
@@ -5,12 +5,12 @@ "use strict"; | ||
exports.POWERS10 = [ | ||
1 /* P0 */, | ||
10 /* P1 */, | ||
100 /* P2 */, | ||
1000 /* P3 */, | ||
10000 /* P4 */, | ||
100000 /* P5 */, | ||
1000000 /* P6 */, | ||
10000000 /* P7 */, | ||
100000000 /* P8 */, | ||
1 /* Constants.P0 */, | ||
10 /* Constants.P1 */, | ||
100 /* Constants.P2 */, | ||
1000 /* Constants.P3 */, | ||
10000 /* Constants.P4 */, | ||
100000 /* Constants.P5 */, | ||
1000000 /* Constants.P6 */, | ||
10000000 /* Constants.P7 */, | ||
100000000 /* Constants.P8 */, | ||
]; | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@phensley/decimal", | ||
"version": "1.5.2", | ||
"version": "1.6.0", | ||
"description": "Arbitrary precision decimal math", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
371440