[R] ISNAN() broken? in ver 2.x on MacOS X

Thomas Lumley tlumley at u.washington.edu
Tue Jan 4 03:48:45 CET 2005


On Tue, 4 Jan 2005, Bill Northcott wrote:

> I have a problem building an extension using ISNAN() on R version 2.0.x.
>
> In R 1.9.1 Arith.h and Rmath.h contained code like
>
> #ifdef IEEE_754
> # define ISNAN(x) (isnan(x)!=0)
> #else
> # define ISNAN(x)      R_IsNaNorNA(x)
> #endif
> #define R_FINITE(x)    R_finite(x)
> int R_IsNaNorNA(double);
> int R_finite(double);
>
> which works.
>
> R 2.0.x has
> # define ISNAN(x) (isnan(x)!=0)
> unconditionally.
>
> This breaks because on MacOS X in /usr/include/architecture/ppc/math.h 
> isnan() is itself a macro thus:
<snip>
> This macro is not substituted because substitution is not recursive. So the 
> build breaks with 'error: `isnan' undeclared'.
>
> How can I fix this?


Although you have clearly gone to some effort to diagnose this, I think 
your diagnosis is incorrect.

1) In R 1.9.1 IEEE_754 was #defined on OS X, so we would already have had
   #define ISNAN(x) (isnan(x)!=0)

2) The gcc C preprocessor documentation says
   "When the preprocessor expands a macro name, the macro's expansion
   replaces the macro invocation, then the expansion is examined for more
   macros to expand. For example,

      #define TABLESIZE BUFSIZE
      #define BUFSIZE 1024
      TABLESIZE
           ==> BUFSIZE
           ==> 1024

   TABLESIZE is expanded first to produce BUFSIZE, then that macro is
   expanded to produce the final result, 1024."

and while I haven't been able to find anything definitive about the ANSI 
standard, the gcc documentation usually flags extensions fairly well and 
in any case you are presumably using gcc (though you don't say 
explicitly).


A work-around would be to use isnan() rather than ISNAN().


 	-thomas




More information about the R-help mailing list