[cfe-dev] libc++: Implementation of std::poisson_distribution::operator()

Nagurne, James via cfe-dev cfe-dev at lists.llvm.org
Wed Jan 10 11:25:13 PST 2018


Back in 2010, the algorithm for this function was updated, adding the following clause:

            if (__x < 10)
            {
                const result_type __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040,
                                             40320, 362880};
                __px = -__pr.__mean_;
                __py = _VSTD::pow(__pr.__mean_, (double)__x) / __fac[__x];
            }

In this case, result_type is the single template parameter to the instantiation of std::poisson_distribution.
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.

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?

Regards,
J.B. Nagurne
Code Generation
Texas Instruments
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180110/2bd40ac4/attachment.html>


More information about the cfe-dev mailing list