1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/random/additive_combine.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,125 @@
1.4 +/* boost random/additive_combine.hpp header file
1.5 + *
1.6 + * Copyright Jens Maurer 2000-2001
1.7 + * Distributed under the Boost Software License, Version 1.0. (See
1.8 + * accompanying file LICENSE_1_0.txt or copy at
1.9 + * http://www.boost.org/LICENSE_1_0.txt)
1.10 + *
1.11 + * See http://www.boost.org for most recent version including documentation.
1.12 + *
1.13 + * $Id: additive_combine.hpp,v 1.11 2005/05/21 15:57:00 dgregor Exp $
1.14 + *
1.15 + * Revision history
1.16 + * 2001-02-18 moved to individual header files
1.17 + */
1.18 +
1.19 +#ifndef BOOST_RANDOM_ADDITIVE_COMBINE_HPP
1.20 +#define BOOST_RANDOM_ADDITIVE_COMBINE_HPP
1.21 +
1.22 +#include <iostream>
1.23 +#include <algorithm> // for std::min and std::max
1.24 +#include <boost/config.hpp>
1.25 +#include <boost/cstdint.hpp>
1.26 +#include <boost/random/linear_congruential.hpp>
1.27 +
1.28 +namespace boost {
1.29 +namespace random {
1.30 +
1.31 +// L'Ecuyer 1988
1.32 +template<class MLCG1, class MLCG2,
1.33 +#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS
1.34 + typename MLCG1::result_type
1.35 +#else
1.36 + int32_t
1.37 +#endif
1.38 + val>
1.39 +class additive_combine
1.40 +{
1.41 +public:
1.42 + typedef MLCG1 first_base;
1.43 + typedef MLCG2 second_base;
1.44 + typedef typename MLCG1::result_type result_type;
1.45 +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
1.46 + static const bool has_fixed_range = true;
1.47 + static const result_type min_value = 1;
1.48 + static const result_type max_value = MLCG1::max_value-1;
1.49 +#else
1.50 + enum { has_fixed_range = false };
1.51 +#endif
1.52 + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 1; }
1.53 + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_mlcg1.max)()-1; }
1.54 +
1.55 + additive_combine() : _mlcg1(), _mlcg2() { }
1.56 + additive_combine(typename MLCG1::result_type seed1,
1.57 + typename MLCG2::result_type seed2)
1.58 + : _mlcg1(seed1), _mlcg2(seed2) { }
1.59 + template<class It> additive_combine(It& first, It last)
1.60 + : _mlcg1(first, last), _mlcg2(first, last) { }
1.61 +
1.62 + void seed()
1.63 + {
1.64 + _mlcg1.seed();
1.65 + _mlcg2.seed();
1.66 + }
1.67 +
1.68 + void seed(typename MLCG1::result_type seed1,
1.69 + typename MLCG2::result_type seed2)
1.70 + {
1.71 + _mlcg1(seed1);
1.72 + _mlcg2(seed2);
1.73 + }
1.74 +
1.75 + template<class It> void seed(It& first, It last)
1.76 + {
1.77 + _mlcg1.seed(first, last);
1.78 + _mlcg2.seed(first, last);
1.79 + }
1.80 +
1.81 + result_type operator()() {
1.82 + result_type z = _mlcg1() - _mlcg2();
1.83 + if(z < 1)
1.84 + z += MLCG1::modulus-1;
1.85 + return z;
1.86 + }
1.87 + static bool validation(result_type x) { return val == x; }
1.88 +
1.89 +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
1.90 +
1.91 +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
1.92 + template<class CharT, class Traits>
1.93 + friend std::basic_ostream<CharT,Traits>&
1.94 + operator<<(std::basic_ostream<CharT,Traits>& os, const additive_combine& r)
1.95 + { os << r._mlcg1 << " " << r._mlcg2; return os; }
1.96 +
1.97 + template<class CharT, class Traits>
1.98 + friend std::basic_istream<CharT,Traits>&
1.99 + operator>>(std::basic_istream<CharT,Traits>& is, additive_combine& r)
1.100 + { is >> r._mlcg1 >> std::ws >> r._mlcg2; return is; }
1.101 +#endif
1.102 +
1.103 + friend bool operator==(const additive_combine& x, const additive_combine& y)
1.104 + { return x._mlcg1 == y._mlcg1 && x._mlcg2 == y._mlcg2; }
1.105 + friend bool operator!=(const additive_combine& x, const additive_combine& y)
1.106 + { return !(x == y); }
1.107 +#else
1.108 + // Use a member function; Streamable concept not supported.
1.109 + bool operator==(const additive_combine& rhs) const
1.110 + { return _mlcg1 == rhs._mlcg1 && _mlcg2 == rhs._mlcg2; }
1.111 + bool operator!=(const additive_combine& rhs) const
1.112 + { return !(*this == rhs); }
1.113 +#endif
1.114 +private:
1.115 + MLCG1 _mlcg1;
1.116 + MLCG2 _mlcg2;
1.117 +};
1.118 +
1.119 +} // namespace random
1.120 +
1.121 +typedef random::additive_combine<
1.122 + random::linear_congruential<int32_t, 40014, 0, 2147483563, 0>,
1.123 + random::linear_congruential<int32_t, 40692, 0, 2147483399, 0>,
1.124 + 2060321752> ecuyer1988;
1.125 +
1.126 +} // namespace boost
1.127 +
1.128 +#endif // BOOST_RANDOM_ADDITIVE_COMBINE_HPP