random (poisson_distribution<>::_M_initialize): Add.

2006-08-15  Paolo Carlini  <pcarlini@suse.de>

	* include/tr1/random (poisson_distribution<>::_M_initialize): Add.
	(poisson_distribution<>::poisson_distribution(const _RealType&):
	Use it.
	(operator>>(std::basic_istream<>&, poisson_distribution<>&)):
	Likewise.
	(poisson_distribution<>::_M_large): Remove.
	* include/tr1/random.tcc (poisson_distribution<>::_M_initialize):
	Define.
	(operator<<(std::basic_ostream<>&, const poisson_distribution<>&)):
	Do not output the constants.

	* include/tr1/random (operator>>(std::basic_istream<>&,
	gamma_distribution&)): Minor tweak.
	
	* include/tr1/random.tcc (poisson_distribution<>::operator()):
	Minor tweak.

	* include/tr1/random: Consistently, all data members private.

From-SVN: r116155
This commit is contained in:
Paolo Carlini 2006-08-15 15:11:24 +00:00 committed by Paolo Carlini
parent 018b899bc7
commit 482e4739cd
3 changed files with 56 additions and 61 deletions

View File

@ -1,3 +1,24 @@
2006-08-15 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random (poisson_distribution<>::_M_initialize): Add.
(poisson_distribution<>::poisson_distribution(const _RealType&):
Use it.
(operator>>(std::basic_istream<>&, poisson_distribution<>&)):
Likewise.
(poisson_distribution<>::_M_large): Remove.
* include/tr1/random.tcc (poisson_distribution<>::_M_initialize):
Define.
(operator<<(std::basic_ostream<>&, const poisson_distribution<>&)):
Do not output the constants.
* include/tr1/random (operator>>(std::basic_istream<>&,
gamma_distribution&)): Minor tweak.
* include/tr1/random.tcc (poisson_distribution<>::operator()):
Minor tweak.
* include/tr1/random: Consistently, all data members private.
2006-08-15 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random.tcc (mersenne_twister<>::operator()): Revert

View File

@ -1556,7 +1556,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
bernoulli_distribution& __x)
{ return __is >> __x._M_p; }
protected:
private:
double _M_p;
};
@ -1643,7 +1643,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
return __is;
}
protected:
private:
_RealType _M_p;
_RealType _M_log_p;
};
@ -1665,12 +1665,6 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
const poisson_distribution<_IntType, _RealType>& __x);
template<typename _IntType, typename _RealType,
typename _CharT, typename _Traits>
std::basic_istream<_CharT, _Traits>&
operator>>(std::basic_istream<_CharT, _Traits>& __is,
poisson_distribution<_IntType, _RealType>& __x);
template<typename _IntType, typename _RealType>
class poisson_distribution
{
@ -1681,7 +1675,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
// constructors and member function
explicit
poisson_distribution(const _RealType& __mean = _RealType(1));
poisson_distribution(const _RealType& __mean = _RealType(1))
: _M_mean(__mean)
{
_GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
_M_initialize();
}
/**
* Gets the distribution parameter @p mean.
@ -1722,20 +1721,27 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
*
* @returns The input stream with @p __x extracted or in an error state.
*/
template<typename _IntType1, typename _RealType1,
typename _CharT, typename _Traits>
template<typename _CharT, typename _Traits>
friend std::basic_istream<_CharT, _Traits>&
operator>>(std::basic_istream<_CharT, _Traits>& __is,
poisson_distribution<_IntType1, _RealType1>& __x);
poisson_distribution& __x)
{
__is >> __x._M_mean;
__x._M_initialize();
return __is;
}
private:
void
_M_initialize();
protected:
_RealType _M_mean;
// _M_lm_thr hosts either log(mean) or the threshold of the simple
// method.
_RealType _M_lm_thr;
#if _GLIBCXX_USE_C99_MATH_TR1
_RealType _M_lfm, _M_sm, _M_d, _M_scx4, _M_2cx, _M_c2b, _M_cb;
#endif
bool _M_large;
};
/* @} */ // group tr1_random_distributions_discrete
@ -1834,7 +1840,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator>>(std::basic_istream<_CharT, _Traits>& __is,
uniform_real<_RealType1>& __x);
protected:
private:
_RealType _M_min;
_RealType _M_max;
};
@ -2115,10 +2121,10 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
*
* @returns The input stream with @p __x extracted or in an error state.
*/
template<typename _RealType1, typename _CharT, typename _Traits>
template<typename _CharT, typename _Traits>
friend std::basic_istream<_CharT, _Traits>&
operator>>(std::basic_istream<_CharT, _Traits>& __is,
gamma_distribution<_RealType1>& __x)
gamma_distribution& __x)
{ return __is >> __x._M_alpha; }
private:

