Message ID | 20180115195956.GA16615@redhat.com |
---|---|
State | New |
Headers | show |
Series | PR libstdc++/83833 fix chi_squared_distribution::param(const param&) | expand |
On 15/01/18 19:59 +0000, Jonathan Wakely wrote: >The chi_squared_distribution::param(const param&) function should also >update the parameters of the gamma_distribution member. > > PR libstdc++/83833 > * include/bits/random.h (chi_squared_distribution::param): Update > gamma distribution parameter. > * testsuite/26_numerics/random/chi_squared_distribution/83833.cc: New > test. > >Tested powerpc64le-linux, committed to trunk. > >(I know this is not a regression, but it's a small fix, and I also >plan to apply it on the branches). This is needed to prevent the test failing on x86-32. Committed to trunk and gcc-7-branch. commit 7b450fcaf80dc75b7007de5f5fd82489cfc92eee Author: Jonathan Wakely <jwakely@redhat.com> Date: Mon Jan 29 14:06:37 2018 +0000 PR libstdc++/83833 fix failing test on ia32 PR libstdc++/83833 * testsuite/26_numerics/random/chi_squared_distribution/83833.cc: Add -ffloat-store to options for m68k and ia32. diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc index 01667635b41..087c9368ce4 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc @@ -16,6 +16,7 @@ // <http://www.gnu.org/licenses/>. // { dg-do run { target c++11 } } +// // { dg-additional-options "-ffloat-store" { target { m68*-*-* || ia32 } } } #include <random> #include <testsuite_hooks.h>
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index 655ee1df6d6..f812bbf18b1 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -2643,7 +2643,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ void param(const param_type& __param) - { _M_param = __param; } + { + _M_param = __param; + typedef typename std::gamma_distribution<result_type>::param_type + param_type; + _M_gd.param(param_type{__param.n() / 2}); + } /** * @brief Returns the greatest lower bound value of the distribution. diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc new file mode 100644 index 00000000000..01667635b41 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do run { target c++11 } } + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + std::default_random_engine r1, r2; + using chi = std::chi_squared_distribution<double>; + chi::param_type p(5); + chi d1(p); + chi d2; + d2.param(p); + VERIFY( d1(r1) == d2(r2) ); // PR libstdc++/83833 +} + +int +main() +{ + test01(); +}