https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80137
Bug ID: 80137
Summary: std::generate_canonical calls its generator a
non-constant number of times
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: john.salmon at deshaw dot com
Target Milestone: ---
The fix to bug 63176 causes std::generate_canonical to loop
until the result is less than 1.0. As noted in the
discussion, this breaks the complexity requirement in
[rand.util.canonical]/p3.
There is a simple solution which also fixes 63176 but
which doesn't violate the standard's complexity requirement.
Instead of looping, do:
if (__builtin_expect(__ret >= _RealType(1), 0))
return _RealType(std::nextafter(_RealType(1), _RealType(0)));
else
return _ret;