@phensley/decimal
Advanced tools
Comparing version 0.11.3-alpha.0 to 0.11.3
@@ -144,3 +144,3 @@ import { NumberOperands } from './operands'; | ||
*/ | ||
toScientificString(minIntegers: number): string; | ||
toScientificString(minIntegers?: number): string; | ||
/** | ||
@@ -158,4 +158,4 @@ * Format this number to an array of parts. | ||
format<R>(formatter: DecimalFormatter<R>, decimal: string, group: string, minInt: number, minGroup: number, priGroup: number, secGroup: number, zeroScale: boolean, digits?: string[]): void; | ||
protected formatString(d: Decimal, minInt?: number): string; | ||
protected formatParts(d: Decimal, minInt?: number): Part[]; | ||
protected formatString(d: Decimal, minInt: number): string; | ||
protected formatParts(d: Decimal, minInt: number): Part[]; | ||
protected static fromRaw(sign: number, exp: number, data: number[]): Decimal; | ||
@@ -162,0 +162,0 @@ /** |
@@ -39,5 +39,2 @@ import { add, divide, multiply, subtract, trimLeadingZeros, DivMod } from './math'; | ||
var size = function (n) { | ||
if (n <= 0) { | ||
throw new Error("Cannot represent a coefficient with " + n + " digits"); | ||
} | ||
var q = (n / 7 /* RDIGITS */) | 0; | ||
@@ -232,3 +229,3 @@ var r = n - q * 7 /* RDIGITS */; | ||
// Perform the division. | ||
var q = divide(u.data, v.data, false)[0]; | ||
var _b = divide(u.data, v.data, false), q = _b[0], rem = _b[1]; | ||
w.data = q; | ||
@@ -238,2 +235,9 @@ w.sign = u.sign === v.sign ? 1 : -1; | ||
w.trim(); | ||
var hasrem = rem.length && rem[rem.length - 1] !== 0; | ||
if (hasrem) { | ||
var lsd = w.data[0] % 10; | ||
if (lsd === 0 || lsd === 5) { | ||
w.data[0]++; | ||
} | ||
} | ||
if (usePrecision) { | ||
@@ -430,6 +434,3 @@ // Adjust precision to match context | ||
Decimal.prototype.toString = function () { | ||
var f = new StringDecimalFormatter(); | ||
this.format(f, '.', '', 1, 1, 3, 3, false); | ||
var r = f.render(); | ||
return this.sign === -1 ? '-' + r : r; | ||
return this.formatString(this, 1); | ||
}; | ||
@@ -440,2 +441,3 @@ /** | ||
Decimal.prototype.toScientificString = function (minIntegers) { | ||
if (minIntegers === void 0) { minIntegers = 1; } | ||
var _a = this.scientific(minIntegers), coeff = _a[0], exp = _a[1]; | ||
@@ -450,3 +452,3 @@ var r = this.formatString(coeff, minIntegers); | ||
Decimal.prototype.toParts = function () { | ||
return this.formatParts(this); | ||
return this.formatParts(this, 1); | ||
}; | ||
@@ -582,3 +584,2 @@ /** | ||
Decimal.prototype.formatString = function (d, minInt) { | ||
if (minInt === void 0) { minInt = 1; } | ||
var f = new StringDecimalFormatter(); | ||
@@ -590,3 +591,2 @@ d.format(f, '.', '', minInt, 1, 3, 3, false); | ||
Decimal.prototype.formatParts = function (d, minInt) { | ||
if (minInt === void 0) { minInt = 1; } | ||
var f = new PartsDecimalFormatter('.', ''); | ||
@@ -593,0 +593,0 @@ d.format(f, '.', '', minInt, 1, 3, 3, false); |
@@ -184,3 +184,3 @@ import { POWERS10 } from './types'; | ||
q[j] -= 1; | ||
_add(u, j, u, j, v, n + 1, n); | ||
addhelper(u, j, v, n + 1, n); | ||
} | ||
@@ -220,5 +220,5 @@ // D7. Loop on j. | ||
/** | ||
* divide() helper, to add u + v and store the result in w. | ||
* divide() "add back" helper, adds v to u. | ||
*/ | ||
var _add = function (w, j0, u, j1, v, m, n) { | ||
var addhelper = function (u, j, v, m, n) { | ||
var i = 0; | ||
@@ -228,18 +228,14 @@ var k = 0; | ||
while (i < n) { | ||
s = u[i + j1] + (v[i] + k); | ||
s = u[i + j] + (v[i] + k); | ||
k = (s < u[i] || s >= 10000000 /* RADIX */) ? 1 : 0; | ||
w[i + j0] = k ? s - 10000000 /* RADIX */ : s; | ||
u[i + j] = k ? s - 10000000 /* RADIX */ : s; | ||
i++; | ||
} | ||
while (k && i < m) { | ||
s = u[i + j1] + k; | ||
s = u[i + j] + k; | ||
k = s === 10000000 /* RADIX */ ? 1 : 0; | ||
w[i + j0] = k === 1 ? s - 10000000 /* RADIX */ : s; | ||
u[i + j] = k === 1 ? s - 10000000 /* RADIX */ : s; | ||
i++; | ||
} | ||
while (i < m) { | ||
w[i + j0] = u[i + j1]; | ||
i++; | ||
} | ||
return k; | ||
// Final carry is ignored | ||
}; | ||
@@ -246,0 +242,0 @@ /** |
@@ -144,3 +144,3 @@ import { NumberOperands } from './operands'; | ||
*/ | ||
toScientificString(minIntegers: number): string; | ||
toScientificString(minIntegers?: number): string; | ||
/** | ||
@@ -158,4 +158,4 @@ * Format this number to an array of parts. | ||
format<R>(formatter: DecimalFormatter<R>, decimal: string, group: string, minInt: number, minGroup: number, priGroup: number, secGroup: number, zeroScale: boolean, digits?: string[]): void; | ||
protected formatString(d: Decimal, minInt?: number): string; | ||
protected formatParts(d: Decimal, minInt?: number): Part[]; | ||
protected formatString(d: Decimal, minInt: number): string; | ||
protected formatParts(d: Decimal, minInt: number): Part[]; | ||
protected static fromRaw(sign: number, exp: number, data: number[]): Decimal; | ||
@@ -162,0 +162,0 @@ /** |
@@ -41,5 +41,2 @@ "use strict"; | ||
var size = function (n) { | ||
if (n <= 0) { | ||
throw new Error("Cannot represent a coefficient with " + n + " digits"); | ||
} | ||
var q = (n / 7 /* RDIGITS */) | 0; | ||
@@ -234,3 +231,3 @@ var r = n - q * 7 /* RDIGITS */; | ||
// Perform the division. | ||
var q = math_1.divide(u.data, v.data, false)[0]; | ||
var _b = math_1.divide(u.data, v.data, false), q = _b[0], rem = _b[1]; | ||
w.data = q; | ||
@@ -240,2 +237,9 @@ w.sign = u.sign === v.sign ? 1 : -1; | ||
w.trim(); | ||
var hasrem = rem.length && rem[rem.length - 1] !== 0; | ||
if (hasrem) { | ||
var lsd = w.data[0] % 10; | ||
if (lsd === 0 || lsd === 5) { | ||
w.data[0]++; | ||
} | ||
} | ||
if (usePrecision) { | ||
@@ -432,6 +436,3 @@ // Adjust precision to match context | ||
Decimal.prototype.toString = function () { | ||
var f = new format_1.StringDecimalFormatter(); | ||
this.format(f, '.', '', 1, 1, 3, 3, false); | ||
var r = f.render(); | ||
return this.sign === -1 ? '-' + r : r; | ||
return this.formatString(this, 1); | ||
}; | ||
@@ -442,2 +443,3 @@ /** | ||
Decimal.prototype.toScientificString = function (minIntegers) { | ||
if (minIntegers === void 0) { minIntegers = 1; } | ||
var _a = this.scientific(minIntegers), coeff = _a[0], exp = _a[1]; | ||
@@ -452,3 +454,3 @@ var r = this.formatString(coeff, minIntegers); | ||
Decimal.prototype.toParts = function () { | ||
return this.formatParts(this); | ||
return this.formatParts(this, 1); | ||
}; | ||
@@ -584,3 +586,2 @@ /** | ||
Decimal.prototype.formatString = function (d, minInt) { | ||
if (minInt === void 0) { minInt = 1; } | ||
var f = new format_1.StringDecimalFormatter(); | ||
@@ -592,3 +593,2 @@ d.format(f, '.', '', minInt, 1, 3, 3, false); | ||
Decimal.prototype.formatParts = function (d, minInt) { | ||
if (minInt === void 0) { minInt = 1; } | ||
var f = new format_1.PartsDecimalFormatter('.', ''); | ||
@@ -595,0 +595,0 @@ d.format(f, '.', '', minInt, 1, 3, 3, false); |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./decimal")); | ||
__export(require("./format")); | ||
__export(require("./rational")); | ||
__export(require("./operands")); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./decimal"), exports); | ||
tslib_1.__exportStar(require("./format"), exports); | ||
tslib_1.__exportStar(require("./rational"), exports); | ||
tslib_1.__exportStar(require("./operands"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -186,3 +186,3 @@ "use strict"; | ||
q[j] -= 1; | ||
_add(u, j, u, j, v, n + 1, n); | ||
addhelper(u, j, v, n + 1, n); | ||
} | ||
@@ -222,5 +222,5 @@ // D7. Loop on j. | ||
/** | ||
* divide() helper, to add u + v and store the result in w. | ||
* divide() "add back" helper, adds v to u. | ||
*/ | ||
var _add = function (w, j0, u, j1, v, m, n) { | ||
var addhelper = function (u, j, v, m, n) { | ||
var i = 0; | ||
@@ -230,18 +230,14 @@ var k = 0; | ||
while (i < n) { | ||
s = u[i + j1] + (v[i] + k); | ||
s = u[i + j] + (v[i] + k); | ||
k = (s < u[i] || s >= 10000000 /* RADIX */) ? 1 : 0; | ||
w[i + j0] = k ? s - 10000000 /* RADIX */ : s; | ||
u[i + j] = k ? s - 10000000 /* RADIX */ : s; | ||
i++; | ||
} | ||
while (k && i < m) { | ||
s = u[i + j1] + k; | ||
s = u[i + j] + k; | ||
k = s === 10000000 /* RADIX */ ? 1 : 0; | ||
w[i + j0] = k === 1 ? s - 10000000 /* RADIX */ : s; | ||
u[i + j] = k === 1 ? s - 10000000 /* RADIX */ : s; | ||
i++; | ||
} | ||
while (i < m) { | ||
w[i + j0] = u[i + j1]; | ||
i++; | ||
} | ||
return k; | ||
// Final carry is ignored | ||
}; | ||
@@ -248,0 +244,0 @@ /** |
{ | ||
"name": "@phensley/decimal", | ||
"version": "0.11.3-alpha.0", | ||
"version": "0.11.3", | ||
"description": "Arbitrary precision decimal math", | ||
@@ -61,3 +61,6 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "b298d97fa3624770fc1ffbabc7d88911e4f35fcb" | ||
"dependencies": { | ||
"tslib": "^1.9.3" | ||
}, | ||
"gitHead": "30e640852cd5fa3cfc78259b6c1d9f3be8e1afdc" | ||
} |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
233090
1
4015
+ Addedtslib@^1.9.3
+ Addedtslib@1.14.1(transitive)