https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119739
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Nathan Myers <[email protected]>: https://gcc.gnu.org/g:866bc8a9214b1d00402fdbdcb976688a95c98f65 commit r16-6177-g866bc8a9214b1d00402fdbdcb976688a95c98f65 Author: Nathan Myers <[email protected]> Date: Wed Aug 6 22:38:44 2025 -0400 libstdc++: New generate_canonical impl (P0952, LWG2524) [PR119739] Implement P0952R2 "A new specification for std::generate_canonical", fixing issue LWG 2524. It has us start over, using new entropy, if the naïve generation of a value in [0..1) comes up equal to 1.0, which occurs too rarely for the change to measurably affect performance, but does affect the number of calls to the underlying random bit generator. The old implementation is preserved, guarded by preprocessor macro _GLIBCXX_USE_OLD_GENERATE_CANONICAL, for use where behavior exactly matching previous runs is required. The fix is extended to all of C++11 to 26. The public function dispatches to variations optimized for requested bit depth `d`, using minimal integer sizes for exact intermediate calculations. It is faster than the old implementation, which computed a floating-point logarithm, and performs all intermediate calculations on integer types. It does not allow the IEEE half- precision type `float16_t`, as its range is not large enough to represent intermediate integer values specified, but does allow `bfloat16_t`. This implementation varies from the Standard in retaining in the output mantissa as much as possible of the entropy obtained from the provided random bit generator, not just the leading `d` bits of randomness as specified, and in permitting use on floating point types beyond float, double, and long double. The macro _GLIBCXX_GENERATE_CANONICAL_STRICT may be defined to obtain the exact Standard behavior. This patch also adds tests for statistical properties, and adds new static asserts on template argument requirements where supported. It adds tests using non-optimal RNGs that yield values 0..999999 and 0..0x7ffffffe. A test for the case addressed in LWG 2524 already appeared in 64351.cc. This change amounts to a different resolution for bugzilla PR64351 and LWG 2524. libstdc++-v3/ChangeLog: PR libstdc++/119739 * include/bits/random.tcc: Add generate_canonical impl for C++26. * testsuite/26_numerics/random/uniform_real_distribution/operators/64351.cc: Adapt test for both pre- and post- C++26. * testsuite/26_numerics/random/uniform_real_distribution/operators/gencanon.cc: Test for float and double from 32-bit RNG, including 1.0 do-over. Reviewed-by: Jonathan Wakely <[email protected]>
