Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Unified Diff: src/conversions.cc

Issue 2526223003: Fix Number.prototype.toString with non-default radix wrt modulo. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/number-tostring.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/conversions.cc
diff --git a/src/conversions.cc b/src/conversions.cc
index fb09d18a407f6780283e2b8bdcc468015a747884..6048b34abf703bbe242572da228e912c1ef52f8d 100644
--- a/src/conversions.cc
+++ b/src/conversions.cc
@@ -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.
« no previous file with comments | « no previous file | test/mjsunit/number-tostring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698