From tlumley at u.washington.edu  Wed Jan  5 17:09:33 2005
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Wed Jan  5 17:09:43 2005
Subject: [Rd] Standalone Mathlib, C++ and ISNAN()
In-Reply-To: <77B2A8C4-5ED8-11D9-97FA-000393D3D676@unsw.edu.au>
References: <77B2A8C4-5ED8-11D9-97FA-000393D3D676@unsw.edu.au>
Message-ID: <Pine.A41.4.61b.0501050759060.100170@homer05.u.washington.edu>

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


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