Skip to content

Commit f02aaa7

Browse files
committed
Tidy up and use Rcpp_IsNA, Rcpp_IsNaN where possible
1 parent 0b5fe6a commit f02aaa7

File tree

11 files changed

+23
-29
lines changed

11 files changed

+23
-29
lines changed

inst/include/Rcpp/traits/NAComparator.h renamed to inst/include/Rcpp/NAComparator.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
// You should have received a copy of the GNU General Public License
2121
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
2222

23-
#ifndef Rcpp__traits__NAComparator__h
24-
#define Rcpp__traits__NAComparator__h
23+
#ifndef Rcpp__NAComparator__h
24+
#define Rcpp__NAComparator__h
2525

2626
namespace Rcpp{
27-
namespace traits{
2827

2928
inline bool Rcpp_IsNA(double x) {
3029
return memcmp(
@@ -93,7 +92,6 @@ struct NAComparator<SEXP> {
9392
}
9493
};
9594

96-
}
9795
}
9896

9997
#endif

inst/include/Rcpp/traits/NAEquals.h renamed to inst/include/Rcpp/NAEquals.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
// You should have received a copy of the GNU General Public License
1818
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
1919

20-
#ifndef Rcpp__traits__NAEquals__h
21-
#define Rcpp__traits__NAEquals__h
20+
#ifndef Rcpp__NAEquals__h
21+
#define Rcpp__NAEquals__h
2222

2323
namespace Rcpp {
2424

25-
namespace traits {
26-
2725
template <typename T>
2826
struct NAEquals {
2927
inline bool operator()(T left, T right) const {
@@ -40,6 +38,4 @@ struct NAEquals<double> {
4038

4139
}
4240

43-
}
44-
4541
#endif

inst/include/Rcpp/hash/IndexHash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ namespace Rcpp{
160160
}
161161

162162
inline bool not_equal(const STORAGE& lhs, const STORAGE& rhs) {
163-
return ! ::Rcpp::traits::NAEquals<STORAGE>()(lhs, rhs);
163+
return ! NAEquals<STORAGE>()(lhs, rhs);
164164
}
165165

166166
bool add_value(int i){
@@ -213,8 +213,8 @@ namespace Rcpp{
213213
union dint_u val_u;
214214
/* double is a bit tricky - we nave to normalize 0.0, NA and NaN */
215215
if (val == 0.0) val = 0.0;
216-
if (R_IsNA(val)) val = NA_REAL;
217-
else if (R_IsNaN(val)) val = R_NaN;
216+
if (Rcpp_IsNA(val)) val = NA_REAL;
217+
else if (Rcpp_IsNaN(val)) val = R_NaN;
218218
val_u.d = val;
219219
addr = RCPP_HASH(val_u.u[0] + val_u.u[1]);
220220
return addr ;

inst/include/Rcpp/hash/SelfHash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ namespace sugar{
104104
union dint_u val_u;
105105
/* double is a bit tricky - we nave to normalize 0.0, NA and NaN */
106106
if (val == 0.0) val = 0.0;
107-
if (R_IsNA(val)) val = NA_REAL;
108-
else if (R_IsNaN(val)) val = R_NaN;
107+
if (Rcpp_IsNA(val)) val = NA_REAL;
108+
else if (Rcpp_IsNaN(val)) val = R_NaN;
109109
val_u.d = val;
110110
addr = RCPP_HASH(val_u.u[0] + val_u.u[1]);
111111
return addr ;

inst/include/Rcpp/internal/r_coerce.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ inline int r_coerce<LGLSXP,INTSXP>(int from){
5252
}
5353
template <>
5454
inline int r_coerce<REALSXP,INTSXP>(double from){
55-
if (R_IsNA(from)) {
55+
if (Rcpp_IsNA(from)) {
5656
return NA_INTEGER;
5757
} else if (from > INT_MAX || from <= INT_MIN ) {
5858
return NA_INTEGER;
@@ -90,7 +90,7 @@ inline double r_coerce<RAWSXP,REALSXP>(Rbyte from){
9090
// -> LGLSXP
9191
template <>
9292
inline int r_coerce<REALSXP,LGLSXP>(double from){
93-
return R_IsNA(from) ? NA_LOGICAL : (from!=0.0);
93+
return Rcpp_IsNA(from) ? NA_LOGICAL : (from!=0.0);
9494
}
9595

9696
template <>
@@ -100,7 +100,7 @@ inline int r_coerce<INTSXP,LGLSXP>(int from){
100100

101101
template <>
102102
inline int r_coerce<CPLXSXP,LGLSXP>(Rcomplex from){
103-
if( R_IsNA(from.r) ) return NA_LOGICAL ;
103+
if( Rcpp_IsNA(from.r) ) return NA_LOGICAL ;
104104
if( from.r == 0.0 || from.i == 0.0 ) return FALSE ;
105105
return TRUE ;
106106
}
@@ -119,7 +119,7 @@ inline Rbyte r_coerce<INTSXP,RAWSXP>(int from){
119119

120120
template <>
121121
inline Rbyte r_coerce<REALSXP,RAWSXP>(double from){
122-
if( R_IsNA(from) ) return static_cast<Rbyte>(0) ;
122+
if( Rcpp_IsNA(from) ) return static_cast<Rbyte>(0) ;
123123
return r_coerce<INTSXP,RAWSXP>(static_cast<int>(from)) ;
124124
}
125125

@@ -137,7 +137,7 @@ inline Rbyte r_coerce<LGLSXP,RAWSXP>(int from){
137137
template <>
138138
inline Rcomplex r_coerce<REALSXP,CPLXSXP>(double from){
139139
Rcomplex c ;
140-
if( R_IsNA(from) ){
140+
if( Rcpp_IsNA(from) ){
141141
c.r = NA_REAL;
142142
c.i = NA_REAL;
143143
} else{
@@ -273,7 +273,7 @@ template <>
273273
inline SEXP r_coerce<REALSXP,STRSXP>(double from){
274274

275275
// handle some special values explicitly
276-
if (R_IsNaN(from)) return Rf_mkChar("NaN");
276+
if (Rcpp_IsNaN(from)) return Rf_mkChar("NaN");
277277
else if (from == R_PosInf) return Rf_mkChar("Inf");
278278
else if (from == R_NegInf) return Rf_mkChar("-Inf");
279279
else return Rcpp::traits::is_na<REALSXP>(from) ? NA_STRING :Rf_mkChar( coerce_to_string<REALSXP>( from ) ) ;

inst/include/Rcpp/sugar/functions/table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Table {
113113
typedef CountInserter<HASH,STORAGE> Inserter ;
114114
HASH hash ;
115115

116-
typedef std::map<STORAGE, int, ::Rcpp::traits::NAComparator<STORAGE> > SORTED_MAP ;
116+
typedef std::map<STORAGE, int, NAComparator<STORAGE> > SORTED_MAP ;
117117
SORTED_MAP map ;
118118

119119
};

inst/include/Rcpp/traits/is_na.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ namespace Rcpp{
3939

4040
template <>
4141
inline bool is_na<REALSXP>(double x) {
42-
return R_IsNA(x) || R_IsNaN(x);
42+
return Rcpp_IsNA(x) || Rcpp_IsNaN(x);
4343
}
4444

4545
template <>
4646
inline bool is_na<CPLXSXP>(Rcomplex x) {
47-
return R_IsNA(x.r) || R_IsNA(x.i) || R_IsNaN(x.r) || R_IsNaN(x.i);
47+
return Rcpp_IsNA(x.r) || Rcpp_IsNA(x.i) || Rcpp_IsNaN(x.r) || Rcpp_IsNaN(x.i);
4848
}
4949

5050
template <>

inst/include/Rcpp/traits/is_nan.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ namespace traits{
3333

3434
template <>
3535
inline bool is_nan<REALSXP>( double x ){
36-
return R_IsNaN(x) ;
36+
return Rcpp_IsNaN(x) ;
3737
}
3838

3939
template <>
4040
inline bool is_nan<CPLXSXP>( Rcomplex x ){
41-
return R_IsNaN(x.r) || R_IsNaN(x.i) ;
41+
return Rcpp_IsNaN(x.r) || Rcpp_IsNaN(x.i) ;
4242
}
4343

4444
}

inst/include/Rcpp/traits/traits.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
#include <Rcpp/traits/storage_type.h>
3939
#include <Rcpp/traits/r_sexptype_traits.h>
4040
#include <Rcpp/traits/storage_type.h>
41-
#include <Rcpp/traits/NAComparator.h>
42-
#include <Rcpp/traits/NAEquals.h>
4341
#include <Rcpp/traits/r_type_traits.h>
4442
#include <Rcpp/traits/un_pointer.h>
4543
#include <Rcpp/traits/is_pointer.h>

inst/include/Rcpp/vector/Vector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class Vector :
247247
std::sort(
248248
start,
249249
start + size(),
250-
typename traits::NAComparator<typename traits::storage_type<RTYPE>::type >()
250+
NAComparator<typename traits::storage_type<RTYPE>::type >()
251251
) ;
252252
return *this ;
253253
}

0 commit comments

Comments
 (0)