[v3] libstdc++/57674
Paolo Carlini
paolo.carlini@oracle.com
Sat Jun 22 21:09:00 GMT 2013
Hi,
tested x86_64-linux, committed mainline and 4_8-branch.
Thanks,
Paolo.
///////////////////////
-------------- next part --------------
2013-06-22 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/57674
* include/bits/random.h (binomial_distribution<>::_M_waiting):
Add double parameter.
* include/bits/random.tcc (binomial_distribution<>::operator()
(_UniformRandomNumberGenerator&, const param_type&)): Pass
__param._M_q to _M_waiting.
(_M_waiting): Adjust.
* testsuite/26_numerics/random/binomial_distribution/
operators/values.cc: Add tests.
-------------- next part --------------
Index: include/bits/random.h
===================================================================
--- include/bits/random.h (revision 200317)
+++ include/bits/random.h (working copy)
@@ -3978,7 +3978,8 @@
template<typename _UniformRandomNumberGenerator>
result_type
- _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
+ _M_waiting(_UniformRandomNumberGenerator& __urng,
+ _IntType __t, double __q);
param_type _M_param;
Index: include/bits/random.tcc
===================================================================
--- include/bits/random.tcc (revision 200317)
+++ include/bits/random.tcc (working copy)
@@ -1648,7 +1648,8 @@
template<typename _UniformRandomNumberGenerator>
typename binomial_distribution<_IntType>::result_type
binomial_distribution<_IntType>::
- _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t)
+ _M_waiting(_UniformRandomNumberGenerator& __urng,
+ _IntType __t, double __q)
{
_IntType __x = 0;
double __sum = 0.0;
@@ -1663,7 +1664,7 @@
__sum += __e / (__t - __x);
__x += 1;
}
- while (__sum <= _M_param._M_q);
+ while (__sum <= __q);
return __x - 1;
}
@@ -1784,12 +1785,13 @@
__x += __np + __naf;
- const _IntType __z = _M_waiting(__urng, __t - _IntType(__x));
+ const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
+ __param._M_q);
__ret = _IntType(__x) + __z;
}
else
#endif
- __ret = _M_waiting(__urng, __t);
+ __ret = _M_waiting(__urng, __t, __param._M_q);
if (__p12 != __p)
__ret = __t - __ret;
Index: testsuite/26_numerics/random/binomial_distribution/operators/values.cc
===================================================================
--- testsuite/26_numerics/random/binomial_distribution/operators/values.cc (revision 200317)
+++ testsuite/26_numerics/random/binomial_distribution/operators/values.cc (working copy)
@@ -43,6 +43,17 @@
std::binomial_distribution<> bd3(10, 0.75);
auto bbd3 = std::bind(bd3, eng);
testDiscreteDist(bbd3, [](int n) { return binomial_pdf(n, 10, 0.75); } );
+
+ // libstdc++/57674
+ std::binomial_distribution<> bd4(1, 0.8);
+ const std::binomial_distribution<>::param_type pm4(1, 0.3);
+ auto bbd4 = std::bind(bd4, eng, pm4);
+ testDiscreteDist(bbd4, [](int n) { return binomial_pdf(n, 1, 0.3); } );
+
+ std::binomial_distribution<> bd5(100, 0.3);
+ const std::binomial_distribution<>::param_type pm5(100, 0.8);
+ auto bbd5 = std::bind(bd5, eng, pm5);
+ testDiscreteDist(bbd5, [](int n) { return binomial_pdf(n, 100, 0.8); } );
}
int main()
More information about the Gcc-patches
mailing list