Skip to content

Commit

Permalink
make RoundedRightShift a no-op
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroshade committed Sep 30, 2024
1 parent 9fda783 commit af8c722
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions cpp/src/arrow/util/decimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct DecimalRealConversion : public BaseDecimalRealConversion {
constexpr int kMantissaDigits = RealTraits<Real>::kMantissaDigits;

// to avoid precision and rounding issues, we'll unconditionally
// throw Decimal32 to the approx algorithm instead. (GH-44216)
// throw Decimal32 to the approx algorithm instead. (GH-44216)
if constexpr (std::is_base_of_v<BasicDecimal32, DecimalType>) {
return Derived::FromPositiveRealApprox(real, precision, scale);
}
Expand Down Expand Up @@ -258,29 +258,10 @@ struct Decimal32RealConversion
using Base::PowerOfTen;

static Decimal32 RoundedRightShift(const Decimal32& x, int bits) {
if (bits == 0) {
return x;
}

int32_t result = x.value();
uint32_t shifted = 0;
if (bits > 0) {
shifted = (result << (32 - bits));
result >>= bits;
}
constexpr uint32_t kHalf = 0x80000000;
if (shifted > kHalf) {
// strictly more than half => round up
result += 1;
} else if (shifted == kHalf) {
// exactly half => round to even
if ((result & 1) != 0) {
result += 1;
}
} else {
// strictly less than half => round down
}
return Decimal32(result);
// currently we *only* push to the Approx method for Decimal32
// so this should never get called.
DCHECK(false);
return x;
}

template <typename Real>
Expand Down

0 comments on commit af8c722

Please sign in to comment.