From: Jonathan Wakely Date: Mon, 29 Jan 2018 14:44:48 +0000 (+0000) Subject: PR libstdc++/83833 fix chi_squared_distribution::param(const param&) X-Git-Tag: releases/gcc-6.5.0~555 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62a0b5d14cef0dda4433076be2995881f7a5ce3d;p=thirdparty%2Fgcc.git PR libstdc++/83833 fix chi_squared_distribution::param(const param&) Backport from mainline 2018-01-15 Jonathan Wakely 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. From-SVN: r257149 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2a94b67d6e4b..99da4c5e072b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2018-01-29 Jonathan Wakely + + Backport from mainline + 2018-01-15 Jonathan Wakely + + 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. + 2018-01-19 Jonathan Wakely Backport from mainline diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index 9de480c02157..52a9b8700b96 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -2618,7 +2618,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ void param(const param_type& __param) - { _M_param = __param; } + { + _M_param = __param; + typedef typename std::gamma_distribution::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 000000000000..821a1a40e2a2 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc @@ -0,0 +1,40 @@ +// 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 +// . + +// { dg-do run { target c++11 } } +// { dg-additional-options "-ffloat-store" { target { m68*-*-* || ia32 } } } + +#include +#include + +void +test01() +{ + std::default_random_engine r1, r2; + using chi = std::chi_squared_distribution; + chi::param_type p(5); + chi d1(p); + chi d2; + d2.param(p); + VERIFY( d1(r1) == d2(r2) ); // PR libstdc++/83833 +} + +int +main() +{ + test01(); +}