<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 10, 2018 at 11:25 AM, Nagurne, James via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_-4603325366131779057WordSection1">
<p class="MsoNormal">Back in 2010, the algorithm for this function was updated, adding the following clause:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">            if (__x < 10)<u></u><u></u></p>
<p class="MsoNormal">            {<u></u><u></u></p>
<p class="MsoNormal">                const result_type __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040,<u></u><u></u></p>
<p class="MsoNormal">                              <wbr>               40320, 362880};<u></u><u></u></p>
<p class="MsoNormal">                __px = -__pr.__mean_;<u></u><u></u></p>
<p class="MsoNormal">                __py = _VSTD::pow(__pr.__mean_, (double)__x) / __fac[__x];<u></u><u></u></p>
<p class="MsoNormal">            }<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">In this case, result_type is the single template parameter to the instantiation of std::poisson_distribution.<u></u><u></u></p>
<p class="MsoNormal">In the case that std::poisson_distribution is instantiated with a 16-bit signed integral type, __fac[8] and __fac[9] are out of range of result_type, and are truncated or result in a change of sign.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Since the only use of __fac is as an operand to a double-precision floating point division, would it not make sense to instead declare it ‘double’ instead of ‘result_type’, and then modify the values populating it to be doubles?<u></u><u></u></p><p class="MsoNormal"><br></p></div></div></blockquote><div><br></div><div>------------------------------------------------------------------------</div><div>r322556 | marshall | 2018-01-16 06:54:36 -0800 (Tue, 16 Jan 2018) | 7 lines</div><div>Changed paths:</div><div>   M /libcxx/trunk/include/random</div><div><br></div><div>Change an internal table of constants for the poisson distribution from</div><div>type 'result_type' to 'double'. The only thing that we ever do with</div><div>these numbers is to promote them to 'double' and use them in a division.</div><div>For small result_types, the values were getting truncated, skewing the</div><div>results. Thanks to James Nagurne for the suggestion.</div><div> </div></div><br></div></div>