jpedroantunes commented on a change in pull request #10516:
URL: https://github.com/apache/arrow/pull/10516#discussion_r669179317



##########
File path: cpp/src/gandiva/precompiled/extended_math_ops.cc
##########
@@ -367,4 +367,36 @@ gdv_float64 get_scale_multiplier(gdv_int32 scale) {
   return power_float64_float64(10.0, scale);
 }
 
+// returns the binary representation of a given integer (e.g. 928 -> 
1110100000)
+#define BIN_INTEGER(IN_TYPE)                                                   
       \
+  FORCE_INLINE                                                                 
       \
+  const char* bin_##IN_TYPE(int64_t context, gdv_##IN_TYPE value, int32_t* 
out_len) { \
+    *out_len = 0;                                                              
       \
+    int32_t len = 8 * sizeof(value);                                           
       \
+    char* ret = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, 
len));   \
+    if (ret == nullptr) {                                                      
       \
+      gdv_fn_context_set_error_msg(context, "Could not allocate memory for 
output");  \
+      return "";                                                               
       \
+    }                                                                          
       \
+    /* generate binary representation iteratively */                           
       \
+    gdv_u##IN_TYPE i;                                                          
       \
+    bool first = false; /* flag for not printing left zeros in positive 
numbers */    \
+    for (i = static_cast<gdv_u##IN_TYPE>(1) << (len - 1); i > 0; i = i / 2) {  
       \
+      if ((value & i) != 0) {                                                  
       \

Review comment:
       You are right! Added the handler for that case and also added tests to 
cover it.




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to