You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "felipecrv (via GitHub)" <gi...@apache.org> on 2023/06/09 17:46:18 UTC
[GitHub] [arrow] felipecrv commented on a diff in pull request #35997: GH-35576: [C++] Make Decimal{128,256}::FromReal more accurate
felipecrv commented on code in PR #35997:
URL: https://github.com/apache/arrow/pull/35997#discussion_r1223808788
##########
cpp/src/arrow/util/decimal.cc:
##########
@@ -44,195 +45,291 @@ using internal::SafeLeftShift;
using internal::SafeSignedAdd;
using internal::uint128_t;
-Decimal128::Decimal128(const std::string& str) : Decimal128() {
- *this = Decimal128::FromString(str).ValueOrDie();
-}
+namespace {
-static constexpr auto kInt64DecimalDigits =
- static_cast<size_t>(std::numeric_limits<int64_t>::digits10);
-
-static constexpr uint64_t kUInt64PowersOfTen[kInt64DecimalDigits + 1] = {
- // clang-format off
- 1ULL,
- 10ULL,
- 100ULL,
- 1000ULL,
- 10000ULL,
- 100000ULL,
- 1000000ULL,
- 10000000ULL,
- 100000000ULL,
- 1000000000ULL,
- 10000000000ULL,
- 100000000000ULL,
- 1000000000000ULL,
- 10000000000000ULL,
- 100000000000000ULL,
- 1000000000000000ULL,
- 10000000000000000ULL,
- 100000000000000000ULL,
- 1000000000000000000ULL
- // clang-format on
+struct BaseDecimalRealConversion {
+ // Return 10**exp, with a fast lookup, assuming `exp` is withing bounds
Review Comment:
typo: withing -> within
##########
cpp/src/arrow/util/basic_decimal.cc:
##########
@@ -1188,14 +857,14 @@ BasicDecimal256& BasicDecimal256::operator<<=(uint32_t bits) {
if (bits == 0) {
return *this;
}
- int cross_word_shift = bits / 64;
- if (static_cast<size_t>(cross_word_shift) >= array_.size()) {
+ const int cross_word_shift = bits / 64;
+ if (cross_word_shift >= kWordWidth) {
Review Comment:
`kWordWidth` is the width of the decimal in words, right? Not the width of a single word. A bit of a confusing name.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org