<div dir="ltr">Note that the R function rpois() always returns an integer vector and thus<div>commonly runs into problems when lambda is near or above 2^31 (the</div><div>smallest positive integral double that cannot represented as a 32-bit signed</div><div>integer).<br><div><br></div><div><div>> set.seed(1)</div><div>> rpois(10, 2^31)</div><div> [1] 2147454617         NA         NA         NA 2147412285         NA         NA</div><div> [8]         NA 2147469496 2147446621</div><div>Warning message:</div><div>In rpois(10, 2^31) : NAs produced</div><div>> storage.mode(.Last.value)</div><div>[1] "integer"</div></div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">Bill Dunlap<br>TIBCO Software<br>wdunlap <a href="http://tibco.com" target="_blank">tibco.com</a></div></div>
<br><div class="gmail_quote">On Sat, Apr 25, 2015 at 9:33 AM, Michael Weylandt <span dir="ltr"><<a href="mailto:michael.weylandt@gmail.com" target="_blank">michael.weylandt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><br></div><div>On Apr 24, 2015, at 23:58, Christian Gunning <<a href="mailto:xian@unm.edu" target="_blank">xian@unm.edu</a>> wrote:<br><br></div><blockquote type="cite"><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" target="_blank">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><br></div><div>The set of integers exactly representable by a double is a superset of those which can represented by a 32bit int.</div><div><br></div><div><span><a href="http://stackoverflow.com/questions/759201/representing-integers-in-doubles" target="_blank">http://stackoverflow.com/questions/759201/representing-integers-in-doubles</a></span></div></div><br>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">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" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></blockquote></div><br></div>