| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7f14f2e commit 52b1ceb
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,8 +30,8 @@ between = function(x, lower, upper, incbounds=TRUE, NAbounds=TRUE, check=FALSE, | |||
| 30 | 30 | } | |
| 31 | 31 | if (is.i64(x)) { | |
| 32 | 32 | if (!requireNamespace("bit64", quietly=TRUE)) stopf("trying to use integer64 class when 'bit64' package is not installed") # nocov | |
| 33 | - if (!is.i64(lower) && is.numeric(lower)) lower = bit64::as.integer64(lower) | ||
| 34 | - if (!is.i64(upper) && is.numeric(upper)) upper = bit64::as.integer64(upper) | ||
| 33 | + if (!is.i64(lower) && (is.integer(lower) || fitsInInt64(lower))) lower = bit64::as.integer64(lower) | ||
| 34 | + if (!is.i64(upper) && (is.integer(upper) || fitsInInt64(upper))) upper = bit64::as.integer64(upper) | ||
| 35 | 35 | } | |
| 36 | 36 | is.supported = function(x) is.numeric(x) || is.character(x) || is.px(x) | |
| 37 | 37 | if (is.supported(x) && is.supported(lower) && is.supported(upper)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15068,7 +15068,7 @@ if (test_bit64) { | |||
| 15068 | 15068 | as.i64 = bit64::as.integer64 | |
| 15069 | 15069 | test(2039.01, between(1:10, as.i64(3), as.i64(6)), error="x is not integer64 but.*Please align classes") | |
| 15070 | 15070 | test(2039.02, between(1:10, 3, as.i64(6)), error="x is not integer64 but.*Please align classes") | |
| 15071 | - test(2039.03, between(as.i64(1:3), "2", as.i64(4)), error="x is integer64 but lower and/or upper are not") | ||
| 15071 | + test(2039.03, between(as.i64(1:3), "2", as.i64(4)), error="x is integer64 but lower is not.*Please align classes") | ||
| 15072 | 15072 | old = options("datatable.verbose"=TRUE) | |
| 15073 | 15073 | x = as.i64(1:10) | |
| 15074 | 15074 | ans36 = c(FALSE,FALSE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE) | |
@@ -15095,6 +15095,10 @@ if (test_bit64) { | |||
| 15095 | 15095 | test(2039.19, between(x+maxint, 3+maxint, NA, incbounds=FALSE), c(head(ans36open, -5L), rep(TRUE, 5)), output="between parallel processing of integer64 took") | |
| 15096 | 15096 | test(2039.20, between(x+maxint, rep(NA, 10L), rep(6+maxint, 10L)), c(TRUE, TRUE, tail(ans36, -2L)), output="between parallel processing of integer64 took") | |
| 15097 | 15097 | test(2039.21, between(x+maxint, rep(3+maxint, 10L), rep(NA, 10L), incbounds=FALSE), c(head(ans36open, -5L), rep(TRUE, 5)), output="between parallel processing of integer64 took") | |
| 15098 | + # must not blindly read integer64 values as doubles when the latter fit into int32, #7164 | ||
| 15099 | + test(2039.22, between(42L, structure(41., class="integer64"), structure(43., class="integer64")), error="x is not integer64 but.*Please align classes") | ||
| 15100 | + # must not blindly convert numeric bounds to integer64, #7164 | ||
| 15101 | + test(2039.23, between(as.i64(42), 41, -2^98), error="x is integer64 but upper is not.*Please align classes") | ||
| 15098 | 15102 | options(old) | |
| 15099 | 15103 | } | |
| 15100 | 15104 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,19 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S | |||
| 29 | 29 | const bool check = LOGICAL(checkArg)[0]; | |
| 30 | 30 | const bool verbose = GetVerbose(); | |
| 31 | 31 | ||
| 32 | + // check before potential coercion which ignores methods, #7164 | ||
| 33 | + if (INHERITS(x, char_integer64)) { | ||
| 34 | + if (!INHERITS(lower, char_integer64)) | ||
| 35 | + error(_("x is integer64 but %s is not. Please align classes."), "lower"); // e.g. between(int64, character, character) | ||
| 36 | + if (!INHERITS(upper, char_integer64)) | ||
| 37 | + error(_("x is integer64 but %s is not. Please align classes."), "upper"); // e.g. between(int64, character, character) | ||
| 38 | + } else { | ||
| 39 | + if (INHERITS(lower, char_integer64)) | ||
| 40 | + error(_("x is not integer64 but %s is. Please align classes."), "lower"); | ||
| 41 | + if (INHERITS(upper, char_integer64)) | ||
| 42 | + error(_("x is not integer64 but %s is. Please align classes."), "upper"); | ||
| 43 | + } | ||
| 44 | + | ||
| 32 | 45 | if (isInteger(x)) { | |
| 33 | 46 | if ((isInteger(lower) || fitsInInt32(lower)) && | |
| 34 | 47 | (isInteger(upper) || fitsInInt32(upper))) { // #3517 coerce to num to int when possible | |
@@ -90,8 +103,6 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S | |||
| 90 | 103 | ||
| 91 | 104 | case REALSXP: | |
| 92 | 105 | if (INHERITS(x, char_integer64)) { | |
| 93 | - if (!INHERITS(lower, char_integer64) || !INHERITS(upper, char_integer64)) | ||
| 94 | - error(_("x is integer64 but lower and/or upper are not.")); // e.g. between(int64, character, character) | ||
| 95 | 106 | const int64_t *lp = (int64_t *)REAL(lower); | |
| 96 | 107 | const int64_t *up = (int64_t *)REAL(upper); | |
| 97 | 108 | const int64_t *xp = (int64_t *)REAL(x); | |
@@ -117,8 +128,6 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S | |||
| 117 | 128 | } | |
| 118 | 129 | if (verbose) Rprintf(_("between parallel processing of integer64 took %8.3fs\n"), omp_get_wtime()-tic); | |
| 119 | 130 | } else { | |
| 120 | - if (INHERITS(lower, char_integer64) || INHERITS(upper, char_integer64)) | ||
| 121 | - error(_("x is not integer64 but lower and/or upper is integer64. Please align classes.")); | ||
| 122 | 131 | const double *lp = REAL(lower); | |
| 123 | 132 | const double *up = REAL(upper); | |
| 124 | 133 | const double *xp = REAL(x); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ bool within_int64_repres(double x) { | |||
| 14 | 14 | // used to error if not passed type double but this needed extra is.double() calls in calling R code | |
| 15 | 15 | // which needed a repeat of the argument. Hence simpler and more robust to return false when not type double. | |
| 16 | 16 | bool fitsInInt32(SEXP x) { | |
| 17 | - if (!isReal(x)) | ||
| 17 | + if (!isReal(x) || INHERITS(x, char_integer64)) | ||
| 18 | 18 | return false; | |
| 19 | 19 | R_xlen_t n=xlength(x), i=0; | |
| 20 | 20 | const double *dx = REAL(x); | |
@@ -31,7 +31,7 @@ SEXP fitsInInt32R(SEXP x) { | |||
| 31 | 31 | } | |
| 32 | 32 | ||
| 33 | 33 | bool fitsInInt64(SEXP x) { | |
| 34 | - if (!isReal(x)) | ||
| 34 | + if (!isReal(x) || INHERITS(x, char_integer64)) | ||
| 35 | 35 | return false; | |
| 36 | 36 | R_xlen_t n=xlength(x), i=0; | |
| 37 | 37 | const double *dx = REAL(x); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments