paleolimbot commented on a change in pull request #11652: URL: https://github.com/apache/arrow/pull/11652#discussion_r750307625
########## 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: I'd thought that the integer division kernel took care of this and so I ran into problems when trying to change this before...the `floor()` solution is a bit more explicit and I like it better! We still need the `if_else()` because casting `Inf` to integer with `allow_integer_overflow = TRUE` results in INT_MAX and errors otherwise. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org