Skip to content

Commit

Permalink
Optimise toString(10)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcl committed Jan 13, 2019
1 parent 171e195 commit 3bcba45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 6 additions & 5 deletions bignumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -2669,15 +2669,16 @@
str = 'NaN';
}
} else {
str = coeffToString(n.c);

if (b == null) {
str = e <= TO_EXP_NEG || e >= TO_EXP_POS
? toExponential(str, e)
: toFixedPoint(str, e, '0');
? toExponential(coeffToString(n.c), e)
: toFixedPoint(coeffToString(n.c), e, '0');
} else if (b === 10) {
n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
str = toFixedPoint(coeffToString(n.c), n.e, '0');
} else {
intCheck(b, 2, ALPHABET.length, 'Base');
str = convertBase(toFixedPoint(str, e, '0'), 10, b, s, true);
str = convertBase(toFixedPoint(coeffToString(n.c), e, '0'), 10, b, s, true);
}

if (s < 0 && n.c[0]) str = '-' + str;
Expand Down
15 changes: 8 additions & 7 deletions bignumber.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,9 @@ function clone(configObject) {
sum = new BigNumber(args[0]);
for (; i < args.length;) sum = sum.plus(args[i++]);
return sum;
};
};



// PRIVATE FUNCTIONS


Expand Down Expand Up @@ -2665,15 +2665,16 @@ function clone(configObject) {
str = 'NaN';
}
} else {
str = coeffToString(n.c);

if (b == null) {
str = e <= TO_EXP_NEG || e >= TO_EXP_POS
? toExponential(str, e)
: toFixedPoint(str, e, '0');
? toExponential(coeffToString(n.c), e)
: toFixedPoint(coeffToString(n.c), e, '0');
} else if (b === 10) {
n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
str = toFixedPoint(coeffToString(n.c), n.e, '0');
} else {
intCheck(b, 2, ALPHABET.length, 'Base');
str = convertBase(toFixedPoint(str, e, '0'), 10, b, s, true);
str = convertBase(toFixedPoint(coeffToString(n.c), e, '0'), 10, b, s, true);
}

if (s < 0 && n.c[0]) str = '-' + str;
Expand Down

0 comments on commit 3bcba45

Please sign in to comment.