[Rcpp-devel] rpois returns double?

Christian Gunning xian at unm.edu
Sat Apr 25 05:58:27 CEST 2015


Quick question, mainly out of curiousity.  I get that Rcpp uses the R api
on the backend, and in the R api, R::rpois returns a double (and
Rcpp::rpois returns NumericVector). The R C code doesn't offer much in the
way of explanation of why double is returned, but always returns a floor() (
https://svn.r-project.org/R/trunk/src/nmath/rpois.c).

It seems to me that, in this case, upstream could (should?) cast to int.
Since it doesn't, downstream users like Rcpp and me must choose whether to
follow upstream convention or to cast.  In this case, is the "best
practice" to cast-to-int right away, or to follow along and just use
doubles for everything?

I've run into this recently with other RNG code that returns doubles for
everything, and I'm wondering if there's an obvious tradeoff that I'm
missing, like speed versus type-correctness?  If anyone has any insights,
I'd love to hear them.

thanks,
Christian

-- 
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150424/812cc34e/attachment.html>


More information about the Rcpp-devel mailing list