js8544 commented on code in PR #36289:
URL: https://github.com/apache/arrow/pull/36289#discussion_r1264934794
##########
cpp/src/arrow/compute/kernels/scalar_round.cc:
##########
@@ -96,8 +117,29 @@ struct RoundUtil {
}
return (power >= 0) ? pow10 : (1 / pow10);
}
+
+ // Calculate powers of ten with arbitrary integer exponent
+ template <typename T>
+ static enable_if_integer_value<T> Pow10(int64_t power) {
+ DCHECK_GE(power, 0);
+ DCHECK_LE(power, std::numeric_limits<T>::digits10);
+ static constexpr uint64_t lut[] = {
+ Pow10Struct<0>::value, Pow10Struct<1>::value, Pow10Struct<2>::value,
+ Pow10Struct<3>::value, Pow10Struct<4>::value, Pow10Struct<5>::value,
+ Pow10Struct<6>::value, Pow10Struct<7>::value, Pow10Struct<8>::value,
+ Pow10Struct<9>::value, Pow10Struct<10>::value, Pow10Struct<11>::value,
+ Pow10Struct<12>::value, Pow10Struct<13>::value, Pow10Struct<14>::value,
+ Pow10Struct<15>::value, Pow10Struct<16>::value, Pow10Struct<17>::value,
+ Pow10Struct<18>::value, Pow10Struct<19>::value};
+
+ return static_cast<T>(lut[power]);
+ }
};
Review Comment:
Now it does seem like an overkill to me. I've changed it to the simpler way.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]