rok commented on a change in pull request #9841: URL: https://github.com/apache/arrow/pull/9841#discussion_r606463260
########## File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc ########## @@ -233,6 +235,184 @@ struct DivideChecked { } }; +struct Power { + template <typename T, typename Arg0, typename Arg1> + static enable_if_signed_integer<T> Call(KernelContext* ctx, Arg0 left, Arg1 right) { + if (right < 0) { + ctx->SetStatus( + Status::Invalid("integers to negative integer powers are not allowed")); + } + if (left == 0 && right != 0) { + return 0; + } + Arg0 result = 1; + for (Arg1 i = 0; i < right; i++) { + MultiplyWithOverflow(result, left, &result); + } + return result; + } + + template <typename T, typename Arg0, typename Arg1> + static enable_if_unsigned_integer<T> Call(KernelContext* ctx, Arg0 left, Arg1 right) { + if (left == 0 && right != 0) { + return 0; + } + Arg0 result = 1; + for (Arg1 i = 0; i < right; i++) { + MultiplyWithOverflow(result, left, &result); + } + return result; + } + + template <typename T, typename Arg0, typename Arg1> + static enable_if_floating_point<T> Call(KernelContext* ctx, Arg0 left, Arg1 right) { + if (std::isnan(left) || std::isnan(right)) { + return NAN; + } Review comment: It can, but it will return `pow(1, NaN) -> 1` and `pow(NaN, 0) -> 1` while we want to return `pow(1, NaN) -> NaN` and `pow(NaN, 0) -> NaN` in the default case. -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org