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

Side by Side Diff: test/cctest/test-fast-dtoa.cc

Issue 1732019: Switch to vectors instead of bare char* arrays. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 8 months 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/fast-dtoa.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 2
3 #include <stdlib.h> 3 #include <stdlib.h>
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "platform.h" 7 #include "platform.h"
8 #include "cctest.h" 8 #include "cctest.h"
9 #include "diy-fp.h" 9 #include "diy-fp.h"
10 #include "double.h" 10 #include "double.h"
11 #include "fast-dtoa.h" 11 #include "fast-dtoa.h"
12 #include "gay-shortest.h" 12 #include "gay-shortest.h"
13 13
14 using namespace v8::internal; 14 using namespace v8::internal;
15 15
16 static const int kBufferSize = 100; 16 static const int kBufferSize = 100;
17 17
18 TEST(FastDtoaVariousDoubles) { 18 TEST(FastDtoaVariousDoubles) {
19 char buffer[kBufferSize]; 19 char buffer_container[kBufferSize];
20 Vector<char> buffer(buffer_container, kBufferSize);
20 int sign; 21 int sign;
21 int length; 22 int length;
22 int point; 23 int point;
23 int status; 24 int status;
24 25
25 double min_double = 5e-324; 26 double min_double = 5e-324;
26 status = FastDtoa(min_double, buffer, &sign, &length, &point); 27 status = FastDtoa(min_double, buffer, &sign, &length, &point);
27 CHECK(status); 28 CHECK(status);
28 CHECK_EQ(0, sign); 29 CHECK_EQ(0, sign);
29 CHECK_EQ("5", buffer); 30 CHECK_EQ("5", buffer.start());
30 CHECK_EQ(-323, point); 31 CHECK_EQ(-323, point);
31 32
32 double max_double = 1.7976931348623157e308; 33 double max_double = 1.7976931348623157e308;
33 status = FastDtoa(max_double, buffer, &sign, &length, &point); 34 status = FastDtoa(max_double, buffer, &sign, &length, &point);
34 CHECK(status); 35 CHECK(status);
35 CHECK_EQ(0, sign); 36 CHECK_EQ(0, sign);
36 CHECK_EQ("17976931348623157", buffer); 37 CHECK_EQ("17976931348623157", buffer.start());
37 CHECK_EQ(309, point); 38 CHECK_EQ(309, point);
38 39
39 status = FastDtoa(4294967272.0, buffer, &sign, &length, &point); 40 status = FastDtoa(4294967272.0, buffer, &sign, &length, &point);
40 CHECK(status); 41 CHECK(status);
41 CHECK_EQ(0, sign); 42 CHECK_EQ(0, sign);
42 CHECK_EQ("4294967272", buffer); 43 CHECK_EQ("4294967272", buffer.start());
43 CHECK_EQ(10, point); 44 CHECK_EQ(10, point);
44 45
45 status = FastDtoa(4.1855804968213567e298, buffer, &sign, &length, &point); 46 status = FastDtoa(4.1855804968213567e298, buffer, &sign, &length, &point);
46 CHECK(status); 47 CHECK(status);
47 CHECK_EQ(0, sign); 48 CHECK_EQ(0, sign);
48 CHECK_EQ("4185580496821357", buffer); 49 CHECK_EQ("4185580496821357", buffer.start());
49 CHECK_EQ(299, point); 50 CHECK_EQ(299, point);
50 51
51 status = FastDtoa(5.5626846462680035e-309, buffer, &sign, &length, &point); 52 status = FastDtoa(5.5626846462680035e-309, buffer, &sign, &length, &point);
52 CHECK(status); 53 CHECK(status);
53 CHECK_EQ(0, sign); 54 CHECK_EQ(0, sign);
54 CHECK_EQ("5562684646268003", buffer); 55 CHECK_EQ("5562684646268003", buffer.start());
55 CHECK_EQ(-308, point); 56 CHECK_EQ(-308, point);
56 57
57 status = FastDtoa(2147483648.0, buffer, &sign, &length, &point); 58 status = FastDtoa(2147483648.0, buffer, &sign, &length, &point);
58 CHECK(status); 59 CHECK(status);
59 CHECK_EQ(0, sign); 60 CHECK_EQ(0, sign);
60 CHECK_EQ("2147483648", buffer); 61 CHECK_EQ("2147483648", buffer.start());
61 CHECK_EQ(10, point); 62 CHECK_EQ(10, point);
62 63
63 status = FastDtoa(3.5844466002796428e+298, buffer, &sign, &length, &point); 64 status = FastDtoa(3.5844466002796428e+298, buffer, &sign, &length, &point);
64 if (status) { // Not all FastDtoa variants manage to compute this number. 65 if (status) { // Not all FastDtoa variants manage to compute this number.
65 CHECK_EQ("35844466002796428", buffer); 66 CHECK_EQ("35844466002796428", buffer.start());
66 CHECK_EQ(0, sign); 67 CHECK_EQ(0, sign);
67 CHECK_EQ(299, point); 68 CHECK_EQ(299, point);
68 } 69 }
69 70
70 uint64_t smallest_normal64 = V8_2PART_UINT64_C(0x00100000, 00000000); 71 uint64_t smallest_normal64 = V8_2PART_UINT64_C(0x00100000, 00000000);
71 double v = Double(smallest_normal64).value(); 72 double v = Double(smallest_normal64).value();
72 status = FastDtoa(v, buffer, &sign, &length, &point); 73 status = FastDtoa(v, buffer, &sign, &length, &point);
73 if (status) { 74 if (status) {
74 CHECK_EQ(0, sign); 75 CHECK_EQ(0, sign);
75 CHECK_EQ("22250738585072014", buffer); 76 CHECK_EQ("22250738585072014", buffer.start());
76 CHECK_EQ(-307, point); 77 CHECK_EQ(-307, point);
77 } 78 }
78 79
79 uint64_t largest_denormal64 = V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF); 80 uint64_t largest_denormal64 = V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF);
80 v = Double(largest_denormal64).value(); 81 v = Double(largest_denormal64).value();
81 status = FastDtoa(v, buffer, &sign, &length, &point); 82 status = FastDtoa(v, buffer, &sign, &length, &point);
82 if (status) { 83 if (status) {
83 CHECK_EQ(0, sign); 84 CHECK_EQ(0, sign);
84 CHECK_EQ("2225073858507201", buffer); 85 CHECK_EQ("2225073858507201", buffer.start());
85 CHECK_EQ(-307, point); 86 CHECK_EQ(-307, point);
86 } 87 }
87 } 88 }
88 89
89 90
90 TEST(FastDtoaGayShortest) { 91 TEST(FastDtoaGayShortest) {
91 char buffer[kBufferSize]; 92 char buffer_container[kBufferSize];
93 Vector<char> buffer(buffer_container, kBufferSize);
92 bool status; 94 bool status;
93 int sign; 95 int sign;
94 int length; 96 int length;
95 int point; 97 int point;
96 int succeeded = 0; 98 int succeeded = 0;
97 int total = 0; 99 int total = 0;
98 bool needed_max_length = false; 100 bool needed_max_length = false;
99 101
100 Vector<const GayShortest> precomputed = PrecomputedShortestRepresentations(); 102 Vector<const GayShortest> precomputed = PrecomputedShortestRepresentations();
101 for (int i = 0; i < precomputed.length(); ++i) { 103 for (int i = 0; i < precomputed.length(); ++i) {
102 const GayShortest current_test = precomputed[i]; 104 const GayShortest current_test = precomputed[i];
103 total++; 105 total++;
104 double v = current_test.v; 106 double v = current_test.v;
105 status = FastDtoa(v, buffer, &sign, &length, &point); 107 status = FastDtoa(v, buffer, &sign, &length, &point);
106 CHECK_GE(kFastDtoaMaximalLength, length); 108 CHECK_GE(kFastDtoaMaximalLength, length);
107 if (!status) continue; 109 if (!status) continue;
108 if (length == kFastDtoaMaximalLength) needed_max_length = true; 110 if (length == kFastDtoaMaximalLength) needed_max_length = true;
109 succeeded++; 111 succeeded++;
110 CHECK_EQ(0, sign); // All precomputed numbers are positive. 112 CHECK_EQ(0, sign); // All precomputed numbers are positive.
111 CHECK_EQ(current_test.decimal_point, point); 113 CHECK_EQ(current_test.decimal_point, point);
112 CHECK_EQ(current_test.representation, buffer); 114 CHECK_EQ(current_test.representation, buffer.start());
113 } 115 }
114 CHECK_GT(succeeded*1.0/total, 0.99); 116 CHECK_GT(succeeded*1.0/total, 0.99);
115 CHECK(needed_max_length); 117 CHECK(needed_max_length);
116 } 118 }
OLDNEW
« no previous file with comments | « src/fast-dtoa.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698