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



##########
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:
       This isn't consistent with the floating-point definition above, where 
`0` gives `1` in the output.




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