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/18 08:00:51 UTC

[GitHub] [arrow] jorisvandenbossche commented on a change in pull request #10349: ARROW-12744: [C++][Compute] Add rounding kernel

jorisvandenbossche commented on a change in pull request #10349:
URL: https://github.com/apache/arrow/pull/10349#discussion_r634139326



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -355,6 +355,32 @@ struct PowerChecked {
   }
 };
 
+struct Round {
+  template <typename T, typename Arg>
+  static constexpr enable_if_floating_point<T> Call(KernelContext*, Arg arg, Status*) {
+    return std::round(arg);
+  }
+
+  template <typename T, typename Arg>
+  static constexpr enable_if_integer<T> Call(KernelContext*, Arg arg, Status*) {
+    return arg;
+  }
+};
+
+struct RoundChecked {
+  template <typename T, typename Arg>
+  static constexpr enable_if_integer<T> Call(KernelContext*, Arg arg, Status*) {
+    static_assert(std::is_same<T, Arg>::value, "");
+    return arg;
+  }
+
+  template <typename T, typename Arg>
+  static constexpr enable_if_floating_point<T> Call(KernelContext*, Arg arg, Status*) {
+    static_assert(std::is_same<T, Arg>::value, "");

Review comment:
       But should a `round` kernel ever change the type? IMO when rounding floats, the result can still be floats, regardless of the number of decimals to round




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