Skip to content

Commit bf1ccf2

Browse files
committed
fix: remove unrelated codes
1 parent 78a6517 commit bf1ccf2

File tree

3 files changed

+12
-43
lines changed

3 files changed

+12
-43
lines changed

src/iceberg/util/decimal.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@
3333
#include <cmath>
3434
#include <cstddef>
3535
#include <cstdint>
36-
#include <cstring>
3736
#include <format>
3837
#include <iomanip>
39-
#include <iostream>
4038
#include <limits>
41-
#include <ostream>
4239
#include <sstream>
4340
#include <string>
4441
#include <string_view>
@@ -451,8 +448,6 @@ Result<Decimal> Decimal::FromString(std::string_view str, int32_t* precision,
451448
parsed_scale = static_cast<int32_t>(dec.fractional_digits.size());
452449
}
453450

454-
// Index 1 is the high part, index 0 is the low part
455-
std::array<uint64_t, 2> result_array = {0, 0};
456451
uint128_t value = 0;
457452
ShiftAndAdd(dec.while_digits, value);
458453
ShiftAndAdd(dec.fractional_digits, value);
@@ -791,7 +786,7 @@ struct DecimalRealConversion {
791786
return x;
792787
}
793788

794-
/// An approximate conversion from Decimal128 to Real that guarantees:
789+
/// An approximate conversion from Decimal to Real that guarantees:
795790
/// 1. If the decimal is an integer, the conversion is exact.
796791
/// 2. If the number of fractional digits is <= RealTraits<Real>::kMantissaDigits (e.g.
797792
/// 8 for float and 16 for double), the conversion is within 1 ULP of the exact

src/iceberg/util/decimal.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -257,22 +257,6 @@ class ICEBERG_EXPORT Decimal {
257257
friend Decimal operator%(const Decimal& lhs, const Decimal& rhs);
258258

259259
private:
260-
static constexpr int32_t highIndex() {
261-
if constexpr (std::endian::native == std::endian::little) {
262-
return 1;
263-
} else {
264-
return 0;
265-
}
266-
}
267-
268-
static constexpr int32_t lowIndex() {
269-
if constexpr (std::endian::native == std::endian::little) {
270-
return 0;
271-
} else {
272-
return 1;
273-
}
274-
}
275-
276260
int128_t data_{0};
277261
};
278262

test/decimal_test.cc

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
#include <bit>
2424
#include <cmath>
2525
#include <cstdint>
26-
#include <vector>
2726

2827
#include <gmock/gmock.h>
2928
#include <gtest/gtest.h>
30-
#include <sys/types.h>
3129

3230
#include "iceberg/util/int128.h"
3331
#include "matchers.h"
@@ -48,11 +46,6 @@ void AssertDecimalFromString(const std::string& s, const Decimal& expected,
4846
EXPECT_EQ(expected_scale, scale);
4947
}
5048

51-
Decimal DecimalFromInt128(int128_t value) {
52-
return {static_cast<int64_t>(value >> 64),
53-
static_cast<uint64_t>(value & 0xFFFFFFFFFFFFFFFFULL)};
54-
}
55-
5649
} // namespace
5750

5851
TEST(DecimalTest, Basics) {
@@ -1094,11 +1087,10 @@ TEST(DecimalTestFunctionality, Multiply) {
10941087
for (auto x : std::vector<int128_t>{-INT64_MAX, -INT32_MAX, 0, INT32_MAX, INT64_MAX}) {
10951088
for (auto y :
10961089
std::vector<int128_t>{-INT32_MAX, -32, -2, -1, 0, 1, 2, 32, INT32_MAX}) {
1097-
Decimal decimal_x = DecimalFromInt128(x);
1098-
Decimal decimal_y = DecimalFromInt128(y);
1090+
Decimal decimal_x(x);
1091+
Decimal decimal_y(y);
10991092
Decimal result = decimal_x * decimal_y;
1100-
EXPECT_EQ(DecimalFromInt128(x * y), result)
1101-
<< " x: " << decimal_x << " y: " << decimal_y;
1093+
EXPECT_EQ(Decimal(x * y), result) << " x: " << decimal_x << " y: " << decimal_y;
11021094
}
11031095
}
11041096
}
@@ -1111,11 +1103,10 @@ TEST(DecimalTestFunctionality, Divide) {
11111103

11121104
for (auto x : std::vector<int128_t>{-INT64_MAX, -INT32_MAX, 0, INT32_MAX, INT64_MAX}) {
11131105
for (auto y : std::vector<int128_t>{-INT32_MAX, -32, -2, -1, 1, 2, 32, INT32_MAX}) {
1114-
Decimal decimal_x = DecimalFromInt128(x);
1115-
Decimal decimal_y = DecimalFromInt128(y);
1106+
Decimal decimal_x(x);
1107+
Decimal decimal_y(y);
11161108
Decimal result = decimal_x / decimal_y;
1117-
EXPECT_EQ(DecimalFromInt128(x / y), result)
1118-
<< " x: " << decimal_x << " y: " << decimal_y;
1109+
EXPECT_EQ(Decimal(x / y), result) << " x: " << decimal_x << " y: " << decimal_y;
11191110
}
11201111
}
11211112
}
@@ -1129,11 +1120,10 @@ TEST(DecimalTestFunctionality, Modulo) {
11291120
// Test some edge cases
11301121
for (auto x : std::vector<int128_t>{-INT64_MAX, -INT32_MAX, 0, INT32_MAX, INT64_MAX}) {
11311122
for (auto y : std::vector<int128_t>{-INT32_MAX, -32, -2, -1, 1, 2, 32, INT32_MAX}) {
1132-
Decimal decimal_x = DecimalFromInt128(x);
1133-
Decimal decimal_y = DecimalFromInt128(y);
1123+
Decimal decimal_x(x);
1124+
Decimal decimal_y(y);
11341125
Decimal result = decimal_x % decimal_y;
1135-
EXPECT_EQ(DecimalFromInt128(x % y), result)
1136-
<< " x: " << decimal_x << " y: " << decimal_y;
1126+
EXPECT_EQ(Decimal(x % y), result) << " x: " << decimal_x << " y: " << decimal_y;
11371127
}
11381128
}
11391129
}
@@ -1206,8 +1196,8 @@ TEST(DecimalTestFunctionality, FitsInPrecision) {
12061196

12071197
TEST(DecimalTest, LeftShift) {
12081198
auto check = [](int128_t x, uint32_t bits) {
1209-
auto expected = DecimalFromInt128(x << bits);
1210-
auto actual = DecimalFromInt128(x) << bits;
1199+
auto expected = Decimal(x << bits);
1200+
auto actual = Decimal(x) << bits;
12111201
ASSERT_EQ(actual.low(), expected.low());
12121202
ASSERT_EQ(actual.high(), expected.high());
12131203
};

0 commit comments

Comments
 (0)