[Rcpp-devel] Rcpp::traits::is_inifinite - PosInf vs. NegInf
Avraham Adler
avraham.adler at gmail.com
Sun May 24 22:25:42 CEST 2020
As I was updating one of my packages (lamW), CRAN's reverse dependency
tests caught an error of my own making. For consistency, I was trying
to remove calls to std::numeric_limits and replace them with R magic
words (like R_NaN instead of
std::numeric_limits<double>::quiet_NaN()).
One of the changes I made was in a test for PosInf FROM:
if (x == std::numeric_limits<double>::infinity()) {
result = std::numeric_limits<double>::infinity();
}
TO
if (Rcpp::traits::is_infinite<REALSXP>(x)) {
result = R_PosInf;
}
The error, of course, is that NegInf is infinite too. My most
immediate question is which is preferable (speed, efficiency,
consistency, etc.). To revert back to checking equality using
std::numeric_limits or to use a compound if
(Rcpp::traits::is_infinite<REALSXP>(x) && x > 0.0)?
More generally, would it be of values to have sugar functions for
checking for PosInf vs. NegInf, or would that end up being a call to
std::numeric_limits anyway?
As always, thanks to Dirk, Romain, JJ, Kevin, and everyone!
Thank you,
Avi
More information about the Rcpp-devel
mailing list