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

Side by Side Diff: runtime/third_party/double-conversion/test/cctest/test-double.cc

Issue 8632010: double-conversion drop. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 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
OLDNEW
(Empty)
1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2
3 #include <stdlib.h>
4
5 #include "cctest.h"
6 #include "diy-fp.h"
7 #include "double.h"
8 #include "utils.h"
9
10
11 using namespace double_conversion;
12
13
14 TEST(Uint64Conversions) {
15 // Start by checking the byte-order.
16 uint64_t ordered = UINT64_2PART_C(0x01234567, 89ABCDEF);
17 CHECK_EQ(3512700564088504e-318, Double(ordered).value());
18
19 uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
20 CHECK_EQ(5e-324, Double(min_double64).value());
21
22 uint64_t max_double64 = UINT64_2PART_C(0x7fefffff, ffffffff);
23 CHECK_EQ(1.7976931348623157e308, Double(max_double64).value());
24 }
25
26 TEST(AsDiyFp) {
27 uint64_t ordered = UINT64_2PART_C(0x01234567, 89ABCDEF);
28 DiyFp diy_fp = Double(ordered).AsDiyFp();
29 CHECK_EQ(0x12 - 0x3FF - 52, diy_fp.e());
30 // The 52 mantissa bits, plus the implicit 1 in bit 52 as a UINT64.
31 CHECK(UINT64_2PART_C(0x00134567, 89ABCDEF) == diy_fp.f()); // NOLINT
32
33 uint64_t min_double64 = UINT64_2PART_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 CHECK(1 == diy_fp.f()); // NOLINT
38
39 uint64_t max_double64 = UINT64_2PART_C(0x7fefffff, ffffffff);
40 diy_fp = Double(max_double64).AsDiyFp();
41 CHECK_EQ(0x7FE - 0x3FF - 52, diy_fp.e());
42 CHECK(UINT64_2PART_C(0x001fffff, ffffffff) == diy_fp.f()); // NOLINT
43 }
44
45
46 TEST(AsNormalizedDiyFp) {
47 uint64_t ordered = UINT64_2PART_C(0x01234567, 89ABCDEF);
48 DiyFp diy_fp = Double(ordered).AsNormalizedDiyFp();
49 CHECK_EQ(0x12 - 0x3FF - 52 - 11, diy_fp.e());
50 CHECK((UINT64_2PART_C(0x00134567, 89ABCDEF) << 11) ==
51 diy_fp.f()); // NOLINT
52
53 uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
54 diy_fp = Double(min_double64).AsNormalizedDiyFp();
55 CHECK_EQ(-0x3FF - 52 + 1 - 63, diy_fp.e());
56 // This is a denormal; so no hidden bit.
57 CHECK(UINT64_2PART_C(0x80000000, 00000000) == diy_fp.f()); // NOLINT
58
59 uint64_t max_double64 = UINT64_2PART_C(0x7fefffff, ffffffff);
60 diy_fp = Double(max_double64).AsNormalizedDiyFp();
61 CHECK_EQ(0x7FE - 0x3FF - 52 - 11, diy_fp.e());
62 CHECK((UINT64_2PART_C(0x001fffff, ffffffff) << 11) ==
63 diy_fp.f()); // NOLINT
64 }
65
66
67 TEST(IsDenormal) {
68 uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
69 CHECK(Double(min_double64).IsDenormal());
70 uint64_t bits = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
71 CHECK(Double(bits).IsDenormal());
72 bits = UINT64_2PART_C(0x00100000, 00000000);
73 CHECK(!Double(bits).IsDenormal());
74 }
75
76
77 TEST(IsSpecial) {
78 CHECK(Double(Double::Infinity()).IsSpecial());
79 CHECK(Double(-Double::Infinity()).IsSpecial());
80 CHECK(Double(Double::NaN()).IsSpecial());
81 uint64_t bits = UINT64_2PART_C(0xFFF12345, 00000000);
82 CHECK(Double(bits).IsSpecial());
83 // Denormals are not special:
84 CHECK(!Double(5e-324).IsSpecial());
85 CHECK(!Double(-5e-324).IsSpecial());
86 // And some random numbers:
87 CHECK(!Double(0.0).IsSpecial());
88 CHECK(!Double(-0.0).IsSpecial());
89 CHECK(!Double(1.0).IsSpecial());
90 CHECK(!Double(-1.0).IsSpecial());
91 CHECK(!Double(1000000.0).IsSpecial());
92 CHECK(!Double(-1000000.0).IsSpecial());
93 CHECK(!Double(1e23).IsSpecial());
94 CHECK(!Double(-1e23).IsSpecial());
95 CHECK(!Double(1.7976931348623157e308).IsSpecial());
96 CHECK(!Double(-1.7976931348623157e308).IsSpecial());
97 }
98
99
100 TEST(IsInfinite) {
101 CHECK(Double(Double::Infinity()).IsInfinite());
102 CHECK(Double(-Double::Infinity()).IsInfinite());
103 CHECK(!Double(Double::NaN()).IsInfinite());
104 CHECK(!Double(0.0).IsInfinite());
105 CHECK(!Double(-0.0).IsInfinite());
106 CHECK(!Double(1.0).IsInfinite());
107 CHECK(!Double(-1.0).IsInfinite());
108 uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
109 CHECK(!Double(min_double64).IsInfinite());
110 }
111
112
113 TEST(IsNan) {
114 CHECK(Double(Double::NaN()).IsNan());
115 uint64_t other_nan = UINT64_2PART_C(0xFFFFFFFF, 00000001);
116 CHECK(Double(other_nan).IsNan());
117 CHECK(!Double(Double::Infinity()).IsNan());
118 CHECK(!Double(-Double::Infinity()).IsNan());
119 CHECK(!Double(0.0).IsNan());
120 CHECK(!Double(-0.0).IsNan());
121 CHECK(!Double(1.0).IsNan());
122 CHECK(!Double(-1.0).IsNan());
123 uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
124 CHECK(!Double(min_double64).IsNan());
125 }
126
127
128 TEST(Sign) {
129 CHECK_EQ(1, Double(1.0).Sign());
130 CHECK_EQ(1, Double(Double::Infinity()).Sign());
131 CHECK_EQ(-1, Double(-Double::Infinity()).Sign());
132 CHECK_EQ(1, Double(0.0).Sign());
133 CHECK_EQ(-1, Double(-0.0).Sign());
134 uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
135 CHECK_EQ(1, Double(min_double64).Sign());
136 }
137
138
139 TEST(NormalizedBoundaries) {
140 DiyFp boundary_plus;
141 DiyFp boundary_minus;
142 DiyFp diy_fp = Double(1.5).AsNormalizedDiyFp();
143 Double(1.5).NormalizedBoundaries(&boundary_minus, &boundary_plus);
144 CHECK_EQ(diy_fp.e(), boundary_minus.e());
145 CHECK_EQ(diy_fp.e(), boundary_plus.e());
146 // 1.5 does not have a significand of the form 2^p (for some p).
147 // Therefore its boundaries are at the same distance.
148 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
149 CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); // NOLINT
150
151 diy_fp = Double(1.0).AsNormalizedDiyFp();
152 Double(1.0).NormalizedBoundaries(&boundary_minus, &boundary_plus);
153 CHECK_EQ(diy_fp.e(), boundary_minus.e());
154 CHECK_EQ(diy_fp.e(), boundary_plus.e());
155 // 1.0 does have a significand of the form 2^p (for some p).
156 // Therefore its lower boundary is twice as close as the upper boundary.
157 CHECK(boundary_plus.f() - diy_fp.f() > diy_fp.f() - boundary_minus.f());
158 CHECK((1 << 9) == diy_fp.f() - boundary_minus.f()); // NOLINT
159 CHECK((1 << 10) == boundary_plus.f() - diy_fp.f()); // NOLINT
160
161 uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
162 diy_fp = Double(min_double64).AsNormalizedDiyFp();
163 Double(min_double64).NormalizedBoundaries(&boundary_minus, &boundary_plus);
164 CHECK_EQ(diy_fp.e(), boundary_minus.e());
165 CHECK_EQ(diy_fp.e(), boundary_plus.e());
166 // min-value does not have a significand of the form 2^p (for some p).
167 // Therefore its boundaries are at the same distance.
168 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
169 // Denormals have their boundaries much closer.
170 CHECK((static_cast<uint64_t>(1) << 62) ==
171 diy_fp.f() - boundary_minus.f()); // NOLINT
172
173 uint64_t smallest_normal64 = UINT64_2PART_C(0x00100000, 00000000);
174 diy_fp = Double(smallest_normal64).AsNormalizedDiyFp();
175 Double(smallest_normal64).NormalizedBoundaries(&boundary_minus,
176 &boundary_plus);
177 CHECK_EQ(diy_fp.e(), boundary_minus.e());
178 CHECK_EQ(diy_fp.e(), boundary_plus.e());
179 // Even though the significand is of the form 2^p (for some p), its boundaries
180 // are at the same distance. (This is the only exception).
181 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
182 CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); // NOLINT
183
184 uint64_t largest_denormal64 = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
185 diy_fp = Double(largest_denormal64).AsNormalizedDiyFp();
186 Double(largest_denormal64).NormalizedBoundaries(&boundary_minus,
187 &boundary_plus);
188 CHECK_EQ(diy_fp.e(), boundary_minus.e());
189 CHECK_EQ(diy_fp.e(), boundary_plus.e());
190 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
191 CHECK((1 << 11) == diy_fp.f() - boundary_minus.f()); // NOLINT
192
193 uint64_t max_double64 = UINT64_2PART_C(0x7fefffff, ffffffff);
194 diy_fp = Double(max_double64).AsNormalizedDiyFp();
195 Double(max_double64).NormalizedBoundaries(&boundary_minus, &boundary_plus);
196 CHECK_EQ(diy_fp.e(), boundary_minus.e());
197 CHECK_EQ(diy_fp.e(), boundary_plus.e());
198 // max-value does not have a significand of the form 2^p (for some p).
199 // Therefore its boundaries are at the same distance.
200 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
201 CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); // NOLINT
202 }
203
204
205 TEST(NextDouble) {
206 CHECK_EQ(4e-324, Double(0.0).NextDouble());
207 CHECK_EQ(0.0, Double(-0.0).NextDouble());
208 CHECK_EQ(-0.0, Double(-4e-324).NextDouble());
209 Double d0(-4e-324);
210 Double d1(d0.NextDouble());
211 Double d2(d1.NextDouble());
212 CHECK_EQ(-0.0, d1.value());
213 CHECK_EQ(0.0, d2.value());
214 CHECK_EQ(4e-324, d2.NextDouble());
215 CHECK_EQ(-1.7976931348623157e308, Double(-Double::Infinity()).NextDouble());
216 CHECK_EQ(Double::Infinity(),
217 Double(UINT64_2PART_C(0x7fefffff, ffffffff)).NextDouble());
218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698