View File

@ -656,16 +656,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
template<typename _IntType, typename _RealType>
void
poisson_distribution<_IntType, _RealType>::
poisson_distribution(const _RealType& __mean)
: _M_mean(__mean), _M_large(false)
_M_initialize()
{
_GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
#if _GLIBCXX_USE_C99_MATH_TR1
if (_M_mean >= 12)
{
_M_large = true;
const _RealType __m = std::floor(_M_mean);
_M_lm_thr = std::log(_M_mean);
_M_lfm = std::tr1::lgamma(__m + 1);
@ -708,20 +705,20 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator()(_UniformRandomNumberGenerator& __urng)
{
#if _GLIBCXX_USE_C99_MATH_TR1
if (_M_large)
if (_M_mean >= 12)
{
_RealType __x;
const _RealType __m = std::floor(_M_mean);
// sqrt(mu * pi / 2)
const _RealType __c1 = (_M_sm
* 1.2533141373155002512078826424055226L);
// sqrt(pi / 2)
const _RealType __spi_2 = 1.2533141373155002512078826424055226L;
const _RealType __c1 = _M_sm * __spi_2;
const _RealType __c2 = _M_c2b + __c1;
const _RealType __c3 = __c2 + 1;
const _RealType __c4 = __c3 + 1;
// c4 + e^(1 / 78)
const _RealType __c5 = (__c4
+ 1.0129030479320018583185514777512983L);
// e^(1 / 78)
const _RealType __e178 = 1.0129030479320018583185514777512983L;
const _RealType __c5 = __c4 + __e178;
const _RealType __c = _M_cb + __c5;
const _RealType __cx = 2 * (2 * __m + _M_d);
@ -801,20 +798,11 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
const std::ios_base::fmtflags __flags = __os.flags();
const _CharT __fill = __os.fill();
const std::streamsize __precision = __os.precision();
const _CharT __space = __os.widen(' ');
__os.flags(std::ios_base::scientific | std::ios_base::left);
__os.fill(__space);
__os.fill(__os.widen(' '));
__os.precision(_Max_digits10<_RealType>::__value);
__os << __x._M_large << __space << __x.mean()
<< __space << __x._M_lm_thr;
#if _GLIBCXX_USE_C99_MATH_TR1
if (__x._M_large)
__os << __space << __x._M_lfm << __space << __x._M_sm
<< __space << __x._M_d << __space << __x._M_scx4
<< __space << __x._M_2cx << __space << __x._M_c2b
<< __space << __x._M_cb;
#endif
__os << __x.mean();
__os.flags(__flags);
__os.fill(__fill);
@ -822,26 +810,6 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
return __os;
}
template<typename _IntType, typename _RealType,
typename _CharT, typename _Traits>
std::basic_istream<_CharT, _Traits>&
operator>>(std::basic_istream<_CharT, _Traits>& __is,
poisson_distribution<_IntType, _RealType>& __x)
{
const std::ios_base::fmtflags __flags = __is.flags();
__is.flags(std::ios_base::skipws);
__is >> __x._M_large >> __x._M_mean >> __x._M_lm_thr;
#if _GLIBCXX_USE_C99_MATH_TR1
if (__x._M_large)
__is >> __x._M_lfm >> __x._M_sm >> __x._M_d >> __x._M_scx4
>> __x._M_2cx >> __x._M_c2b >> __x._M_cb;
#endif
__is.flags(__flags);
return __is;
}
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&