edponce commented on a change in pull request #10395:
URL: https://github.com/apache/arrow/pull/10395#discussion_r656530353



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -454,6 +456,48 @@ struct PowerChecked {
   }
 };
 
+struct Sign {
+  template <typename T, typename Arg,
+            enable_if_t<std::is_floating_point<Arg>::value, bool> = true>
+  static constexpr T Call(KernelContext*, Arg arg, Status*) {
+    return (arg == 0) ? 0 : (std::signbit(arg) ? -1 : 1);
+  }
+
+  template <typename T, typename Arg,
+            enable_if_t<std::is_unsigned<Arg>::value, bool> = true>
+  static constexpr T Call(KernelContext*, Arg arg, Status*) {
+    return (arg == 0) ? 0 : 1;
+  }
+
+  template <typename T, typename Arg,
+            enable_if_t<std::is_integral<Arg>::value && 
std::is_signed<Arg>::value,
+                        bool> = true>
+  static constexpr T Call(KernelContext*, Arg arg, Status*) {
+    return (arg > 0) ? 1 : ((arg == 0) ? 0 : -1);
+  }
+};
+
+struct SignWithSignedZero {
+  template <typename T, typename Arg,
+            enable_if_t<std::is_floating_point<Arg>::value, bool> = true>
+  static constexpr T Call(KernelContext*, Arg arg, Status*) {
+    return std::signbit(arg) ? -1 : 1;
+  }
+
+  template <typename T, typename Arg,
+            enable_if_t<std::is_unsigned<Arg>::value, bool> = true>
+  static constexpr T Call(KernelContext*, Arg arg, Status*) {
+    return (arg == 0) ? 0 : 1;
+  }
+
+  template <typename T, typename Arg,
+            enable_if_t<std::is_integral<Arg>::value && 
std::is_signed<Arg>::value,
+                        bool> = true>
+  static constexpr T Call(KernelContext*, Arg arg, Status*) {
+    return (arg > 0) ? 1 : ((arg == 0) ? 0 : -1);

Review comment:
       If zero is treated as a signed value, FP output will always be one of 
(-1,1).
   If zero is not signed, FP output can be (-1,0,1).




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


Reply via email to