[Rd] Standalone Mathlib, C++ and ISNAN()

Bill Northcott w.northcott at unsw.edu.au
Wed Jan 5 06:12:59 CET 2005


In the hope of some meaningful response and ignoring the risk of 
further abuse, let me try to clarify the issue here.

I have re-read the 'Writing R Extensions' manual.  It seems to me that 
it clearly says R API functions can be called from from C++ programs, 
and the API  includes the special values ISNAN() and R_FINITE() and the 
missing test ISNA().

R_FINITE is no problem.  It is defined as R_finite, which is declared 
in Rmath.h and included in libRmath.

ISNAN() however is broken.
In R 1.9 it was defined as R_IsNaNorNA unless IEEE_754 was defined 
which was not done in the standalone libRmath/Rmath.h.  R_IsNaNorNA was 
declared in Rmath and included in libRmath.  So it would work, although 
probably not when built against an installed R library because R.h 
would likely define IEEE_754.

In R2.0 ISNAN() is defined using isnan thus (isnan(x)!=0).  isnan() is 
in math.h and this works perfectly for C code.  However, in C++ the 
header cmath (included by iostream and others) undefs isnan().  So on 
platforms for which isnan() is a macro, the code breaks at compile time 
with 'isnan() undeclared'.

If building against a full R library, one might possible use R_IsNaN 
instead but this function is not included in libRmath v2.0 and the 
function R_IsNaNorNA which was used in libRmath v1.9 no longer exists

While I am on this topic, there seems to be nothing at all in the 
standalone libRmath to deal with ISNA() and although R_PosInf and 
R_NegInf are in the library, they don't seem to me to be declared.

Bill Northcott



More information about the R-devel mailing list