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/12 02:33:31 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_r630683291



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -66,6 +66,50 @@ constexpr Unsigned to_unsigned(T signed_) {
   return static_cast<Unsigned>(signed_);
 }
 
+struct AbsoluteValue {
+  template <typename T, typename Arg>
+  static constexpr enable_if_floating_point<T> Call(KernelContext*, Arg arg, Status*) {
+    return (arg < static_cast<T>(0)) ? -arg : arg;

Review comment:
       Any reason don't use `std::fabs` directly?
   std::fabs provides more optimized code: https://godbolt.org/z/nd38arvTe
   std::fabs(-0.0) = 0.0, but `(x < 0) ? -x : x` outputs -0.0 if x = -0.0.




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