[Bug libstdc++/67011] New: division by zero in std::exponential_distribution
janus at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Jul 25 21:34:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67011
Bug ID: 67011
Summary: division by zero in std::exponential_distribution
Product: gcc
Version: 4.8.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: janus at gcc dot gnu.org
Target Milestone: ---
After seeing a division-by-zero problem in a C++11 code (compiled with GCC
4.8.4), I traced it down and found that it seems to come from a call to
std::exponential_distribution.
Looking into the GCC trunk sources, I found two implementations of
std::exponential_distribution, in these two files:
libstdc++-v3/include/bits/random.h
libstdc++-v3/include/tr1/random.h
In the first one, operator() is implemented like this:
return -std::log(result_type(1) - __aurng()) / __p.lambda();
In the second one like this:
return -std::log(__urng()) / _M_lambda;
Looking through bugzilla I found PR 55047, which seems to describe exactly the
problem I observed (resulting from a log(0) call), but the fix has only been
applied to bits/random.h, not to tr1/random.h. I don't actually understand the
relationship between those two files (and which implementation is used under
which circumstances), but I guess the fix from PR 55047 should also be applied
to tr1/random.h?
More information about the Gcc-bugs
mailing list