Skip to content

Commit 63c3993

Browse files
committed
stop trying to be clever and just be portable
1 parent b609e3a commit 63c3993

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

inst/include/Rcpp/sugar/tools/mapcompare.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,9 @@
2222
#ifndef Rcpp__sugar__tools__mapcompare_h
2323
#define Rcpp__sugar__tools__mapcompare_h
2424

25-
#define R_UNSIGNED_LONG_NAN_REAL 0x7ff8000000000000
26-
2725
namespace Rcpp {
2826
namespace sugar {
2927

30-
inline bool Rcpp_IsNA(double x) {
31-
return *reinterpret_cast<unsigned long*>(&x) == *reinterpret_cast<unsigned long*>(&NA_REAL);
32-
}
33-
34-
inline bool Rcpp_IsNaN(double x) {
35-
return *reinterpret_cast<unsigned long*>(&x) == R_UNSIGNED_LONG_NAN_REAL;
36-
}
37-
3828
inline int StrCmp(SEXP x, SEXP y) {
3929
if (x == NA_STRING) return (y == NA_STRING ? 0 : 1);
4030
if (y == NA_STRING) return -1;
@@ -67,7 +57,7 @@ struct MapCompare<double> {
6757

6858
// this branch inspired by data.table: see
6959
// https://github.com/arunsrinivasan/datatable/commit/1a3e476d3f746e18261662f484d2afa84ac7a146#commitcomment-4885242
70-
if (Rcpp_IsNaN(right) and Rcpp_IsNA(left)) return true;
60+
if (R_IsNaN(right) and R_IsNA(left)) return true;
7161

7262
if (leftNaN != rightNaN) {
7363
return leftNaN < rightNaN;

inst/unitTests/runit.table.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,28 @@
2121

2222
if (.runThisTest) {
2323

24-
set.seed(123)
25-
2624
.setUp <- Rcpp:::unit_test_setup("table.cpp")
2725

28-
table <- function(x) base::table(x, useNA="ifany")
26+
table_ <- function(x) c(base::table(x, useNA="ifany"))
2927

3028
test.table.numeric <- function() {
31-
x <- c(1, 2, NA, NaN, -Inf, Inf)
32-
checkEquals( RcppTable(x), c(table(x)), "table matches R: numeric case")
29+
x <- c(1, 2, 1, 1, NA, NaN, -Inf, Inf)
30+
checkEquals( RcppTable(x), table_(x), "table matches R: numeric case")
3331
}
3432

3533
test.table.integer <- function() {
3634
x <- c(-1L, 1L, NA_integer_, NA_integer_, 100L, 1L)
37-
checkEquals( RcppTable(x), c(table(x)), "table matches R: integer case")
35+
checkEquals( RcppTable(x), table_(x), "table matches R: integer case")
3836
}
3937

4038
test.table.logical <- function() {
4139
x <- c(TRUE, TRUE, FALSE, NA)
42-
checkEquals( RcppTable(x), c(table(x)), "table matches R: logical case")
40+
checkEquals( RcppTable(x), table_(x), "table matches R: logical case")
4341
}
4442

4543
test.table.character <- function() {
4644
x <- c("a", "a", "b", "a", NA, NA)
47-
checkEquals( RcppTable(x), c(table(x)), "table matches R: character case")
45+
checkEquals( RcppTable(x), table_(x), "table matches R: character case")
4846
}
4947

5048
}

0 commit comments

Comments
 (0)