NA in C/C++
On Mon, 29 May 2000, John Chambers wrote:
A few general comments. The IEEE 754 floating-point standard is one of the more striking successes in getting computer hardware to be more useful for those who program. There are, of course, glitches, both in non-compliance and in holes in the standard, but if we can work within the standard as far as possible, while complaining about the glitches, we'll be better off, and C/C++ software produced will be more likely to port gracefully to other environments. From that view, using C routines that are part of the standard (while perhaps overriding them on machines that don't conform) has advantages inside your own C/C++ code, IF that code is not intrinsically R/S dependent. So isnan() would be better in that case, R_IsNaNorNA() better for code that is R-dependent.
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.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._