Commit 73986c31 by Michele Pezzutti Committed by Paolo Carlini

re PR libstdc++/83237 (Values returned by std::poisson_distribution are not distributed correctly)

2017-12-24  Michele Pezzutti <mpezz@tiscali.it>

	PR libstdc++/83237
	* include/bits/random.tcc (poisson_distribution<>::operator()):
	Fix __x = 1 case - see updated Errata of Devroye's treatise.
	* testsuite/26_numerics/random/poisson_distribution/operators/
	values.cc: Add test.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	line number.

From-SVN: r255993
parent 4f962139
2017-12-24 Michele Pezzutti <mpezz@tiscali.it>
PR libstdc++/83237
* include/bits/random.tcc (poisson_distribution<>::operator()):
Fix __x = 1 case - see updated Errata of Devroye's treatise.
* testsuite/26_numerics/random/poisson_distribution/operators/
values.cc: Add test.
* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
line number.
2017-12-24 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/83450
......
......@@ -1301,6 +1301,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const double __c2 = __param._M_c2b + __c1;
const double __c3 = __c2 + 1;
const double __c4 = __c3 + 1;
// 1 / 78
const double __178 = 0.0128205128205128205128205128205128L;
// e^(1 / 78)
const double __e178 = 1.0129030479320018583185514777512983L;
const double __c5 = __c4 + __e178;
......@@ -1340,7 +1342,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
else if (__u <= __c4)
__x = 0;
else if (__u <= __c5)
__x = 1;
{
__x = 1;
// Only in the Errata, see libstdc++/83237.
__w = __178;
}
else
{
const double __v = -std::log(1.0 - __aurng());
......
......@@ -42,6 +42,12 @@ void test01()
std::poisson_distribution<> pd3(30.0);
auto bpd3 = std::bind(pd3, eng);
testDiscreteDist(bpd3, [](int n) { return poisson_pdf(n, 30.0); } );
// libstdc++/83237
std::poisson_distribution<> pd4(37.17);
auto bpd4 = std::bind(pd4, eng);
testDiscreteDist<100, 2000000>(bpd4, [](int n)
{ return poisson_pdf(n, 37.17); } );
}
int main()
......
......@@ -11,4 +11,4 @@ auto x = std::generate_canonical<std::size_t,
// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 156 }
// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3311 }
// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3317 }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment