<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div style="-webkit-text-size-adjust: auto;"><br></div><div style="-webkit-text-size-adjust: auto;">On Apr 24, 2015, at 23:58, Christian Gunning <<a href="mailto:xian@unm.edu">xian@unm.edu</a>> wrote:<br><br></div><blockquote type="cite" style="-webkit-text-size-adjust: auto;"><div><div dir="ltr"><div>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() (<a href="https://svn.r-project.org/R/trunk/src/nmath/rpois.c">https://svn.r-project.org/R/trunk/src/nmath/rpois.c</a>).<br><br></div><div>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?<br><br></div><div>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.<br><br></div></div></div></blockquote><div style="-webkit-text-size-adjust: auto;"><br></div><div style="-webkit-text-size-adjust: auto;">The set of integers exactly representable by a double is a superset of those which can represented by a 32bit int.</div><div style="-webkit-text-size-adjust: auto;"><br></div><div><span style="-webkit-text-size-adjust: auto;"><a href="http://stackoverflow.com/questions/759201/representing-integers-in-doubles">http://stackoverflow.com/questions/759201/representing-integers-in-doubles</a></span></div></body></html>