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

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

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

Powered by Google App Engine
This is Rietveld 408576698