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

From: Thomas Lumley <>
Date: Thu 06 Jan 2005 - 03:09:33 EST

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 mailing list Received on Thu Jan 06 03:25:34 2005

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:02:28 EST