Commit b6d2bacd authored by yangguo's avatar yangguo Committed by Commit bot

Fix Number.prototype.toString with non-default radix wrt modulo.

TBR=tebbi@chromium.org
BUG=chromium:668510

Review-Url: https://codereview.chromium.org/2526223003
Cr-Commit-Position: refs/heads/master@{#41280}
parent 309b77f0
......@@ -474,12 +474,15 @@ char* DoubleToRadixCString(double value, int radix) {
} while (fraction > delta);
}
// Compute integer digits.
// Compute integer digits. Fill unrepresented digits with zero.
while (Double(integer / radix).Exponent() > 0) {
integer /= radix;
buffer[--integer_cursor] = '0';
}
do {
double multiple = std::floor(integer / radix);
int digit = static_cast<int>(integer - multiple * radix);
buffer[--integer_cursor] = chars[digit];
integer = multiple;
double remainder = modulo(integer, radix);
buffer[--integer_cursor] = chars[static_cast<int>(remainder)];
integer = (integer - remainder) / radix;
} while (integer > 0);
// Add sign and terminate string.
......
......@@ -151,6 +151,9 @@ assertEquals("10000", (81).toString(3));
assertEquals("10000.01", (81 + 1/9).toString(3));
assertEquals("0.0212010212010212010212010212010212", (2/7).toString(3));
assertEquals("314404114120101444444424000000000000000",
(1.2345e+27).toString(5));
// ----------------------------------------------------------------------
// toFixed
assertEquals("NaN", (NaN).toFixed(2));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment