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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/dtoa.h ('k') | test/cctest/SConscript » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <math.h> 28 #include <math.h>
29 29
30 #include "v8.h" 30 #include "v8.h"
31 #include "dtoa.h" 31 #include "dtoa.h"
32 32
33 #include "bignum-dtoa.h"
33 #include "double.h" 34 #include "double.h"
34 #include "fast-dtoa.h" 35 #include "fast-dtoa.h"
35 #include "fixed-dtoa.h" 36 #include "fixed-dtoa.h"
36 37
37 namespace v8 { 38 namespace v8 {
38 namespace internal { 39 namespace internal {
39 40
40 bool DoubleToAscii(double v, DtoaMode mode, int requested_digits, 41 static BignumDtoaMode DtoaToBignumDtoaMode(DtoaMode dtoa_mode) {
42 switch (dtoa_mode) {
43 case DTOA_SHORTEST: return BIGNUM_DTOA_SHORTEST;
44 case DTOA_FIXED: return BIGNUM_DTOA_FIXED;
45 case DTOA_PRECISION: return BIGNUM_DTOA_PRECISION;
46 default:
47 UNREACHABLE();
48 return BIGNUM_DTOA_SHORTEST; // To silence compiler.
49 }
50 }
51
52
53 void DoubleToAscii(double v, DtoaMode mode, int requested_digits,
41 Vector<char> buffer, int* sign, int* length, int* point) { 54 Vector<char> buffer, int* sign, int* length, int* point) {
42 ASSERT(!Double(v).IsSpecial()); 55 ASSERT(!Double(v).IsSpecial());
43 ASSERT(mode == DTOA_SHORTEST || requested_digits >= 0); 56 ASSERT(mode == DTOA_SHORTEST || requested_digits >= 0);
44 57
45 if (Double(v).Sign() < 0) { 58 if (Double(v).Sign() < 0) {
46 *sign = 1; 59 *sign = 1;
47 v = -v; 60 v = -v;
48 } else { 61 } else {
49 *sign = 0; 62 *sign = 0;
50 } 63 }
51 64
52 if (v == 0) { 65 if (v == 0) {
53 buffer[0] = '0'; 66 buffer[0] = '0';
54 buffer[1] = '\0'; 67 buffer[1] = '\0';
55 *length = 1; 68 *length = 1;
56 *point = 1; 69 *point = 1;
57 return true; 70 return;
58 } 71 }
59 72
60 if (mode == DTOA_PRECISION && requested_digits == 0) { 73 if (mode == DTOA_PRECISION && requested_digits == 0) {
61 buffer[0] = '\0'; 74 buffer[0] = '\0';
62 *length = 0; 75 *length = 0;
63 return true; 76 return;
64 } 77 }
65 78
79 bool fast_worked;
66 switch (mode) { 80 switch (mode) {
67 case DTOA_SHORTEST: 81 case DTOA_SHORTEST:
68 return FastDtoa(v, FAST_DTOA_SHORTEST, 0, buffer, length, point); 82 fast_worked = FastDtoa(v, FAST_DTOA_SHORTEST, 0, buffer, length, point);
83 break;
69 case DTOA_FIXED: 84 case DTOA_FIXED:
70 return FastFixedDtoa(v, requested_digits, buffer, length, point); 85 fast_worked = FastFixedDtoa(v, requested_digits, buffer, length, point);
86 break;
71 case DTOA_PRECISION: 87 case DTOA_PRECISION:
72 return FastDtoa(v, FAST_DTOA_PRECISION, requested_digits, 88 fast_worked = FastDtoa(v, FAST_DTOA_PRECISION, requested_digits,
73 buffer, length, point); 89 buffer, length, point);
90 break;
91 default:
92 UNREACHABLE();
93 fast_worked = false;
74 } 94 }
75 return false; 95 if (fast_worked) return;
96
97 // If the fast dtoa didn't succeed use the slower bignum version.
98 BignumDtoaMode bignum_mode = DtoaToBignumDtoaMode(mode);
99 BignumDtoa(v, bignum_mode, requested_digits, buffer, length, point);
100 buffer[*length] = '\0';
76 } 101 }
77 102
78 } } // namespace v8::internal 103 } } // namespace v8::internal
OLDNEW
« 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