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

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

Issue 1032007: Rename grisu to fast_dtoa. Get rid of template. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 9 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 | « test/cctest/SConscript ('k') | test/cctest/test-grisu3.cc » ('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 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 "gay_shortest.h" 12 #include "gay_shortest.h"
12 #include "grisu3.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(GrisuVariousDoubles) { 18 TEST(FastDtoaVariousDoubles) {
19 char buffer[kBufferSize]; 19 char buffer[kBufferSize];
20 int sign; 20 int sign;
21 int length; 21 int length;
22 int point; 22 int point;
23 int status; 23 int status;
24 24
25 double min_double = 5e-324; 25 double min_double = 5e-324;
26 status = grisu3(min_double, buffer, &sign, &length, &point); 26 status = FastDtoa(min_double, buffer, &sign, &length, &point);
27 CHECK(status); 27 CHECK(status);
28 CHECK_EQ(0, sign); 28 CHECK_EQ(0, sign);
29 CHECK_EQ("5", buffer); 29 CHECK_EQ("5", buffer);
30 CHECK_EQ(-323, point); 30 CHECK_EQ(-323, point);
31 31
32 double max_double = 1.7976931348623157e308; 32 double max_double = 1.7976931348623157e308;
33 status = grisu3(max_double, buffer, &sign, &length, &point); 33 status = FastDtoa(max_double, buffer, &sign, &length, &point);
34 CHECK(status); 34 CHECK(status);
35 CHECK_EQ(0, sign); 35 CHECK_EQ(0, sign);
36 CHECK_EQ("17976931348623157", buffer); 36 CHECK_EQ("17976931348623157", buffer);
37 CHECK_EQ(309, point); 37 CHECK_EQ(309, point);
38 38
39 status = grisu3(4294967272.0, buffer, &sign, &length, &point); 39 status = FastDtoa(4294967272.0, buffer, &sign, &length, &point);
40 CHECK(status); 40 CHECK(status);
41 CHECK_EQ(0, sign); 41 CHECK_EQ(0, sign);
42 CHECK_EQ("4294967272", buffer); 42 CHECK_EQ("4294967272", buffer);
43 CHECK_EQ(10, point); 43 CHECK_EQ(10, point);
44 44
45 status = grisu3(4.1855804968213567e298, buffer, &sign, &length, &point); 45 status = FastDtoa(4.1855804968213567e298, buffer, &sign, &length, &point);
46 CHECK(status); 46 CHECK(status);
47 CHECK_EQ(0, sign); 47 CHECK_EQ(0, sign);
48 CHECK_EQ("4185580496821357", buffer); 48 CHECK_EQ("4185580496821357", buffer);
49 CHECK_EQ(299, point); 49 CHECK_EQ(299, point);
50 50
51 status = grisu3(5.5626846462680035e-309, buffer, &sign, &length, &point); 51 status = FastDtoa(5.5626846462680035e-309, buffer, &sign, &length, &point);
52 CHECK(status); 52 CHECK(status);
53 CHECK_EQ(0, sign); 53 CHECK_EQ(0, sign);
54 CHECK_EQ("5562684646268003", buffer); 54 CHECK_EQ("5562684646268003", buffer);
55 CHECK_EQ(-308, point); 55 CHECK_EQ(-308, point);
56 56
57 status = grisu3(2147483648.0, buffer, &sign, &length, &point); 57 status = FastDtoa(2147483648.0, buffer, &sign, &length, &point);
58 CHECK(status); 58 CHECK(status);
59 CHECK_EQ(0, sign); 59 CHECK_EQ(0, sign);
60 CHECK_EQ("2147483648", buffer); 60 CHECK_EQ("2147483648", buffer);
61 CHECK_EQ(10, point); 61 CHECK_EQ(10, point);
62 62
63 status = grisu3(3.5844466002796428e+298, buffer, &sign, &length, &point); 63 status = FastDtoa(3.5844466002796428e+298, buffer, &sign, &length, &point);
64 if (status) { // Not all grisu3 variants manage to compute this number. 64 if (status) { // Not all FastDtoa variants manage to compute this number.
65 CHECK_EQ("35844466002796428", buffer); 65 CHECK_EQ("35844466002796428", buffer);
66 CHECK_EQ(0, sign); 66 CHECK_EQ(0, sign);
67 CHECK_EQ(299, point); 67 CHECK_EQ(299, point);
68 } 68 }
69 69
70 uint64_t smallest_normal64 = V8_2PART_UINT64_C(0x00100000, 00000000); 70 uint64_t smallest_normal64 = V8_2PART_UINT64_C(0x00100000, 00000000);
71 double v = Double(smallest_normal64).value(); 71 double v = Double(smallest_normal64).value();
72 status = grisu3(v, buffer, &sign, &length, &point); 72 status = FastDtoa(v, buffer, &sign, &length, &point);
73 if (status) { 73 if (status) {
74 CHECK_EQ(0, sign); 74 CHECK_EQ(0, sign);
75 CHECK_EQ("22250738585072014", buffer); 75 CHECK_EQ("22250738585072014", buffer);
76 CHECK_EQ(-307, point); 76 CHECK_EQ(-307, point);
77 } 77 }
78 78
79 uint64_t largest_denormal64 = V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF); 79 uint64_t largest_denormal64 = V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF);
80 v = Double(largest_denormal64).value(); 80 v = Double(largest_denormal64).value();
81 status = grisu3(v, buffer, &sign, &length, &point); 81 status = FastDtoa(v, buffer, &sign, &length, &point);
82 if (status) { 82 if (status) {
83 CHECK_EQ(0, sign); 83 CHECK_EQ(0, sign);
84 CHECK_EQ("2225073858507201", buffer); 84 CHECK_EQ("2225073858507201", buffer);
85 CHECK_EQ(-307, point); 85 CHECK_EQ(-307, point);
86 } 86 }
87 } 87 }
88 88
89 89
90 TEST(GrisuGayShortest) { 90 TEST(FastDtoaGayShortest) {
91 char buffer[kBufferSize]; 91 char buffer[kBufferSize];
92 bool status; 92 bool status;
93 int sign; 93 int sign;
94 int length; 94 int length;
95 int point; 95 int point;
96 int succeeded = 0; 96 int succeeded = 0;
97 int total = 0; 97 int total = 0;
98 bool needed_max_length = false; 98 bool needed_max_length = false;
99 99
100 Vector<const GayShortest> precomputed = PrecomputedShortestRepresentations(); 100 Vector<const GayShortest> precomputed = PrecomputedShortestRepresentations();
101 for (int i = 0; i < precomputed.length(); ++i) { 101 for (int i = 0; i < precomputed.length(); ++i) {
102 const GayShortest current_test = precomputed[i]; 102 const GayShortest current_test = precomputed[i];
103 total++; 103 total++;
104 double v = current_test.v; 104 double v = current_test.v;
105 status = grisu3(v, buffer, &sign, &length, &point); 105 status = FastDtoa(v, buffer, &sign, &length, &point);
106 CHECK_GE(kGrisu3MaximalLength, length); 106 CHECK_GE(kFastDtoaMaximalLength, length);
107 if (!status) continue; 107 if (!status) continue;
108 if (length == kGrisu3MaximalLength) needed_max_length = true; 108 if (length == kFastDtoaMaximalLength) needed_max_length = true;
109 succeeded++; 109 succeeded++;
110 CHECK_EQ(0, sign); // All precomputed numbers are positive. 110 CHECK_EQ(0, sign); // All precomputed numbers are positive.
111 CHECK_EQ(current_test.decimal_point, point); 111 CHECK_EQ(current_test.decimal_point, point);
112 CHECK_EQ(current_test.representation, buffer); 112 CHECK_EQ(current_test.representation, buffer);
113 } 113 }
114 CHECK_GT(succeeded*1.0/total, 0.99); 114 CHECK_GT(succeeded*1.0/total, 0.99);
115 CHECK(needed_max_length); 115 CHECK(needed_max_length);
116 } 116 }
OLDNEW
« no previous file with comments | « test/cctest/SConscript ('k') | test/cctest/test-grisu3.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698