| 31 | namespace impala { |
| 32 | |
| 33 | TEST(MultiPrecisionIntTest, Conversion) { |
| 34 | int128_t x = 0; |
| 35 | int256_t y = 0; |
| 36 | EXPECT_TRUE(ConvertToInt256(x) == 0); |
| 37 | |
| 38 | x = -1; |
| 39 | EXPECT_TRUE(ConvertToInt256(x) == -1); |
| 40 | |
| 41 | x = 1; |
| 42 | EXPECT_TRUE(ConvertToInt256(x) == 1); |
| 43 | |
| 44 | x = numeric_limits<int32_t>::max(); |
| 45 | EXPECT_TRUE(ConvertToInt256(x) == numeric_limits<int32_t>::max()); |
| 46 | |
| 47 | x = numeric_limits<int32_t>::min(); |
| 48 | EXPECT_TRUE(ConvertToInt256(x) == numeric_limits<int32_t>::min()); |
| 49 | |
| 50 | x = numeric_limits<int64_t>::max(); |
| 51 | EXPECT_TRUE(ConvertToInt256(x) == numeric_limits<int64_t>::max()); |
| 52 | |
| 53 | x = numeric_limits<int64_t>::min(); |
| 54 | EXPECT_TRUE(ConvertToInt256(x) == numeric_limits<int64_t>::min()); |
| 55 | |
| 56 | x = numeric_limits<int64_t>::max(); |
| 57 | x *= 1000; |
| 58 | y = numeric_limits<int64_t>::max(); |
| 59 | y *= 1000; |
| 60 | EXPECT_TRUE(ConvertToInt256(x) == y); |
| 61 | |
| 62 | x = -numeric_limits<int64_t>::max(); |
| 63 | x *= 1000; |
| 64 | y = -numeric_limits<int64_t>::max(); |
| 65 | y *= 1000; |
| 66 | EXPECT_TRUE(ConvertToInt256(x) == y); |
| 67 | |
| 68 | // Note: numer_limits<> doesn't work for int128_t. |
| 69 | static int128_t MAX_VALUE; |
| 70 | memset(&MAX_VALUE, 255, sizeof(MAX_VALUE)); |
| 71 | uint8_t* buf = reinterpret_cast<uint8_t*>(&MAX_VALUE); |
| 72 | buf[15] = 127; |
| 73 | |
| 74 | bool overflow = false; |
| 75 | EXPECT_TRUE(ConvertToInt128(ConvertToInt256(x), MAX_VALUE, &overflow) == x); |
| 76 | EXPECT_FALSE(overflow); |
| 77 | } |
| 78 | |
| 79 | TEST(MultiPrecisionIntTest, HighLowBits) { |
| 80 | // x = 0x0f0e0d0c0b0a09080706050403020100 |
nothing calls this directly
no test coverage detected