Skip to content
Prev 5893 / 398506 Next

NA in C/C++

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

Where it makes sense, there is also an advantage to doing the relevant
testing in the S language and passing the result to the C code, either
directly, say as a logical vector argument, or indirectly by doing the
selection outside and leaving the C code to just grind away on the
selected subset of the data.  Within the S language, is.na() is the
best test, because it deals with either floating point or integer
data.

Anyone interested in the relevance of the standard, or just a read
through some insightful if eccentric ranting about numerical
computation generally should eventually encounter W. Kahan, "the
father of IEEE 754".

There is a directory on the web at the Berkeley CS department:
  www.cs.berkeley.edu/%7Ewkahan/ieee754status/
All the papers in that directory are worth looking at, allowing
for Kahan's legendary rages at all those who failed his standards.
Having had the privilege (well, looking back on it anyway) of taking a
course from Kahan, I can verify that his personality comes across well
in the papers.