Skip to content
Prev 5895 / 398506 Next

NA in C/C++

On Mon, 29 May 2000, John Chambers wrote:

            
Since John may not have read *all* the R code yet, that is precisely what
R_IsNaNorNA is: a wrapper for isnan on machines which have a working
isnan, and something else otherwise. Namely:

#ifdef IEEE_754

int R_IsNaNorNA(double x)
{
/* NOTE: some systems do not return 1 for TRUE. */
    return (isnan(x) != 0);
}
#else
....

where IEEE_754 is only set after testing (somewhat) functionality.

For finite, which is buggier, the 1997 draft revision to the 
ANSI C standard promised isfinite and defined it tightly.  It's just that
neither that revision not isfinite seem to be making any progress.

One thing the R project keeps on teaching me is the importance of
pragmatism here: a large proportion of the bug-fixing time is actually
bug-avoidance over all of an increasing range of machines.  Even so. I was
unprepared for the truth of Inf < 3 on Visual C++ ! I would prefer to be
pragmatic with correct answers than purist with wrong ones.