cyb70289 commented on a change in pull request #10274:
URL: https://github.com/apache/arrow/pull/10274#discussion_r630686322
##########
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;
+ }
+
+ template <typename T, typename Arg>
+ static constexpr enable_if_unsigned_integer<T> Call(KernelContext*, Arg arg,
Status*) {
+ return arg;
+ }
+
+ 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;
Review comment:
This produces exactly same code as `std::abs`:
https://godbolt.org/z/exvd8nxWc
I suggest use `std::abs` directly and combine this function with floating
point.
--
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:
[email protected]