[R-pkg-devel] testing for NaN in C++ code
Ben Bolker
bbo|ker @end|ng |rom gm@||@com
Sat Mar 6 03:07:18 CET 2021
Thanks! Now I see this is in Writing R Extensions, should have
looked more carefully ...
On 3/5/21 9:00 PM, Andrew Simmons wrote:
> Hello,
>
>
> You probably want one of the following
> ISNA TRUE for R's NA only
> ISNAN TRUE for R's and IEEE's NaN
> R_IsNaN TRUE for IEEE'S NaN only
>
> On Fri, Mar 5, 2021, 20:55 Ben Bolker <bbolker using gmail.com
> <mailto:bbolker using gmail.com>> wrote:
>
> 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
> <https://stackoverflow.com/questions/570669/checking-if-a-double-or-float-is-nan-in-c/42138465#42138465>
>
> ______________________________________________
> R-package-devel using r-project.org <mailto:R-package-devel using r-project.org>
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> <https://stat.ethz.ch/mailman/listinfo/r-package-devel>
>
More information about the R-package-devel
mailing list