Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaffle committed May 6, 2024
1 parent 3b7c8da commit fbe46b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions BigDecimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
// BigDecimal.subtract(a, b[, rounding])
// BigDecimal.multiply(a, b[, rounding])
// BigDecimal.divide(a, b, rounding)

// BigDecimal.cmp(a, b)

// BigDecimal.round(a, rounding)

// a.toString()
// a.toFixed(fractionDigits[, roundingMode = "half-up"])
// a.toPrecision(precision[, roundingMode = "half-up"])
Expand Down Expand Up @@ -177,7 +176,7 @@ function bigIntAbs(a) {
// floor(log2(a)) + 1 if a > 0
function bitLength(a) {
const s = a.toString(16);
const c = +s.charCodeAt(0) - "0".charCodeAt(0);
const c = +s.charCodeAt(0) - +"0".charCodeAt(0);
if (c <= 0) {
throw new RangeError();
}
Expand Down Expand Up @@ -658,7 +657,7 @@ BigDecimal.prototype.toString = function () {
return "0";
}
let sign = "";
if (significand.charCodeAt(0) === "-".charCodeAt(0)) {
if (+significand.charCodeAt(0) === +"-".charCodeAt(0)) {
significand = significand.slice(1);
sign = "-";
}
Expand All @@ -682,15 +681,15 @@ function bigDecimalToPlainString(significand, exponent, minFraction, minSignific
let fraction = significand.length - (e + 1);
let i = significand.length;
while (fraction > minFraction &&
i >= minSignificant &&
i >= 1 && 0 + significand.charCodeAt(i - 1) === "0".charCodeAt(0)) {
+i >= +minSignificant &&
i >= 1 && +significand.charCodeAt(i - 1) === +"0".charCodeAt(0)) {
i -= 1;
fraction -= 1;
}
if (i < significand.length) {
if (+i < +significand.length) {
significand = significand.slice(0, i);
}
const zeros = Math.max(minFraction - fraction, minSignificant - significand.length);
const zeros = Math.max(minFraction - fraction, +minSignificant - +significand.length);
if (zeros > 0) {
significand += String("0".repeat(zeros));
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yaffle/bigdecimal",
"version": "1.0.36",
"version": "1.0.37",
"description": "Arbitrary precision decimal arithmetic library. Polyfill for decimal proposal. Implemented on the top of BigInt.",
"main": "BigDecimal.js",
"types": "BigDecimal.d.ts",
Expand Down

0 comments on commit fbe46b3

Please sign in to comment.