Skip to content
Prev 6672 / 12125 Next

[R-pkg-devel] testing for NaN in C++ code

I would like to test for NaN inside C++ code that lives inside a CRAN 
package.

Following the StackOverflow question linked below, I was using

#define isNAN(a)  (a!=a)

which I *think* used to work, but at some point along the way it stopped 
working due to compiler/flag changes. I'm thinking of switching to

#define isNAN(a) std::isnan(a)

instead. Does anyone have first-hand knowledge of having tried this and 
know if it works across the range of platforms/standard compilation 
flags that CRAN/R users are likely to experience?  Any other suggestions?

  I know that I should follow the problem upstream and detect it where 
it happens (see the answer titled "nan prevention" on SO), but in the 
meantime it would be nice to be able to do this robustly across all the 
platforms it's likely to see.

   cheers
     Ben Bolker


https://stackoverflow.com/questions/570669/checking-if-a-double-or-float-is-nan-in-c/42138465#42138465