You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/05/13 01:45:44 UTC

[GitHub] [arrow] cyb70289 commented on a change in pull request #10274: ARROW-12685: [C++][Compute] Add unary absolute value kernel

cyb70289 commented on a change in pull request #10274:
URL: https://github.com/apache/arrow/pull/10274#discussion_r631509260



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -79,22 +79,20 @@ struct AbsoluteValue {
 
   template <typename T, typename Arg>
   static constexpr enable_if_signed_integer<T> Call(KernelContext*, Arg arg, Status* st) {
-    return (arg < static_cast<T>(0)) ? arrow::internal::SafeSignedNegate(arg) : arg;
+    return std::abs(arg);
   }
 };
 
 struct AbsoluteValueChecked {
   template <typename T, typename Arg>
   static enable_if_signed_integer<T> Call(KernelContext*, Arg arg, Status* st) {
     static_assert(std::is_same<T, Arg>::value, "");
-    if (arg < static_cast<T>(0)) {
-      T result = 0;
-      if (ARROW_PREDICT_FALSE(NegateWithOverflow(arg, &result))) {
-        *st = Status::Invalid("overflow");
-      }
-      return result;
+    T result = std::abs(arg);
+    if (result < 0) {
+      *st = Status::Invalid("overflow");
+      return 0;

Review comment:
       Returning 0 looks strange. What about just returning the negative result?




-- 
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:
users@infra.apache.org