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-double.cc

Issue 619005: Fast algorithm for double->string conversion. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2
3 #include <stdlib.h>
4
5 #include "v8.h"
6
7 #include "platform.h"
8 #include "cctest.h"
9 #include "double.h"
10
11 using namespace v8::internal;
12
13
14 TEST(Uint64Conversions) {
15 // Start by checking the byte-order.
16 uint64_t ordered = V8_2PART_UINT64_C(0x01234567,89ABCDEF);
17 CHECK_EQ(3512700564088504e-318, Double(ordered).value());
18
19 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000,00000001);
20 CHECK_EQ(5e-324, Double(min_double64).value());
21
22 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff,ffffffff);
23 CHECK_EQ(1.7976931348623157e308, Double(max_double64).value());
24 }
25
26 TEST(AsDiyFp) {
27 uint64_t ordered = V8_2PART_UINT64_C(0x01234567,89ABCDEF);
28 DiyFp diy_fp = Double(ordered).AsDiyFp();
29 CHECK_EQ(0x12 - 0x3FF - 52, diy_fp.e());
30 // The last 52 bits + 1 hidden bit a position 52.
31 CHECK_EQ(V8_2PART_UINT64_C(0x00134567,89ABCDEF), diy_fp.f());
32
33 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000,00000001);
34 diy_fp = Double(min_double64).AsDiyFp();
35 CHECK_EQ(-0x3FF - 52 + 1, diy_fp.e());
36 // This is a denormal; so no hidden bit.
37 uint64_t correct_f = 1;
38 CHECK_EQ(correct_f, diy_fp.f());
39
40 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff,ffffffff);
41 diy_fp = Double(max_double64).AsDiyFp();
42 CHECK_EQ(0x7FE - 0x3FF - 52, diy_fp.e());
43 correct_f = V8_2PART_UINT64_C(0x001fffff,ffffffff);
44 CHECK_EQ(correct_f, diy_fp.f());
45 }
46
47
48 TEST(AsNormalizedDiyFp) {
49 uint64_t ordered = V8_2PART_UINT64_C(0x01234567,89ABCDEF);
50 DiyFp diy_fp = Double(ordered).AsNormalizedDiyFp();
51 CHECK_EQ(0x12 - 0x3FF - 52 - 11, diy_fp.e());
52 uint64_t correct_f = V8_2PART_UINT64_C(0x00134567,89ABCDEF) << 11;
53 CHECK_EQ(correct_f, diy_fp.f());
54
55 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000,00000001);
56 diy_fp = Double(min_double64).AsNormalizedDiyFp();
57 CHECK_EQ(-0x3FF - 52 + 1 - 63, diy_fp.e());
58 // This is a denormal; so no hidden bit.
59 correct_f = V8_2PART_UINT64_C(0x80000000,00000000);
60 CHECK_EQ(correct_f, diy_fp.f());
61
62 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff,ffffffff);
63 diy_fp = Double(max_double64).AsNormalizedDiyFp();
64 CHECK_EQ(0x7FE - 0x3FF - 52 - 11, diy_fp.e());
65 correct_f = V8_2PART_UINT64_C(0x001fffff,ffffffff) << 11;
66 CHECK_EQ(correct_f, diy_fp.f());
67 }
68
69 TEST(IsDenormal) {
70 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000,00000001);
71 CHECK(Double(min_double64).IsDenormal());
72 uint64_t bits = V8_2PART_UINT64_C(0x000FFFFF,FFFFFFFF);
73 CHECK(Double(bits).IsDenormal());
74 bits = V8_2PART_UINT64_C(0x00100000,00000000);
75 CHECK(!Double(bits).IsDenormal());
76 }
77
78 TEST(IsSpecial) {
79 CHECK(Double(V8_INFINITY).IsSpecial());
80 CHECK(Double(-V8_INFINITY).IsSpecial());
81 CHECK(Double(OS::nan_value()).IsSpecial());
82 uint64_t bits = V8_2PART_UINT64_C(0xFFF12345,00000000);
83 CHECK(Double(bits).IsSpecial());
84 // Denormals are not special:
85 CHECK(!Double(5e-324).IsSpecial());
86 // And some random numbers:
87 CHECK(!Double(0.0).IsSpecial());
88 CHECK(!Double(1.0).IsSpecial());
89 CHECK(!Double(1000000.0).IsSpecial());
90 CHECK(!Double(1e23).IsSpecial());
91 CHECK(!Double(1.7976931348623157e308).IsSpecial());
92 }
93
94 TEST(NormalizedBoundaries) {
95 DiyFp boundary_plus;
96 DiyFp boundary_minus;
97 DiyFp diy_fp = Double(1.5).AsNormalizedDiyFp();
98 Double(1.5).NormalizedBoundaries(&boundary_minus, &boundary_plus);
99 CHECK_EQ(diy_fp.e(), boundary_minus.e());
100 CHECK_EQ(diy_fp.e(), boundary_plus.e());
101 // 1.5 does not have a significand of the form 2^p (for some p).
102 // Therefore its boundaries are at the same distance.
103 CHECK_EQ(diy_fp.f() - boundary_minus.f(), boundary_plus.f() - diy_fp.f());
104 CHECK_EQ(static_cast<uint64_t>(1) << 10, diy_fp.f() - boundary_minus.f());
105
106 diy_fp = Double(1.0).AsNormalizedDiyFp();
107 Double(1.0).NormalizedBoundaries(&boundary_minus, &boundary_plus);
108 CHECK_EQ(diy_fp.e(), boundary_minus.e());
109 CHECK_EQ(diy_fp.e(), boundary_plus.e());
110 // 1.0 does have a significand of the form 2^p (for some p).
111 // Therefore its lower boundary is twice as close as the upper boundary.
112 CHECK_GT(boundary_plus.f() - diy_fp.f(), diy_fp.f() - boundary_minus.f());
113 CHECK_EQ(static_cast<uint64_t>(1) << 9, diy_fp.f() - boundary_minus.f());
114 CHECK_EQ(static_cast<uint64_t>(1) << 10, boundary_plus.f() - diy_fp.f());
115
116 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000,00000001);
117 diy_fp = Double(min_double64).AsNormalizedDiyFp();
118 Double(min_double64).NormalizedBoundaries(&boundary_minus, &boundary_plus);
119 CHECK_EQ(diy_fp.e(), boundary_minus.e());
120 CHECK_EQ(diy_fp.e(), boundary_plus.e());
121 // min-value does not have a significand of the form 2^p (for some p).
122 // Therefore its boundaries are at the same distance.
123 CHECK_EQ(diy_fp.f() - boundary_minus.f(), boundary_plus.f() - diy_fp.f());
124 // Denormals have their boundaries much closer.
125 CHECK_EQ(static_cast<uint64_t>(1) << 62, diy_fp.f() - boundary_minus.f());
126
127 uint64_t smallest_normal64 = V8_2PART_UINT64_C(0x00100000,00000000);
128 diy_fp = Double(smallest_normal64).AsNormalizedDiyFp();
129 Double(smallest_normal64).NormalizedBoundaries(&boundary_minus,
130 &boundary_plus);
131 CHECK_EQ(diy_fp.e(), boundary_minus.e());
132 CHECK_EQ(diy_fp.e(), boundary_plus.e());
133 // Even though the significand is of the form 2^p (for some p), its boundaries
134 // are at the same distance. (This is the only exception).
135 CHECK_EQ(diy_fp.f() - boundary_minus.f(), boundary_plus.f() - diy_fp.f());
136 CHECK_EQ(static_cast<uint64_t>(1) << 10, diy_fp.f() - boundary_minus.f());
137
138 uint64_t largest_denormal64 = V8_2PART_UINT64_C(0x000FFFFF,FFFFFFFF);
139 diy_fp = Double(largest_denormal64).AsNormalizedDiyFp();
140 Double(largest_denormal64).NormalizedBoundaries(&boundary_minus,
141 &boundary_plus);
142 CHECK_EQ(diy_fp.e(), boundary_minus.e());
143 CHECK_EQ(diy_fp.e(), boundary_plus.e());
144 CHECK_EQ(diy_fp.f() - boundary_minus.f(), boundary_plus.f() - diy_fp.f());
145 CHECK_EQ(static_cast<uint64_t>(1) << 11, diy_fp.f() - boundary_minus.f());
146
147 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff,ffffffff);
148 diy_fp = Double(max_double64).AsNormalizedDiyFp();
149 Double(max_double64).NormalizedBoundaries(&boundary_minus, &boundary_plus);
150 CHECK_EQ(diy_fp.e(), boundary_minus.e());
151 CHECK_EQ(diy_fp.e(), boundary_plus.e());
152 // max-value does not have a significand of the form 2^p (for some p).
153 // Therefore its boundaries are at the same distance.
154 CHECK_EQ(diy_fp.f() - boundary_minus.f(), boundary_plus.f() - diy_fp.f());
155 CHECK_EQ(static_cast<uint64_t>(1) << 10, diy_fp.f() - boundary_minus.f());
156 }
OLDNEW
« src/powers_ten.h ('K') | « test/cctest/test-diy_fp.cc ('k') | test/cctest/test-grisu3.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698