OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "net/base/int128.h" | 7 #include "net/base/int128.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 | 10 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 for (int i = 0; i < 64; ++i) { | 223 for (int i = 0; i < 64; ++i) { |
224 for (int j = 0; j < 64; ++j) { | 224 for (int j = 0; j < 64; ++j) { |
225 a = uint128(1) << i; | 225 a = uint128(1) << i; |
226 b = uint128(1) << j; | 226 b = uint128(1) << j; |
227 c = a * b; | 227 c = a * b; |
228 EXPECT_EQ(uint128(1) << (i+j), c); | 228 EXPECT_EQ(uint128(1) << (i+j), c); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 // Verified with dc. | 232 // Verified with dc. |
233 a = uint128(0xffffeeeeddddccccULL, 0xbbbbaaaa99998888ULL); | 233 a = uint128(GG_ULONGLONG(0xffffeeeeddddcccc), |
234 b = uint128(0x7777666655554444ULL, 0x3333222211110000ULL); | 234 GG_ULONGLONG(0xbbbbaaaa99998888)); |
| 235 b = uint128(GG_ULONGLONG(0x7777666655554444), |
| 236 GG_ULONGLONG(0x3333222211110000)); |
235 c = a * b; | 237 c = a * b; |
236 EXPECT_EQ(uint128(0x530EDA741C71D4C3ULL, 0xBF25975319080000ULL), c); | 238 EXPECT_EQ(uint128(GG_ULONGLONG(0x530EDA741C71D4C3), |
| 239 GG_ULONGLONG(0xBF25975319080000)), c); |
237 EXPECT_EQ(0, c - b * a); | 240 EXPECT_EQ(0, c - b * a); |
238 EXPECT_EQ(a*a - b*b, (a+b) * (a-b)); | 241 EXPECT_EQ(a*a - b*b, (a+b) * (a-b)); |
239 | 242 |
240 // Verified with dc. | 243 // Verified with dc. |
241 a = uint128(0x0123456789abcdefULL, 0xfedcba9876543210ULL); | 244 a = uint128(GG_ULONGLONG(0x0123456789abcdef), |
242 b = uint128(0x02468ace13579bdfULL, 0xfdb97531eca86420ULL); | 245 GG_ULONGLONG(0xfedcba9876543210)); |
| 246 b = uint128(GG_ULONGLONG(0x02468ace13579bdf), |
| 247 GG_ULONGLONG(0xfdb97531eca86420)); |
243 c = a * b; | 248 c = a * b; |
244 EXPECT_EQ(uint128(0x97a87f4f261ba3f2ULL, 0x342d0bbf48948200ULL), c); | 249 EXPECT_EQ(uint128(GG_ULONGLONG(0x97a87f4f261ba3f2), |
| 250 GG_ULONGLONG(0x342d0bbf48948200)), c); |
245 EXPECT_EQ(0, c - b * a); | 251 EXPECT_EQ(0, c - b * a); |
246 EXPECT_EQ(a*a - b*b, (a+b) * (a-b)); | 252 EXPECT_EQ(a*a - b*b, (a+b) * (a-b)); |
247 } | 253 } |
248 | 254 |
249 TEST(Int128, AliasTests) { | 255 TEST(Int128, AliasTests) { |
250 uint128 x1(1, 2); | 256 uint128 x1(1, 2); |
251 uint128 x2(2, 4); | 257 uint128 x2(2, 4); |
252 x1 += x1; | 258 x1 += x1; |
253 EXPECT_EQ(x2, x1); | 259 EXPECT_EQ(x2, x1); |
254 | 260 |
255 uint128 x3(1, 1ull << 63); | 261 uint128 x3(1, 1ull << 63); |
256 uint128 x4(3, 0); | 262 uint128 x4(3, 0); |
257 x3 += x3; | 263 x3 += x3; |
258 EXPECT_EQ(x4, x3); | 264 EXPECT_EQ(x4, x3); |
259 } | 265 } |
OLD | NEW |