@phensley/decimal
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -128,5 +128,3 @@ import { add, divide, multiply, subtract, trimLeadingZeros, DivMod } from './math'; | ||
// 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 /* INFINITY */ ? (u.sign === -1 ? -1 : 1) : v.sign === -1 ? 1 : -1; | ||
} | ||
@@ -212,3 +210,3 @@ u = u.stripTrailingZeros(); | ||
} | ||
return (this._exp + this.trailingZeros()) >= 0; | ||
return this._exp + this.trailingZeros() >= 0; | ||
}; | ||
@@ -268,3 +266,3 @@ /** | ||
w.sign = u.sign === v.sign ? 1 : -1; | ||
w._exp = (u._exp + v._exp); | ||
w._exp = u._exp + v._exp; | ||
var uz = u.isZero(); | ||
@@ -307,5 +305,5 @@ var vz = v.isZero(); | ||
var shift = usePrecision | ||
? (v.precision() - u.precision()) + scaleprec + 2 | ||
? v.precision() - u.precision() + scaleprec + 2 | ||
: v.precision() + u.precision() + Math.abs(scaleprec) + 2; | ||
var exp = (u._exp - v._exp) - shift; | ||
var exp = u._exp - v._exp - shift; | ||
if (shift > 0) { | ||
@@ -439,6 +437,3 @@ u = u.shiftleft(shift); | ||
var coeff = Decimal.fromRaw(this.sign, exp === 0 ? 0 : exp, this.data, this.flag); | ||
return [ | ||
coeff, | ||
this._exp - coeff._exp | ||
]; | ||
return [coeff, this._exp - coeff._exp]; | ||
}; | ||
@@ -453,3 +448,3 @@ /** | ||
var len = this.data.length; | ||
return ((len - 1) * 7 /* RDIGITS */) + digitCount(this.data[len - 1]); | ||
return (len - 1) * 7 /* RDIGITS */ + digitCount(this.data[len - 1]); | ||
}; | ||
@@ -486,3 +481,3 @@ /** | ||
Decimal.prototype.alignexp = function () { | ||
return this.flag ? 0 : (this._exp + this.precision()) - 1; | ||
return this.flag ? 0 : this._exp + this.precision() - 1; | ||
}; | ||
@@ -582,9 +577,4 @@ /** | ||
} | ||
var sign = exp < 0 ? | ||
{ type: 'minus', value: '-' } : { type: 'plus', value: '+' }; | ||
return r.concat([ | ||
{ type: 'exp', value: 'E' }, | ||
sign, | ||
{ type: 'integer', value: "" + Math.abs(exp) } | ||
]); | ||
var sign = exp < 0 ? { type: 'minus', value: '-' } : { type: 'plus', value: '+' }; | ||
return r.concat([{ type: 'exp', value: 'E' }, sign, { type: 'integer', value: "" + Math.abs(exp) }]); | ||
}; | ||
@@ -605,3 +595,3 @@ /** | ||
// larger than the integer coefficient we emit leading zeros. | ||
var int = (this.data.length === 1 && this.data[0] === 0) ? 1 : this.precision() + exp; | ||
var int = this.data.length === 1 && this.data[0] === 0 ? 1 : this.precision() + exp; | ||
if (minInt <= 0 && this.compare(ONE, true) === -1) { | ||
@@ -777,4 +767,9 @@ // If the number is between 0 and 1 and format requested minimum | ||
else if (uinf || vinf) { | ||
return uinf ? (u.sign === 1 ? POSITIVE_INFINITY : NEGATIVE_INFINITY) | ||
: v.sign === 1 ? NEGATIVE_INFINITY : POSITIVE_INFINITY; | ||
return uinf | ||
? u.sign === 1 | ||
? POSITIVE_INFINITY | ||
: NEGATIVE_INFINITY | ||
: v.sign === 1 | ||
? NEGATIVE_INFINITY | ||
: POSITIVE_INFINITY; | ||
} | ||
@@ -795,4 +790,9 @@ break; | ||
if (uinf) { | ||
return vzero ? (u.sign === 1 ? POSITIVE_INFINITY : NEGATIVE_INFINITY) : | ||
u.sign === v.sign ? POSITIVE_INFINITY : NEGATIVE_INFINITY; | ||
return vzero | ||
? u.sign === 1 | ||
? POSITIVE_INFINITY | ||
: NEGATIVE_INFINITY | ||
: u.sign === v.sign | ||
? POSITIVE_INFINITY | ||
: NEGATIVE_INFINITY; | ||
} | ||
@@ -813,3 +813,3 @@ if (vinf) { | ||
} | ||
if (uzero && (!vzero && !vinf)) { | ||
if (uzero && !vzero && !vinf) { | ||
return u; | ||
@@ -1018,3 +1018,3 @@ } | ||
// if n = 5 and digit to left of n is odd round up; if even round down | ||
return Number((rnd > 5) || ((rnd === 5 && this.isodd()))); | ||
return Number(rnd > 5 || (rnd === 5 && this.isodd())); | ||
default: | ||
@@ -1028,3 +1028,3 @@ return 0; | ||
Decimal.prototype.isodd = function () { | ||
return this.data.length > 0 && (this.data[0] % 2 === 1); | ||
return this.data.length > 0 && this.data[0] % 2 === 1; | ||
}; | ||
@@ -1220,7 +1220,5 @@ /** | ||
// 105 digits of pi - https://oeis.org/A000796/constant | ||
var PI = new Decimal('3.141592653589793238462643383279502884197169399375105' + | ||
'82097494459230781640628620899862803482534211706798214'); | ||
var PI = new Decimal('3.141592653589793238462643383279502884197169399375105' + '82097494459230781640628620899862803482534211706798214'); | ||
// 105 digits of e - https://oeis.org/A001113/constant | ||
var E = new Decimal('2.718281828459045235360287471352662497757247093699959' + | ||
'57496696762772407663035354759457138217852516642742746'); | ||
var E = new Decimal('2.718281828459045235360287471352662497757247093699959' + '57496696762772407663035354759457138217852516642742746'); | ||
var NAN = new Decimal(NaN); | ||
@@ -1242,4 +1240,4 @@ var NEGATIVE_INFINITY = new Decimal(-Infinity); | ||
POSITIVE_INFINITY: POSITIVE_INFINITY, | ||
NEGATIVE_INFINITY: NEGATIVE_INFINITY | ||
NEGATIVE_INFINITY: NEGATIVE_INFINITY, | ||
}; | ||
//# sourceMappingURL=decimal.js.map |
@@ -85,3 +85,3 @@ import { POWERS10 } from './types'; | ||
// M4. Multiply and add | ||
var p = (k + w[i + j]) + u[i] * v[j]; | ||
var p = k + w[i + j] + u[i] * v[j]; | ||
k = (p / 10000000 /* RADIX */) | 0; | ||
@@ -107,3 +107,3 @@ w[i + j] = p - k * 10000000 /* RADIX */; | ||
for (i = 0; i < n; i++) { | ||
var p = (k + u[i] * v); | ||
var p = k + u[i] * v; | ||
k = (p / 10000000 /* RADIX */) | 0; | ||
@@ -152,3 +152,3 @@ w[i] = p - k * 10000000 /* RADIX */; | ||
// D3. Calculate q̂ and r̂. | ||
p = u[j + n - 1] + (u[j + n] * 10000000 /* RADIX */); | ||
p = u[j + n - 1] + u[j + n] * 10000000 /* RADIX */; | ||
var qhat = (p / v[n - 1]) | 0; | ||
@@ -205,3 +205,3 @@ var rhat = p - qhat * v[n - 1]; | ||
for (var i = n - 1; i >= 0; i--) { | ||
p = u[i] + (k * 10000000 /* RADIX */); | ||
p = u[i] + k * 10000000 /* RADIX */; | ||
r[i] = (p / d) | 0; | ||
@@ -223,3 +223,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 /* RADIX */; | ||
q[i] = (p / v) | 0; | ||
@@ -226,0 +226,0 @@ r = p - q[i] * v; |
import { DivMod } from './math'; | ||
import { POWERS10 } from './types'; | ||
var cmp = function (a, b) { return a < b ? -1 : a === b ? 0 : 1; }; | ||
var cmp = function (a, b) { return (a < b ? -1 : a === b ? 0 : 1); }; | ||
export var compare = function (a, b, shift) { | ||
@@ -5,0 +5,0 @@ var _a, _b; |
@@ -102,4 +102,4 @@ import { Decimal, DecimalConstants } from './decimal'; | ||
export var RationalConstants = { | ||
ONE: new Rational(1, 1) | ||
ONE: new Rational(1, 1), | ||
}; | ||
//# sourceMappingURL=rational.js.map |
@@ -10,4 +10,4 @@ export var POWERS10 = [ | ||
10000000 /* P7 */, | ||
100000000 /* P8 */ | ||
100000000 /* P8 */, | ||
]; | ||
//# sourceMappingURL=types.js.map |
@@ -130,5 +130,3 @@ "use strict"; | ||
// 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 /* INFINITY */ ? (u.sign === -1 ? -1 : 1) : v.sign === -1 ? 1 : -1; | ||
} | ||
@@ -214,3 +212,3 @@ u = u.stripTrailingZeros(); | ||
} | ||
return (this._exp + this.trailingZeros()) >= 0; | ||
return this._exp + this.trailingZeros() >= 0; | ||
}; | ||
@@ -270,3 +268,3 @@ /** | ||
w.sign = u.sign === v.sign ? 1 : -1; | ||
w._exp = (u._exp + v._exp); | ||
w._exp = u._exp + v._exp; | ||
var uz = u.isZero(); | ||
@@ -309,5 +307,5 @@ var vz = v.isZero(); | ||
var shift = usePrecision | ||
? (v.precision() - u.precision()) + scaleprec + 2 | ||
? v.precision() - u.precision() + scaleprec + 2 | ||
: v.precision() + u.precision() + Math.abs(scaleprec) + 2; | ||
var exp = (u._exp - v._exp) - shift; | ||
var exp = u._exp - v._exp - shift; | ||
if (shift > 0) { | ||
@@ -441,6 +439,3 @@ u = u.shiftleft(shift); | ||
var coeff = Decimal.fromRaw(this.sign, exp === 0 ? 0 : exp, this.data, this.flag); | ||
return [ | ||
coeff, | ||
this._exp - coeff._exp | ||
]; | ||
return [coeff, this._exp - coeff._exp]; | ||
}; | ||
@@ -455,3 +450,3 @@ /** | ||
var len = this.data.length; | ||
return ((len - 1) * 7 /* RDIGITS */) + operations_1.digitCount(this.data[len - 1]); | ||
return (len - 1) * 7 /* RDIGITS */ + operations_1.digitCount(this.data[len - 1]); | ||
}; | ||
@@ -488,3 +483,3 @@ /** | ||
Decimal.prototype.alignexp = function () { | ||
return this.flag ? 0 : (this._exp + this.precision()) - 1; | ||
return this.flag ? 0 : this._exp + this.precision() - 1; | ||
}; | ||
@@ -584,9 +579,4 @@ /** | ||
} | ||
var sign = exp < 0 ? | ||
{ type: 'minus', value: '-' } : { type: 'plus', value: '+' }; | ||
return r.concat([ | ||
{ type: 'exp', value: 'E' }, | ||
sign, | ||
{ type: 'integer', value: "" + Math.abs(exp) } | ||
]); | ||
var sign = exp < 0 ? { type: 'minus', value: '-' } : { type: 'plus', value: '+' }; | ||
return r.concat([{ type: 'exp', value: 'E' }, sign, { type: 'integer', value: "" + Math.abs(exp) }]); | ||
}; | ||
@@ -607,3 +597,3 @@ /** | ||
// larger than the integer coefficient we emit leading zeros. | ||
var int = (this.data.length === 1 && this.data[0] === 0) ? 1 : this.precision() + exp; | ||
var int = this.data.length === 1 && this.data[0] === 0 ? 1 : this.precision() + exp; | ||
if (minInt <= 0 && this.compare(ONE, true) === -1) { | ||
@@ -779,4 +769,9 @@ // If the number is between 0 and 1 and format requested minimum | ||
else if (uinf || vinf) { | ||
return uinf ? (u.sign === 1 ? POSITIVE_INFINITY : NEGATIVE_INFINITY) | ||
: v.sign === 1 ? NEGATIVE_INFINITY : POSITIVE_INFINITY; | ||
return uinf | ||
? u.sign === 1 | ||
? POSITIVE_INFINITY | ||
: NEGATIVE_INFINITY | ||
: v.sign === 1 | ||
? NEGATIVE_INFINITY | ||
: POSITIVE_INFINITY; | ||
} | ||
@@ -797,4 +792,9 @@ break; | ||
if (uinf) { | ||
return vzero ? (u.sign === 1 ? POSITIVE_INFINITY : NEGATIVE_INFINITY) : | ||
u.sign === v.sign ? POSITIVE_INFINITY : NEGATIVE_INFINITY; | ||
return vzero | ||
? u.sign === 1 | ||
? POSITIVE_INFINITY | ||
: NEGATIVE_INFINITY | ||
: u.sign === v.sign | ||
? POSITIVE_INFINITY | ||
: NEGATIVE_INFINITY; | ||
} | ||
@@ -815,3 +815,3 @@ if (vinf) { | ||
} | ||
if (uzero && (!vzero && !vinf)) { | ||
if (uzero && !vzero && !vinf) { | ||
return u; | ||
@@ -1020,3 +1020,3 @@ } | ||
// if n = 5 and digit to left of n is odd round up; if even round down | ||
return Number((rnd > 5) || ((rnd === 5 && this.isodd()))); | ||
return Number(rnd > 5 || (rnd === 5 && this.isodd())); | ||
default: | ||
@@ -1030,3 +1030,3 @@ return 0; | ||
Decimal.prototype.isodd = function () { | ||
return this.data.length > 0 && (this.data[0] % 2 === 1); | ||
return this.data.length > 0 && this.data[0] % 2 === 1; | ||
}; | ||
@@ -1222,7 +1222,5 @@ /** | ||
// 105 digits of pi - https://oeis.org/A000796/constant | ||
var PI = new Decimal('3.141592653589793238462643383279502884197169399375105' + | ||
'82097494459230781640628620899862803482534211706798214'); | ||
var PI = new Decimal('3.141592653589793238462643383279502884197169399375105' + '82097494459230781640628620899862803482534211706798214'); | ||
// 105 digits of e - https://oeis.org/A001113/constant | ||
var E = new Decimal('2.718281828459045235360287471352662497757247093699959' + | ||
'57496696762772407663035354759457138217852516642742746'); | ||
var E = new Decimal('2.718281828459045235360287471352662497757247093699959' + '57496696762772407663035354759457138217852516642742746'); | ||
var NAN = new Decimal(NaN); | ||
@@ -1244,4 +1242,4 @@ var NEGATIVE_INFINITY = new Decimal(-Infinity); | ||
POSITIVE_INFINITY: POSITIVE_INFINITY, | ||
NEGATIVE_INFINITY: NEGATIVE_INFINITY | ||
NEGATIVE_INFINITY: NEGATIVE_INFINITY, | ||
}; | ||
//# sourceMappingURL=decimal.js.map |
@@ -87,3 +87,3 @@ "use strict"; | ||
// M4. Multiply and add | ||
var p = (k + w[i + j]) + u[i] * v[j]; | ||
var p = k + w[i + j] + u[i] * v[j]; | ||
k = (p / 10000000 /* RADIX */) | 0; | ||
@@ -109,3 +109,3 @@ w[i + j] = p - k * 10000000 /* RADIX */; | ||
for (i = 0; i < n; i++) { | ||
var p = (k + u[i] * v); | ||
var p = k + u[i] * v; | ||
k = (p / 10000000 /* RADIX */) | 0; | ||
@@ -154,3 +154,3 @@ w[i] = p - k * 10000000 /* RADIX */; | ||
// D3. Calculate q̂ and r̂. | ||
p = u[j + n - 1] + (u[j + n] * 10000000 /* RADIX */); | ||
p = u[j + n - 1] + u[j + n] * 10000000 /* RADIX */; | ||
var qhat = (p / v[n - 1]) | 0; | ||
@@ -207,3 +207,3 @@ var rhat = p - qhat * v[n - 1]; | ||
for (var i = n - 1; i >= 0; i--) { | ||
p = u[i] + (k * 10000000 /* RADIX */); | ||
p = u[i] + k * 10000000 /* RADIX */; | ||
r[i] = (p / d) | 0; | ||
@@ -225,3 +225,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 /* RADIX */; | ||
q[i] = (p / v) | 0; | ||
@@ -228,0 +228,0 @@ r = p - q[i] * v; |
@@ -5,3 +5,3 @@ "use strict"; | ||
var types_1 = require("./types"); | ||
var cmp = function (a, b) { return a < b ? -1 : a === b ? 0 : 1; }; | ||
var cmp = function (a, b) { return (a < b ? -1 : a === b ? 0 : 1); }; | ||
exports.compare = function (a, b, shift) { | ||
@@ -8,0 +8,0 @@ var _a, _b; |
@@ -104,4 +104,4 @@ "use strict"; | ||
exports.RationalConstants = { | ||
ONE: new Rational(1, 1) | ||
ONE: new Rational(1, 1), | ||
}; | ||
//# sourceMappingURL=rational.js.map |
@@ -12,4 +12,4 @@ "use strict"; | ||
10000000 /* P7 */, | ||
100000000 /* P8 */ | ||
100000000 /* P8 */, | ||
]; | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@phensley/decimal", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Arbitrary precision decimal math", | ||
@@ -39,21 +39,21 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"tslib": "^1.11.1" | ||
"tslib": "^1.13.0" | ||
}, | ||
"devDependencies": { | ||
"@microsoft/api-extractor": "^7.7.13", | ||
"@microsoft/api-extractor": "^7.8.0", | ||
"@types/jest": "^25.2.1", | ||
"@types/node": "^13.13.4", | ||
"@typescript-eslint/eslint-plugin": "^2.30.0", | ||
"@typescript-eslint/parser": "^2.30.0", | ||
"@types/node": "^14.0.1", | ||
"@typescript-eslint/eslint-plugin": "^2.33.0", | ||
"@typescript-eslint/parser": "^2.33.0", | ||
"beautify-benchmark": "^0.2.4", | ||
"benchmark": "^2.1.4", | ||
"chalk": "^4.0.0", | ||
"eslint": "^6.8.0", | ||
"eslint": "^7.0.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-prettier": "^3.1.3", | ||
"jest": "^25.4.0", | ||
"jest": "^26.0.1", | ||
"prettier": "^2.0.5", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^25.4.0", | ||
"typescript": "^3.8.3" | ||
"ts-jest": "^25.5.1", | ||
"typescript": "~3.8.3" | ||
}, | ||
@@ -73,3 +73,3 @@ "jest": { | ||
}, | ||
"gitHead": "42b88fa1fa672c12a88dfe4fea152d1eb614e919" | ||
"gitHead": "b4e3308079a0bcb58a666cd94c248ffd452b2486" | ||
} |
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
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
260487
4579
Updatedtslib@^1.13.0