mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-05 22:11:30 +08:00
random (variate_generator<>::min, [...]): Return non-trivial values when _Engine_result_type is a floating point type and...
2007-11-03 Paolo Carlini <pcarlini@suse.de> Kai-Uwe Bux <bux@kubux.net> * include/tr1_impl/random (variate_generator<>::min, max, operator()()): Return non-trivial values when _Engine_result_type is a floating point type and result_type is an integer type. Co-Authored-By: Kai-Uwe Bux <bux@kubux.net> From-SVN: r129875
This commit is contained in:
parent
83dffdeb44
commit
202d1d5f54
@ -1,3 +1,10 @@
|
||||
2007-11-03 Paolo Carlini <pcarlini@suse.de>
|
||||
Kai-Uwe Bux <bux@kubux.net>
|
||||
|
||||
* include/tr1_impl/random (variate_generator<>::min, max,
|
||||
operator()()): Return non-trivial values when _Engine_result_type
|
||||
is a floating point type and result_type is an integer type.
|
||||
|
||||
2007-11-02 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* include/bits/stl_algo.h (minmax, minmax_element): Add.
|
||||
|
@ -89,11 +89,11 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
|
||||
result_type
|
||||
min() const
|
||||
{
|
||||
result_type __return_value = 0;
|
||||
result_type __return_value;
|
||||
if (is_integral<_Engine_result_type>::value
|
||||
&& is_integral<result_type>::value)
|
||||
__return_value = _M_g.min();
|
||||
else if (!is_integral<result_type>::value)
|
||||
else
|
||||
__return_value = result_type(0);
|
||||
return __return_value;
|
||||
}
|
||||
@ -101,48 +101,51 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
|
||||
result_type
|
||||
max() const
|
||||
{
|
||||
result_type __return_value = 0;
|
||||
result_type __return_value;
|
||||
if (is_integral<_Engine_result_type>::value
|
||||
&& is_integral<result_type>::value)
|
||||
__return_value = _M_g.max();
|
||||
else if (!is_integral<result_type>::value)
|
||||
__return_value = result_type(1);
|
||||
else
|
||||
__return_value = std::numeric_limits<result_type>::max() - 1;
|
||||
return __return_value;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts a value generated by the adapted random number generator
|
||||
* into a value in the input domain for the dependent random number
|
||||
* distribution.
|
||||
*
|
||||
* Because the type traits are compile time constants only the
|
||||
* appropriate clause of the if statements will actually be emitted
|
||||
* by the compiler.
|
||||
*/
|
||||
result_type
|
||||
operator()();
|
||||
operator()()
|
||||
{
|
||||
result_type __return_value;
|
||||
if (is_integral<_Engine_result_type>::value
|
||||
&& is_integral<result_type>::value)
|
||||
__return_value = _M_g();
|
||||
else if (!is_integral<_Engine_result_type>::value
|
||||
&& !is_integral<result_type>::value)
|
||||
__return_value = result_type(_M_g() - _M_g.min())
|
||||
/ result_type(_M_g.max() - _M_g.min());
|
||||
else if (is_integral<_Engine_result_type>::value
|
||||
&& !is_integral<result_type>::value)
|
||||
__return_value = result_type(_M_g() - _M_g.min())
|
||||
/ result_type(_M_g.max() - _M_g.min() + result_type(1));
|
||||
else
|
||||
__return_value = (((_M_g() - _M_g.min())
|
||||
/ (_M_g.max() - _M_g.min()))
|
||||
* std::numeric_limits<result_type>::max());
|
||||
return __return_value;
|
||||
}
|
||||
|
||||
private:
|
||||
_Engine _M_g;
|
||||
};
|
||||
|
||||
/*
|
||||
* Converts a value generated by the adapted random number generator into a
|
||||
* value in the input domain for the dependent random number distribution.
|
||||
*
|
||||
* Because the type traits are compile time constants only the appropriate
|
||||
* clause of the if statements will actually be emitted by the compiler.
|
||||
*/
|
||||
template<typename _Engine, typename _Distribution>
|
||||
typename _Adaptor<_Engine, _Distribution>::result_type
|
||||
_Adaptor<_Engine, _Distribution>::
|
||||
operator()()
|
||||
{
|
||||
result_type __return_value = 0;
|
||||
if (is_integral<_Engine_result_type>::value
|
||||
&& is_integral<result_type>::value)
|
||||
__return_value = _M_g();
|
||||
else if (is_integral<_Engine_result_type>::value
|
||||
&& !is_integral<result_type>::value)
|
||||
__return_value = result_type(_M_g() - _M_g.min())
|
||||
/ result_type(_M_g.max() - _M_g.min() + result_type(1));
|
||||
else if (!is_integral<_Engine_result_type>::value
|
||||
&& !is_integral<result_type>::value)
|
||||
__return_value = result_type(_M_g() - _M_g.min())
|
||||
/ result_type(_M_g.max() - _M_g.min());
|
||||
return __return_value;
|
||||
}
|
||||
} // namespace __detail
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user