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:24:07 UTC

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

sagnikc-dremio commented on a change in pull request #7885:
URL: https://github.com/apache/arrow/pull/7885#discussion_r465480139



##########
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:
       Modified this PR to handle only integers and long integers. For floats and doubles, handling for inf/NaN will be necessary, so will be taking it up in another PR.
   
   For this particular case, we need to be dealing with cases only where the precision for rounding is a negative number, and hence pow(10, precision) will never run into overflow or underflow (providing a check if the precision is larger than the number of digits in the number, return 0).
   
   Please let me know if you have any suggestions.




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