Skip to content
Prev 207180 / 398503 Next

Optimizing C code

Bonjour Christophe,

NA and NaN are different things... Actually this is tricky because NA is 
implemented as a special kind of NaN :

See this extract of R_ext/Arith.h :

int R_IsNA(double);		/* True for R's NA only */
int R_IsNaN(double);		/* True for special NaN, *not* for NA */
int R_finite(double);		/* True if none of NA, NaN, +/-Inf */
#define ISNA(x)	       R_IsNA(x)

/* ISNAN(): True for *both* NA and NaN.
    NOTE: some systems do not return 1 for TRUE.
    Also note that C++ math headers specifically undefine
    isnan if it is a macro (it is on OS X and in C99),
    hence the workaround.  This code also appears in Rmath.h
*/
#ifdef __cplusplus
   int R_isnancpp(double); /* in arithmetic.c */
#  define ISNAN(x)     R_isnancpp(x)
#else
#  define ISNAN(x)     (isnan(x)!=0)
#endif

Romain

PS: the question would be more appropriate in R-devel.
On 01/22/2010 11:14 AM, Christophe Genolini wrote: