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 2020/08/05 05:42:14 UTC

[GitHub] [arrow] emkornfield commented on a change in pull request #7885: ARROW-9640: [C++][Gandiva] Implement round() for integers and long integers

emkornfield commented on a change in pull request #7885:
URL: https://github.com/apache/arrow/pull/7885#discussion_r465485532



##########
File path: cpp/src/gandiva/precompiled/arithmetic_ops.cc
##########
@@ -234,6 +234,25 @@ DIV_FLOAT(float64)
 
 #undef DIV_FLOAT
 
+#define ROUND(TYPE)                                                \
+  FORCE_INLINE                                                     \
+  gdv_##TYPE round_##TYPE(gdv_##TYPE number, gdv_int32 place) {    \
+    if (number == 0) {                                             \
+      return 0;                                                    \
+    }                                                              \
+    if (number < 0) {                                              \
+      return -round_##TYPE(-number, place);                        \
+    }                                                              \
+    return floor(number * pow(10, place) + 0.5) * pow(10, -place); \

Review comment:
       My suggestion would be to avoid floating point operations altogether.   I haven't tested this but for pow(10, ...) on integers I think either a lookup table or recursive/squaring would like be more efficient.  Then for rounding I think something like:
   
   (num + (pow(10, -(precision + 1)) * 5) / pow(10, -precision) should work.
   




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