aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/tr1_impl/random65
2 files changed, 41 insertions, 31 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index b477561..9687899 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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.
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
/**