Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cpp/src/gandiva/precompiled/extended_math_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ POWER(float64, float64, float64)
#define ROUND_DECIMAL(TYPE) \
FORCE_INLINE \
gdv_##TYPE round_##TYPE##_int32(gdv_##TYPE number, gdv_int32 out_scale) { \
gdv_##TYPE scale_multiplier = \
static_cast<gdv_##TYPE>(get_scale_multiplier(out_scale)); \
gdv_float64 scale_multiplier = get_scale_multiplier(out_scale); \
return static_cast<gdv_##TYPE>( \
trunc(number * scale_multiplier + ((number > 0) ? 0.5 : -0.5)) / \
scale_multiplier); \
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/gandiva/precompiled/extended_math_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ TEST(TestExtendedMathOps, TestRoundDecimal) {
EXPECT_FLOAT_EQ(round_float32_int32(-1234.4567f, 3), -1234.457f);
EXPECT_FLOAT_EQ(round_float32_int32(-1234.4567f, -3), -1000);
EXPECT_FLOAT_EQ(round_float32_int32(1234.4567f, 0), 1234);
EXPECT_FLOAT_EQ(round_float32_int32(1.5499999523162842f, 1), 1.5f);
EXPECT_FLOAT_EQ(round_float32_int32(static_cast<float>(1.55), 1), 1.5f);
Comment thread
sgnkc marked this conversation as resolved.
Outdated
Comment thread
sgnkc marked this conversation as resolved.
Outdated
EXPECT_FLOAT_EQ(round_float32_int32(static_cast<float>(9.134123), 2), 9.13f);
EXPECT_FLOAT_EQ(round_float32_int32(static_cast<float>(-1.923), 1), -1.9f);

VerifyFuzzyEquals(round_float64_int32(1234.789, 2), 1234.79);
VerifyFuzzyEquals(round_float64_int32(1234.12345, -3), 1000);
Expand Down