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) { ...@@ -474,12 +474,15 @@ char* DoubleToRadixCString(double value, int radix) {
} while (fraction > delta); } 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 { do {
double multiple = std::floor(integer / radix); double remainder = modulo(integer, radix);
int digit = static_cast<int>(integer - multiple * radix); buffer[--integer_cursor] = chars[static_cast<int>(remainder)];
buffer[--integer_cursor] = chars[digit]; integer = (integer - remainder) / radix;
integer = multiple;
} while (integer > 0); } while (integer > 0);
// Add sign and terminate string. // Add sign and terminate string.
......
...@@ -151,6 +151,9 @@ assertEquals("10000", (81).toString(3)); ...@@ -151,6 +151,9 @@ assertEquals("10000", (81).toString(3));
assertEquals("10000.01", (81 + 1/9).toString(3)); assertEquals("10000.01", (81 + 1/9).toString(3));
assertEquals("0.0212010212010212010212010212010212", (2/7).toString(3)); assertEquals("0.0212010212010212010212010212010212", (2/7).toString(3));
assertEquals("314404114120101444444424000000000000000",
(1.2345e+27).toString(5));
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// toFixed // toFixed
assertEquals("NaN", (NaN).toFixed(2)); 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