mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
If the span of the range R produced by uniform bit generator U passed to generate_canonical is not power of two, we need to use algorithm that requires computing power R^k that is greater than 2^d, where d is number of digits in mantissa of _RealT. Previously we have used an integer type that is has twice as many digits as d. This lead to situation that for standard engines that produced such range (like std::minstd_rand0, std::minstd_rand, std::ranlux24, ....) 256bit integer support was required for 128bit floats. However, in this cases R^4 provides more than d bits of precision, while requiring 124 bits. We overestimate the number of required bits, by computing a value l * bit_width(R) (log2(R) + 1), where l is value such that log2(R) * l >= d. As R >= 2^log2(R), then R^l >= (2^log2(R))^l == 2^(log(R) * l) >= 2^d, so k+1 >= l >= k. In consequence R^k is smaller R^l which require at most l * bit_width(R). This is an overestimate, but difference should not be higher than l bits. We replace __gen_can_pow and __gen_can_rng_calls_needed with __gen_canon_log(v, b), which computes the largest power of b that fits into v. As such a number is smaller than v, the result will always fit in it's type. Both the logarithm and the power value are returned using __gen_canon_log_res struct. libstdc++-v3/ChangeLog: * include/bits/random.h (__rand_uint128::operator>) (__rand_uint128::operator>=): Define. * include/bits/random.tcc (__generate_canonical_pow2): Adjust for use of __rand_uint128 in C++11. (__gen_can_pow, __gen_can_rng_calls_needed): Replace with __gen_canon_log. (__gen_canon_log_res, __gen_canon_log): Define. (__generate_canonical_any): Reworked how _UInt is determined. * testsuite/26_numerics/random/uniform_real_distribution/operators/gencanon_eng.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
file: libstdc++-v3/README New users may wish to point their web browsers to the file index.html in the 'doc/html' subdirectory. It contains brief building instructions and notes on how to configure the library in interesting ways.