Message ID | 20170424134316.GA16538@redhat.com |
---|---|
State | New |
Headers | show |
Hi, On 24/04/2017 15:43, Jonathan Wakely wrote: > We use the wrong constant for the Marsaglia Tsang algorithm. > > PR libstdc++/80506 > * include/bits/random.tcc (gamma_distribution::operator()): Fix magic > number used in loop condition. > > Tested powerpc64le-linux, committed to trunk. Thanks Jon for handling this. It would still be very nice to have a testcase... Cheers, Paolo.
.. or maybe using the wrong constant only impacts the performance?!? Paolo.
On 26/04/17 11:14 +0200, Paolo Carlini wrote:
>.. or maybe using the wrong constant only impacts the performance?!?
Yes, I think so. I did some very simple sanity tests and the numbers
were identical before and after.
On 04/26/2017 05:16 AM, Jonathan Wakely wrote: > On 26/04/17 11:14 +0200, Paolo Carlini wrote: >> .. or maybe using the wrong constant only impacts the performance?!? > > Yes, I think so. I did some very simple sanity tests and the numbers > were identical before and after. > > > I was backporting this and saw that __generate_impl does this twice more. For trunk and branch-8 I have these patches. OK? 2018-05-07 Edward Smith-Rowland <3dw4rd@verizon.net> Moar PR libstdc++/80506 * include/bits/random.tcc (gamma_distribution::__generate_impl()): Fix magic number used in loop condition. Index: include/bits/random.tcc =================================================================== --- include/bits/random.tcc (revision 259965) +++ include/bits/random.tcc (working copy) @@ -2408,7 +2408,7 @@ __v = __v * __v * __v; __u = __aurng(); } - while (__u > result_type(1.0) - 0.331 * __n * __n * __n * __n + while (__u > result_type(1.0) - 0.0331 * __n * __n * __n * __n && (std::log(__u) > (0.5 * __n * __n + __a1 * (1.0 - __v + std::log(__v))))); @@ -2429,7 +2429,7 @@ __v = __v * __v * __v; __u = __aurng(); } - while (__u > result_type(1.0) - 0.331 * __n * __n * __n * __n + while (__u > result_type(1.0) - 0.0331 * __n * __n * __n * __n && (std::log(__u) > (0.5 * __n * __n + __a1 * (1.0 - __v + std::log(__v)))));
On 05/05/18 21:19 -0400, Ed Smith-Rowland wrote: >On 04/26/2017 05:16 AM, Jonathan Wakely wrote: >>On 26/04/17 11:14 +0200, Paolo Carlini wrote: >>>.. or maybe using the wrong constant only impacts the performance?!? >> >>Yes, I think so. I did some very simple sanity tests and the numbers >>were identical before and after. >> >> >> >I was backporting this and saw that __generate_impl does this twice more. > >For trunk and branch-8 I have these patches. > >OK? OK, thanks for noticing the additional cases.
diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc index df05ebe..63d1c02 100644 --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -2356,7 +2356,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __v = __v * __v * __v; __u = __aurng(); } - while (__u > result_type(1.0) - 0.331 * __n * __n * __n * __n + while (__u > result_type(1.0) - 0.0331 * __n * __n * __n * __n && (std::log(__u) > (0.5 * __n * __n + __a1 * (1.0 - __v + std::log(__v)))));