jonkeane commented on a change in pull request #11652:
URL: https://github.com/apache/arrow/pull/11652#discussion_r749363543
##########
File path: r/R/expression.R
##########
@@ -217,7 +217,23 @@ build_expr <- function(FUN,
} else if (FUN == "%/%") {
# In R, integer division works like floor(float division)
out <- build_expr("/", args = args)
- return(out$cast(int32(), allow_float_truncate = TRUE))
+
+ # integer output only for all integer input
+ int_type_ids <- Type[toupper(INTEGER_TYPES)]
+ numerator_is_int <- args[[1]]$type_id() %in% int_type_ids
+ denominator_is_int <- args[[2]]$type_id() %in% int_type_ids
+
+ if (numerator_is_int && denominator_is_int) {
+ out_float <- build_expr(
+ "if_else",
+ build_expr("equal", args[[2]], 0L),
+ Scalar$create(NA_integer_),
+ out
+ )
+ return(out_float$cast(args[[1]]$type(), allow_float_truncate = TRUE))
Review comment:
🤔 Would it be possible to take out `allow_float_truncate = TRUE` and use
`floor()` here to accomplish the truncation bit? When this code was originally
written `floor()` didn't exist and we used `allow_float_truncate` to accomplish
that (though like you show here that leads to some very silly results!)
--
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]