This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/67011] division by zero in std::exponential_distribution
- From: "kretz at kde dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 27 Jul 2015 14:25:44 +0000
- Subject: [Bug libstdc++/67011] division by zero in std::exponential_distribution
- Auto-submitted: auto-generated
- References: <bug-67011-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67011
Matthias Kretz <kretz at kde dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kretz at kde dot org
--- Comment #3 from Matthias Kretz <kretz at kde dot org> ---
The problem is that (result_type(1) - __aurng()) must never be zero (because
std::log might raise FE_DIVBYZERO for std::log(0)). If __aurng() is a
distribution guaranteed to exclude result_type(1) then this works fine. AFAIK
std::generate_canoncial<float> sometimes generates a 1 (cf.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63176).
Also, I'm wondering whether the 1 - rng wouldn't reduce the randomness.
Consider:
std::log(numeric_limits<float>::min()) -> -87.3365478515625
std::log(1.f - nextafter(1.f, 0.f)) -> -16.635532379150390625
IIUC, the effect of log(1 - rng) is that the distance between random values
from std::exponential_distribution is considerable larger than for log(rng).