aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2007-11-03 23:27:55 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2007-11-03 23:27:55 +0000
commit202d1d5f54c5cb27b90358ac754acbea5697e40a (patch)
treeed31fce3c8c55d5b58038fb0e13e19cd1a5645c4 /libstdc++-v3/include
parent83dffdeb44589d502a1e21fc19380bc27e7dfc54 (diff)
downloadgcc-202d1d5f54c5cb27b90358ac754acbea5697e40a.zip
gcc-202d1d5f54c5cb27b90358ac754acbea5697e40a.tar.gz
gcc-202d1d5f54c5cb27b90358ac754acbea5697e40a.tar.bz2
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
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/tr1_impl/random65
1 files changed, 34 insertions, 31 deletions
diff --git a/libstdc++-v3/include/tr1_impl/random b/libstdc++-v3/include/tr1_impl/random
index 4ce7d8b..02ad85a 100644
--- a/libstdc++-v3/include/tr1_impl/random
+++ b/libstdc++-v3/include/tr1_impl/random
@@ -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
/**