jorisvandenbossche commented on a change in pull request #9841:
URL: https://github.com/apache/arrow/pull/9841#discussion_r606633215



##########
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:
       NumPy returns 1 by default in those cases as well:
   
   ```
   In [20]: np.power(1.0, np.nan)
   Out[20]: 1.0
   
   In [21]: np.power(np.nan, 0.0)
   Out[21]: 1.0
   ```
   
   So we could maybe do that as well? (for NaN, not necessarily for Null)




-- 
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


Reply via email to