<div dir="ltr"><div>Thanks all for the details, I appreciate the helpful answers!<br></div>-Christian<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 25, 2015 at 12:46 PM, William Dunlap <span dir="ltr"><<a href="mailto:wdunlap@tibco.com" target="_blank">wdunlap@tibco.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div>
<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> <a href="tel:%5B1%5D%202147454617" value="+12147454617" target="_blank">[1] 2147454617</a>         NA         NA         NA <a href="tel:2147412285" value="+12147412285" target="_blank">2147412285</a>         NA         NA</div>
<div> [8]         NA <a href="tel:2147469496" value="+12147469496" target="_blank">2147469496</a> <a href="tel:2147446621" value="+12147446621" target="_blank">2147446621</a></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>Bill Dunlap<br>
TIBCO Software<br>
wdunlap <a href="http://tibco.com" target="_blank">tibco.com</a></div>
</div>
<br>
<div class="gmail_quote"><span class="">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>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="auto"><span class="">
<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>
</span><div><div class="h5"><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></div><span class=""><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>
</span></div>
<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" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</blockquote>
</div>
<br>
</div>
</div>

</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!</div>
</div>