Rcpp Version 0.12.14
is_na.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // is_na.h: Rcpp R/C++ interface class library -- vector operators
4 //
5 // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef Rcpp__traits_is_na_h
23 #define Rcpp__traits_is_na_h
24 
25 namespace Rcpp{
26 
27  namespace traits{
28 
29  // default to always false, applies to VECSXP, EXPRSXP and RAWSXP
30  template <int RTYPE>
32  return false;
33  }
34 
35  template <>
36  inline bool is_na<INTSXP>(int x) {
37  return x == NA_INTEGER;
38  }
39 
40  template <>
41  inline bool is_na<REALSXP>(double x) {
42  return internal::Rcpp_IsNA(x) || internal::Rcpp_IsNaN(x);
43  }
44 
45  template <>
46  inline bool is_na<CPLXSXP>(Rcomplex x) {
47  return internal::Rcpp_IsNA(x.r) || internal::Rcpp_IsNA(x.i) ||
48  internal::Rcpp_IsNaN(x.r) || internal::Rcpp_IsNaN(x.i);
49  }
50 
51  template <>
52  inline bool is_na<STRSXP>(SEXP x) {
53  return x == NA_STRING;
54  }
55 
56  template <>
57  inline bool is_na<LGLSXP>(int x) {
58  return x == NA_LOGICAL;
59  }
60 
61  }
62 }
63 
64 #endif
bool is_na< CPLXSXP >(Rcomplex x)
Definition: is_na.h:46
bool is_na< STRSXP >(SEXP x)
Definition: is_na.h:52
bool is_na(typename storage_type< RTYPE >::type)
Definition: is_na.h:31
bool is_na< REALSXP >(double x)
Definition: is_na.h:41
bool is_na< LGLSXP >(int x)
Definition: is_na.h:57
Rcpp API.
Definition: algo.h:28
bool is_na< INTSXP >(int x)
Definition: is_na.h:36