<div dir="ltr"><div>FWIW, the implementation of of is_finite lives here:</div><div><br></div><div><a href="https://github.com/RcppCore/Rcpp/blob/b1254701a899cb187f9a6917cb8d18c7f93290c7/inst/include/Rcpp/traits/is_infinite.h#L34-L37">https://github.com/RcppCore/Rcpp/blob/b1254701a899cb187f9a6917cb8d18c7f93290c7/inst/include/Rcpp/traits/is_infinite.h#L34-L37</a><br></div><div><br></div><div>I would recommend checking equality directly against the R constants `R_PosInf` and `R_NegInf`.</div><div><br></div><div>As for whether this would be useful to have directly in Rcpp, it wouldn't hurt, but I also don't see a great need since the existing R API suffices here (IMO).</div><div><br></div><div>Best,</div><div>Kevin</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, May 24, 2020 at 1:26 PM Avraham Adler <<a href="mailto:avraham.adler@gmail.com">avraham.adler@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">As I was updating one of my packages (lamW), CRAN's reverse dependency<br>
tests caught an error of my own making. For consistency, I was trying<br>
to remove calls to std::numeric_limits and replace them with R magic<br>
words (like R_NaN instead of<br>
std::numeric_limits<double>::quiet_NaN()).<br>
<br>
One of the changes I made was in a test for PosInf FROM:<br>
<br>
if (x == std::numeric_limits<double>::infinity()) {<br>
  result = std::numeric_limits<double>::infinity();<br>
}<br>
<br>
TO<br>
<br>
if (Rcpp::traits::is_infinite<REALSXP>(x)) {<br>
 result = R_PosInf;<br>
}<br>
<br>
The error, of course, is that NegInf is infinite too. My most<br>
immediate question is which is preferable (speed, efficiency,<br>
consistency, etc.). To revert back to checking equality using<br>
std::numeric_limits or to use a compound if<br>
(Rcpp::traits::is_infinite<REALSXP>(x) && x > 0.0)?<br>
<br>
More generally, would it be of values to have sugar functions for<br>
checking for PosInf vs. NegInf, or would that end up being a call to<br>
std::numeric_limits anyway?<br>
<br>
As always, thanks to Dirk, Romain, JJ, Kevin, and everyone!<br>
<br>
Thank you,<br>
<br>
Avi<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></blockquote></div></div>