Skip to content

Commit add1817

Browse files
committed
static unsigned long NA_REAL, R_NaN
1 parent 63c3993 commit add1817

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525
namespace Rcpp {
2626
namespace sugar {
2727

28+
static unsigned long const R_UNSIGNED_LONG_NA_REAL = *(unsigned long*)(&NA_REAL);
29+
static unsigned long const R_UNSIGNED_LONG_NAN_REAL = *(unsigned long*)(&R_NaN);
30+
31+
inline bool Rcpp_IsNA(double x) {
32+
return *reinterpret_cast<unsigned long*>(&x) == R_UNSIGNED_LONG_NA_REAL;
33+
}
34+
35+
inline bool Rcpp_IsNaN(double x) {
36+
return *reinterpret_cast<unsigned long*>(&x) == R_UNSIGNED_LONG_NAN_REAL;
37+
}
38+
2839
inline int StrCmp(SEXP x, SEXP y) {
2940
if (x == NA_STRING) return (y == NA_STRING ? 0 : 1);
3041
if (y == NA_STRING) return -1;
@@ -57,7 +68,7 @@ struct MapCompare<double> {
5768

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

6273
if (leftNaN != rightNaN) {
6374
return leftNaN < rightNaN;

0 commit comments

Comments
 (0)