[Bug libstdc++/80506] New: Wrong magic number in std::gamma_distribution
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Apr 24 12:10:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80506
Bug ID: 80506
Summary: Wrong magic number in std::gamma_distribution
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
Vincent Poinot reported the following by email:
The GNU C++ implementation uses the algorithm by Marsaglia and Tsang, and
in particular an optimization that avoids computing two logarithms. It goes
like this in random.tcc:
do
{
}
while (__u > result_type(1.0) - 0.331 * __n * __n * __n * __n
&& (std::log(__u) > (0.5 * __n * __n + __a1
* (1.0 - __v + std::log(__v)))));
However, I am pretty sure that the constant used in the short-circuit is
wrong: the paper by the authors (http://dl.acm.org/citation.cfm?id=358414)
clearly prescribes 0.0331 instead (and this is also the value used by the
GSL library that uses the same algorithm).
More information about the Gcc-bugs
mailing list