github-actions[bot] commented on code in PR #26822: URL: https://github.com/apache/doris/pull/26822#discussion_r1390332045
########## be/src/vec/common/int_exp.h: ########## @@ -53,36 +53,120 @@ } // namespace exp_details -/// On overflow, the function returns unspecified value. - -inline uint64_t int_exp2(int x) { - return 1ULL << x; -} - inline uint64_t int_exp10(int x) { - if (x < 0) return 0; - if (x > 19) return std::numeric_limits<uint64_t>::max(); + if (x < 0) { + return 0; + } + if (x > 19) { + return std::numeric_limits<uint64_t>::max(); + } return exp_details::get_exp<uint64_t, 10, 20>(x); } namespace common { -inline constexpr std::int32_t exp10_i32(int x) { - return exp_details::get_exp<std::int32_t, 10, 10>(x); +constexpr inline int exp10_i32(int x) { + if (x < 0) { + return 0; + } + if (x > 9) { Review Comment: warning: 9 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp if (x > 9) { ^ ``` ########## be/src/vec/common/int_exp.h: ########## @@ -53,36 +53,120 @@ } // namespace exp_details -/// On overflow, the function returns unspecified value. - -inline uint64_t int_exp2(int x) { - return 1ULL << x; -} - inline uint64_t int_exp10(int x) { - if (x < 0) return 0; - if (x > 19) return std::numeric_limits<uint64_t>::max(); + if (x < 0) { + return 0; + } + if (x > 19) { + return std::numeric_limits<uint64_t>::max(); + } return exp_details::get_exp<uint64_t, 10, 20>(x); } namespace common { -inline constexpr std::int32_t exp10_i32(int x) { - return exp_details::get_exp<std::int32_t, 10, 10>(x); +constexpr inline int exp10_i32(int x) { + if (x < 0) { + return 0; + } + if (x > 9) { + return std::numeric_limits<int>::max(); + } + + constexpr int values[] = {1, 10, 100, 1000, 10000, + 100000, 1000000, 10000000, 100000000, 1000000000}; + return values[x]; } -inline constexpr std::int64_t exp10_i64(int x) { - return exp_details::get_exp<std::int64_t, 10, 19>(x); +constexpr inline int64_t exp10_i64(int x) { + if (x < 0) { + return 0; + } + if (x > 18) { Review Comment: warning: 18 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp if (x > 18) { ^ ``` ########## be/src/vec/common/int_exp.h: ########## @@ -53,36 +53,120 @@ constexpr T get_exp(std::size_t x) { } // namespace exp_details -/// On overflow, the function returns unspecified value. - -inline uint64_t int_exp2(int x) { - return 1ULL << x; -} - inline uint64_t int_exp10(int x) { - if (x < 0) return 0; - if (x > 19) return std::numeric_limits<uint64_t>::max(); + if (x < 0) { + return 0; + } + if (x > 19) { Review Comment: warning: 19 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp if (x > 19) { ^ ``` ########## be/src/vec/common/int_exp.h: ########## @@ -53,36 +53,120 @@ } // namespace exp_details -/// On overflow, the function returns unspecified value. - -inline uint64_t int_exp2(int x) { - return 1ULL << x; -} - inline uint64_t int_exp10(int x) { - if (x < 0) return 0; - if (x > 19) return std::numeric_limits<uint64_t>::max(); + if (x < 0) { + return 0; + } + if (x > 19) { + return std::numeric_limits<uint64_t>::max(); + } return exp_details::get_exp<uint64_t, 10, 20>(x); } namespace common { -inline constexpr std::int32_t exp10_i32(int x) { - return exp_details::get_exp<std::int32_t, 10, 10>(x); +constexpr inline int exp10_i32(int x) { + if (x < 0) { + return 0; + } + if (x > 9) { + return std::numeric_limits<int>::max(); + } + + constexpr int values[] = {1, 10, 100, 1000, 10000, + 100000, 1000000, 10000000, 100000000, 1000000000}; + return values[x]; } -inline constexpr std::int64_t exp10_i64(int x) { - return exp_details::get_exp<std::int64_t, 10, 19>(x); +constexpr inline int64_t exp10_i64(int x) { + if (x < 0) { + return 0; + } + if (x > 18) { + return std::numeric_limits<int64_t>::max(); + } + + constexpr int64_t values[] = {1LL, + 10LL, + 100LL, + 1000LL, + 10000LL, + 100000LL, + 1000000LL, + 10000000LL, + 100000000LL, + 1000000000LL, + 10000000000LL, + 100000000000LL, + 1000000000000LL, + 10000000000000LL, + 100000000000000LL, + 1000000000000000LL, + 10000000000000000LL, + 100000000000000000LL, + 1000000000000000000LL}; + return values[x]; } -inline constexpr __int128 exp10_i128(int x) { - return exp_details::get_exp<__int128, 10, 39>(x); +constexpr inline __int128 exp10_i128(int x) { + if (x < 0) { + return 0; + } + if (x > 38) { + return std::numeric_limits<__int128>::max(); + } + + constexpr __int128 values[] = { + static_cast<__int128>(1LL), + static_cast<__int128>(10LL), + static_cast<__int128>(100LL), + static_cast<__int128>(1000LL), + static_cast<__int128>(10000LL), + static_cast<__int128>(100000LL), + static_cast<__int128>(1000000LL), + static_cast<__int128>(10000000LL), + static_cast<__int128>(100000000LL), + static_cast<__int128>(1000000000LL), + static_cast<__int128>(10000000000LL), + static_cast<__int128>(100000000000LL), + static_cast<__int128>(1000000000000LL), + static_cast<__int128>(10000000000000LL), + static_cast<__int128>(100000000000000LL), + static_cast<__int128>(1000000000000000LL), + static_cast<__int128>(10000000000000000LL), + static_cast<__int128>(100000000000000000LL), + static_cast<__int128>(1000000000000000000LL), + static_cast<__int128>(1000000000000000000LL) * 10LL, + static_cast<__int128>(1000000000000000000LL) * 100LL, + static_cast<__int128>(1000000000000000000LL) * 1000LL, + static_cast<__int128>(1000000000000000000LL) * 10000LL, + static_cast<__int128>(1000000000000000000LL) * 100000LL, + static_cast<__int128>(1000000000000000000LL) * 1000000LL, + static_cast<__int128>(1000000000000000000LL) * 10000000LL, + static_cast<__int128>(1000000000000000000LL) * 100000000LL, + static_cast<__int128>(1000000000000000000LL) * 1000000000LL, + static_cast<__int128>(1000000000000000000LL) * 10000000000LL, + static_cast<__int128>(1000000000000000000LL) * 100000000000LL, + static_cast<__int128>(1000000000000000000LL) * 1000000000000LL, + static_cast<__int128>(1000000000000000000LL) * 10000000000000LL, + static_cast<__int128>(1000000000000000000LL) * 100000000000000LL, + static_cast<__int128>(1000000000000000000LL) * 1000000000000000LL, + static_cast<__int128>(1000000000000000000LL) * 10000000000000000LL, + static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL, + static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL * 10LL, + static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL * 100LL, + static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL * 1000LL}; + return values[x]; } inline wide::Int256 exp10_i256(int x) { - if (x < 0) return 0; - if (x > 76) return std::numeric_limits<wide::Int256>::max(); + if (x < 0) { + return 0; + } + if (x > 76) { Review Comment: warning: 76 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp if (x > 76) { ^ ``` ########## be/src/vec/common/int_exp.h: ########## @@ -53,36 +53,120 @@ } // namespace exp_details -/// On overflow, the function returns unspecified value. - -inline uint64_t int_exp2(int x) { - return 1ULL << x; -} - inline uint64_t int_exp10(int x) { - if (x < 0) return 0; - if (x > 19) return std::numeric_limits<uint64_t>::max(); + if (x < 0) { + return 0; + } + if (x > 19) { + return std::numeric_limits<uint64_t>::max(); + } return exp_details::get_exp<uint64_t, 10, 20>(x); } namespace common { -inline constexpr std::int32_t exp10_i32(int x) { - return exp_details::get_exp<std::int32_t, 10, 10>(x); +constexpr inline int exp10_i32(int x) { + if (x < 0) { + return 0; + } + if (x > 9) { + return std::numeric_limits<int>::max(); + } + + constexpr int values[] = {1, 10, 100, 1000, 10000, + 100000, 1000000, 10000000, 100000000, 1000000000}; + return values[x]; } -inline constexpr std::int64_t exp10_i64(int x) { - return exp_details::get_exp<std::int64_t, 10, 19>(x); +constexpr inline int64_t exp10_i64(int x) { + if (x < 0) { + return 0; + } + if (x > 18) { + return std::numeric_limits<int64_t>::max(); + } + + constexpr int64_t values[] = {1LL, + 10LL, + 100LL, + 1000LL, + 10000LL, + 100000LL, + 1000000LL, + 10000000LL, + 100000000LL, + 1000000000LL, + 10000000000LL, + 100000000000LL, + 1000000000000LL, + 10000000000000LL, + 100000000000000LL, + 1000000000000000LL, + 10000000000000000LL, + 100000000000000000LL, + 1000000000000000000LL}; + return values[x]; } -inline constexpr __int128 exp10_i128(int x) { - return exp_details::get_exp<__int128, 10, 39>(x); +constexpr inline __int128 exp10_i128(int x) { + if (x < 0) { + return 0; + } + if (x > 38) { Review Comment: warning: 38 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp if (x > 38) { ^ ``` -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org