]> gcc.gnu.org Git - gcc.git/commitdiff
PR libstdc++/83833 fix chi_squared_distribution::param(const param&)
authorJonathan Wakely <jwakely@redhat.com>
Mon, 15 Jan 2018 19:58:22 +0000 (19:58 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 15 Jan 2018 19:58:22 +0000 (19:58 +0000)
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: r256708

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/random.h
libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc [new file with mode: 0644]

index 572fbc68a08152f8aa5aef097f16b6f2b57cda4a..2f4df710b4d58adf3fcab22a5d916cec30c4e569 100644 (file)
@@ -1,5 +1,11 @@
 2018-01-15  Jonathan Wakely  <jwakely@redhat.com>
 
+       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.
+
        PR libstdc++/83830
        * include/std/type_traits (has_unique_object_representations_v): Add
        variable template.
index 655ee1df6d610dde66206226901b04c864412597..f812bbf18b1e08a8de066aaf3e7a8f854d4129f1 100644 (file)
@@ -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 (file)
index 0000000..0166763
--- /dev/null
@@ -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();
+}
This page took 0.06682 seconds and 5 git commands to generate.