Skip to content

Commit

Permalink
beetween fun edge case regression fix, closes #3565 (#3568)
Browse files Browse the repository at this point in the history
  • Loading branch information
jangorecki authored and mattdowle committed May 16, 2019
1 parent b44e22c commit d586595
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -14530,6 +14530,10 @@ old = options("datatable.verbose"=TRUE)
test(2038.18, between(1:5, 2, 4), output="between parallel processing of integer with recycling")
test(2038.19, between(1:5, 2L, 4), output="between parallel processing of integer with recycling")
test(2038.20, between(1:5, 2, 4L), output="between parallel processing of integer with recycling")
# revdep regression #3565
test(2038.21, between(1:10, -Inf, Inf), between(1:10, NA, NA), output="between parallel processing of double using closed bounds with recycling")
test(2038.22, between(1:10, -Inf, Inf), between(as.double(1:10), -Inf, Inf), output="between parallel processing of double using closed bounds with recycling")

options(old)

# between int64 support
Expand Down
24 changes: 14 additions & 10 deletions src/between.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP bounds) {
int nprotect = 0;
bool integer=true;
bool integer64=false;
if (isInteger(x) && // #3517 coerce to num to int when possible
(isInteger(lower) || isRealReallyInt(lower)) &&
(isInteger(upper) || isRealReallyInt(upper))) {
if (!isInteger(lower)) {
lower = PROTECT(coerceVector(lower, INTSXP)); nprotect++;
}
if (!isInteger(upper)) {
upper = PROTECT(coerceVector(upper, INTSXP)); nprotect++;
if (isInteger(x)) {
if ((isInteger(lower) || isRealReallyInt(lower)) &&
(isInteger(upper) || isRealReallyInt(upper))) { // #3517 coerce to num to int when possible
if (!isInteger(lower)) {
lower = PROTECT(coerceVector(lower, INTSXP)); nprotect++;
}
if (!isInteger(upper)) {
upper = PROTECT(coerceVector(upper, INTSXP)); nprotect++;
}
} else { // #3565
x = PROTECT(coerceVector(x, REALSXP)); nprotect++;
}
} else if (inherits(x,"integer64")) {
}
if (inherits(x,"integer64")) {
if (!inherits(lower,"integer64") || !inherits(upper,"integer64"))
error("Internal error in between: 'x' is integer64 while 'lower' and/or 'upper' are not, should have been caught by now"); // # nocov
integer=false;
Expand All @@ -53,7 +57,7 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP bounds) {
if (!isReal(upper)) {
upper = PROTECT(coerceVector(upper, REALSXP)); nprotect++;
}
} else {
} else if (!isInteger(x)) {
error("Internal error in between: 'x' is not int, double or int64, should have been caught by now"); // # nocov
}
// TODO: sweep through lower and upper ensuring lower<=upper (inc bounds) and no lower>upper or lower==INT_MAX
Expand Down

0 comments on commit d586595

Please sign in to comment.