40 #include <google/protobuf/port_def.inc>
259 TEST(Int128, OperatorAssignReturnRef) {
286 for (
int i = 0;
i < 64; ++
i) {
287 for (
int j = 0; j < 64; ++j) {
296 a =
uint128(PROTOBUF_ULONGLONG(0xffffeeeeddddcccc),
297 PROTOBUF_ULONGLONG(0xbbbbaaaa99998888));
298 b =
uint128(PROTOBUF_ULONGLONG(0x7777666655554444),
299 PROTOBUF_ULONGLONG(0x3333222211110000));
302 PROTOBUF_ULONGLONG(0xBF25975319080000)),
308 a =
uint128(PROTOBUF_ULONGLONG(0x0123456789abcdef),
309 PROTOBUF_ULONGLONG(0xfedcba9876543210));
310 b =
uint128(PROTOBUF_ULONGLONG(0x02468ace13579bdf),
311 PROTOBUF_ULONGLONG(0xfdb97531eca86420));
314 PROTOBUF_ULONGLONG(0x342d0bbf48948200)),
332 #ifdef PROTOBUF_HAS_DEATH_TEST
333 TEST(Int128, DivideByZeroCheckFails) {
336 EXPECT_DEATH(
a /
b,
"Division or mod by zero:");
338 EXPECT_DEATH(
a /
b,
"Division or mod by zero:");
341 TEST(Int128, ModByZeroCheckFails) {
344 EXPECT_DEATH(
a %
b,
"Division or mod by zero:");
346 EXPECT_DEATH(
a %
b,
"Division or mod by zero:");
348 #endif // PROTOBUF_HAS_DEATH_TEST
362 a =
uint128(PROTOBUF_ULONGLONG(0x530eda741c71d4c3),
363 PROTOBUF_ULONGLONG(0xbf25975319080000));
364 q =
uint128(PROTOBUF_ULONGLONG(0x4de2cab081),
365 PROTOBUF_ULONGLONG(0x14c34ab4676e4bab));
403 uint128 expected_r(PROTOBUF_ULONGLONG(0x29876d3a0e38ea61),
404 PROTOBUF_ULONGLONG(0xdf92cba98c83ffff));
421 TEST(Int128, DivideAndModRandomInputs) {
422 const int kNumIters = 1 << 18;
423 for (
int i = 0;
i < kNumIters; ++
i) {
435 #ifdef GOOGLE_PROTOBUF_HAS_CONSTEXPR
436 TEST(Int128, ConstexprTest) {
437 constexpr uint128 zero;
438 constexpr uint128 one = 1;
439 constexpr uint128_pod pod = {2, 3};
440 constexpr uint128 from_pod = pod;
441 constexpr uint128 minus_two = -2;
447 TEST(Int128, Traits) {
452 #endif // GOOGLE_PROTOBUF_HAS_CONSTEXPR
457 std::ios_base::fmtflags
flags;
458 std::streamsize
width;
463 {
uint128(0), std::ios::dec, 0,
'_',
"0"},
464 {
uint128(0), std::ios::oct, 0,
'_',
"0"},
465 {
uint128(0), std::ios::hex, 0,
'_',
"0"},
467 {
uint128(0, -1), std::ios::dec, 0,
'_',
"18446744073709551615"},
468 {
uint128(0, -1), std::ios::oct, 0,
'_',
"1777777777777777777777"},
469 {
uint128(0, -1), std::ios::hex, 0,
'_',
"ffffffffffffffff"},
470 {
uint128(1, 0), std::ios::dec, 0,
'_',
"18446744073709551616"},
471 {
uint128(1, 0), std::ios::oct, 0,
'_',
"2000000000000000000000"},
472 {
uint128(1, 0), std::ios::hex, 0,
'_',
"10000000000000000"},
474 {
uint128(PROTOBUF_ULONGLONG(0x8000000000000000), 0), std::ios::dec, 0,
475 '_',
"170141183460469231731687303715884105728"},
476 {
uint128(PROTOBUF_ULONGLONG(0x8000000000000000), 0), std::ios::oct, 0,
477 '_',
"2000000000000000000000000000000000000000000"},
478 {
uint128(PROTOBUF_ULONGLONG(0x8000000000000000), 0), std::ios::hex, 0,
479 '_',
"80000000000000000000000000000000"},
481 {
uint128(-1, -1), std::ios::dec, 0,
'_',
482 "340282366920938463463374607431768211455"},
483 {
uint128(-1, -1), std::ios::oct, 0,
'_',
484 "3777777777777777777777777777777777777777777"},
485 {
uint128(-1, -1), std::ios::hex, 0,
'_',
486 "ffffffffffffffffffffffffffffffff"},
488 {
uint128(-1, -1), std::ios::hex | std::ios::uppercase, 0,
'_',
489 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"},
491 {
uint128(1), std::ios::dec | std::ios::showbase, 0,
'_',
"1"},
492 {
uint128(1), std::ios::oct | std::ios::showbase, 0,
'_',
"01"},
493 {
uint128(1), std::ios::hex | std::ios::showbase, 0,
'_',
"0x1"},
495 {
uint128(0), std::ios::dec | std::ios::showbase, 0,
'_',
"0"},
496 {
uint128(0), std::ios::oct | std::ios::showbase, 0,
'_',
"0"},
497 {
uint128(0), std::ios::hex | std::ios::showbase, 0,
'_',
"0"},
499 {
uint128(1), std::ios::dec | std::ios::showpos, 0,
'_',
"1"},
501 {
uint128(9), std::ios::dec, 6,
'_',
"_____9"},
502 {
uint128(12345), std::ios::dec, 6,
'_',
"_12345"},
508 std::ostringstream os;
511 os.fill(cases[
i].fill);