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

Thomas Lumley tlumley at u.washington.edu
Wed Jan 5 17:09:33 CET 2005


On Wed, 5 Jan 2005, Bill Northcott wrote:

>
> 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
>

Yes, but in your standalone C or C++ code you can just use isnan() from 
math.h directly.

The reason that R doesn't do that is twofold.  In the past we tried to 
support computers that didn't use IEEE 754 arithmetic, which meant that 
isnan might not exist.  Also, IIRC we found that isnan() doesn't use 1 for 
TRUE on all platforms -- sometimes it uses -1 or something else -- and 
code had assumed 1.  That's why the strange-looking isnan(x)!=0 is there.

You shouldn't have either of these problems in your C++ code, so it would 
be much easier to just use isnan(x) directly.  The only complication 
would be distinguishing NA from other NaNs, but you won't have to do that 
in standalone C++ code.

It would be worth noting somewhere that ISNAN breaks when some C++ headers 
are included on Mac OS X, and I will do that.


 	-thomas



More information about the R-devel mailing list