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

Unified Diff: src/dtoa.cc

Issue 3468003: Add bignum fall-back when the fast dtoa doesn't succeed. This removes Gay's d... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 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 | « src/dtoa.h ('k') | test/cctest/SConscript » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/dtoa.cc
===================================================================
--- src/dtoa.cc (revision 5826)
+++ src/dtoa.cc (working copy)
@@ -30,6 +30,7 @@
#include "v8.h"
#include "dtoa.h"
+#include "bignum-dtoa.h"
#include "double.h"
#include "fast-dtoa.h"
#include "fixed-dtoa.h"
@@ -37,7 +38,19 @@
namespace v8 {
namespace internal {
-bool DoubleToAscii(double v, DtoaMode mode, int requested_digits,
+static BignumDtoaMode DtoaToBignumDtoaMode(DtoaMode dtoa_mode) {
+ switch (dtoa_mode) {
+ case DTOA_SHORTEST: return BIGNUM_DTOA_SHORTEST;
+ case DTOA_FIXED: return BIGNUM_DTOA_FIXED;
+ case DTOA_PRECISION: return BIGNUM_DTOA_PRECISION;
+ default:
+ UNREACHABLE();
+ return BIGNUM_DTOA_SHORTEST; // To silence compiler.
+ }
+}
+
+
+void DoubleToAscii(double v, DtoaMode mode, int requested_digits,
Vector<char> buffer, int* sign, int* length, int* point) {
ASSERT(!Double(v).IsSpecial());
ASSERT(mode == DTOA_SHORTEST || requested_digits >= 0);
@@ -54,25 +67,37 @@
buffer[1] = '\0';
*length = 1;
*point = 1;
- return true;
+ return;
}
if (mode == DTOA_PRECISION && requested_digits == 0) {
buffer[0] = '\0';
*length = 0;
- return true;
+ return;
}
+ bool fast_worked;
switch (mode) {
case DTOA_SHORTEST:
- return FastDtoa(v, FAST_DTOA_SHORTEST, 0, buffer, length, point);
+ fast_worked = FastDtoa(v, FAST_DTOA_SHORTEST, 0, buffer, length, point);
+ break;
case DTOA_FIXED:
- return FastFixedDtoa(v, requested_digits, buffer, length, point);
+ fast_worked = FastFixedDtoa(v, requested_digits, buffer, length, point);
+ break;
case DTOA_PRECISION:
- return FastDtoa(v, FAST_DTOA_PRECISION, requested_digits,
- buffer, length, point);
+ fast_worked = FastDtoa(v, FAST_DTOA_PRECISION, requested_digits,
+ buffer, length, point);
+ break;
+ default:
+ UNREACHABLE();
+ fast_worked = false;
}
- return false;
+ if (fast_worked) return;
+
+ // If the fast dtoa didn't succeed use the slower bignum version.
+ BignumDtoaMode bignum_mode = DtoaToBignumDtoaMode(mode);
+ BignumDtoa(v, bignum_mode, requested_digits, buffer, length, point);
+ buffer[*length] = '\0';
}
} } // namespace v8::internal
« no previous file with comments | « src/dtoa.h ('k') | test/cctest/SConscript » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698