summaryrefslogtreecommitdiffstats
path: root/contrib/src/boost/random
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2017-05-19 08:49:52 (GMT)
committerStefan Radomski <github@mintwerk.de>2017-05-19 08:49:52 (GMT)
commit747781cbebe22efb4f2efb8f3269320962791914 (patch)
tree0c6df03ea42971d04695f3f6b295fc18c9113699 /contrib/src/boost/random
parent827bd207b54839dfa3d24c1b65afb638b9b5cd0e (diff)
downloaduscxml-747781cbebe22efb4f2efb8f3269320962791914.zip
uscxml-747781cbebe22efb4f2efb8f3269320962791914.tar.gz
uscxml-747781cbebe22efb4f2efb8f3269320962791914.tar.bz2
Worked on issue 131
Update boost Spent a mutex for UUIDgen
Diffstat (limited to 'contrib/src/boost/random')
-rw-r--r--contrib/src/boost/random/detail/config.hpp36
-rw-r--r--contrib/src/boost/random/detail/const_mod.hpp432
-rw-r--r--contrib/src/boost/random/detail/disable_warnings.hpp58
-rw-r--r--contrib/src/boost/random/detail/enable_warnings.hpp44
-rw-r--r--contrib/src/boost/random/detail/generator_bits.hpp72
-rw-r--r--contrib/src/boost/random/detail/generator_seed_seq.hpp80
-rw-r--r--contrib/src/boost/random/detail/integer_log2.hpp168
-rw-r--r--contrib/src/boost/random/detail/large_arithmetic.hpp244
-rw-r--r--contrib/src/boost/random/detail/operators.hpp168
-rw-r--r--contrib/src/boost/random/detail/polynomial.hpp768
-rw-r--r--contrib/src/boost/random/detail/ptr_helper.hpp134
-rw-r--r--contrib/src/boost/random/detail/seed.hpp230
-rw-r--r--contrib/src/boost/random/detail/seed_impl.hpp796
-rw-r--r--contrib/src/boost/random/detail/signed_unsigned_tools.hpp178
-rw-r--r--contrib/src/boost/random/detail/uniform_int_float.hpp152
-rw-r--r--contrib/src/boost/random/mersenne_twister.hpp1364
-rw-r--r--contrib/src/boost/random/traits.hpp214
-rw-r--r--contrib/src/boost/random/uniform_int.hpp198
-rw-r--r--contrib/src/boost/random/uniform_int_distribution.hpp838
-rw-r--r--contrib/src/boost/random/variate_generator.hpp244
20 files changed, 3209 insertions, 3209 deletions
diff --git a/contrib/src/boost/random/detail/config.hpp b/contrib/src/boost/random/detail/config.hpp
index 724ab19..854afe1 100644
--- a/contrib/src/boost/random/detail/config.hpp
+++ b/contrib/src/boost/random/detail/config.hpp
@@ -1,18 +1,18 @@
-/* boost random/detail/config.hpp header file
- *
- * Copyright Steven Watanabe 2009
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- */
-
-#include <boost/config.hpp>
-
-#if (defined(BOOST_NO_OPERATORS_IN_NAMESPACE) || defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)) \
- && !defined(BOOST_MSVC)
- #define BOOST_RANDOM_NO_STREAM_OPERATORS
-#endif
+/* boost random/detail/config.hpp header file
+ *
+ * Copyright Steven Watanabe 2009
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ */
+
+#include <boost/config.hpp>
+
+#if (defined(BOOST_NO_OPERATORS_IN_NAMESPACE) || defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)) \
+ && !defined(BOOST_MSVC)
+ #define BOOST_RANDOM_NO_STREAM_OPERATORS
+#endif
diff --git a/contrib/src/boost/random/detail/const_mod.hpp b/contrib/src/boost/random/detail/const_mod.hpp
index e0a43ab..9f0d0e5 100644
--- a/contrib/src/boost/random/detail/const_mod.hpp
+++ b/contrib/src/boost/random/detail/const_mod.hpp
@@ -1,216 +1,216 @@
-/* boost random/detail/const_mod.hpp header file
- *
- * Copyright Jens Maurer 2000-2001
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- * Revision history
- * 2001-02-18 moved to individual header files
- */
-
-#ifndef BOOST_RANDOM_CONST_MOD_HPP
-#define BOOST_RANDOM_CONST_MOD_HPP
-
-#include <boost/assert.hpp>
-#include <boost/static_assert.hpp>
-#include <boost/integer_traits.hpp>
-#include <boost/type_traits/make_unsigned.hpp>
-#include <boost/random/detail/large_arithmetic.hpp>
-
-#include <boost/random/detail/disable_warnings.hpp>
-
-namespace boost {
-namespace random {
-
-template<class IntType, IntType m>
-class const_mod
-{
-public:
- static IntType apply(IntType x)
- {
- if(((unsigned_m() - 1) & unsigned_m()) == 0)
- return (unsigned_type(x)) & (unsigned_m() - 1);
- else {
- IntType suppress_warnings = (m == 0);
- BOOST_ASSERT(suppress_warnings == 0);
- return x % (m + suppress_warnings);
- }
- }
-
- static IntType add(IntType x, IntType c)
- {
- if(((unsigned_m() - 1) & unsigned_m()) == 0)
- return (unsigned_type(x) + unsigned_type(c)) & (unsigned_m() - 1);
- else if(c == 0)
- return x;
- else if(x < m - c)
- return x + c;
- else
- return x - (m - c);
- }
-
- static IntType mult(IntType a, IntType x)
- {
- if(((unsigned_m() - 1) & unsigned_m()) == 0)
- return unsigned_type(a) * unsigned_type(x) & (unsigned_m() - 1);
- else if(a == 0)
- return 0;
- else if(a == 1)
- return x;
- else if(m <= traits::const_max/a) // i.e. a*m <= max
- return mult_small(a, x);
- else if(traits::is_signed && (m%a < m/a))
- return mult_schrage(a, x);
- else
- return mult_general(a, x);
- }
-
- static IntType mult_add(IntType a, IntType x, IntType c)
- {
- if(((unsigned_m() - 1) & unsigned_m()) == 0)
- return (unsigned_type(a) * unsigned_type(x) + unsigned_type(c)) & (unsigned_m() - 1);
- else if(a == 0)
- return c;
- else if(m <= (traits::const_max-c)/a) { // i.e. a*m+c <= max
- IntType suppress_warnings = (m == 0);
- BOOST_ASSERT(suppress_warnings == 0);
- return (a*x+c) % (m + suppress_warnings);
- } else
- return add(mult(a, x), c);
- }
-
- static IntType pow(IntType a, boost::uintmax_t exponent)
- {
- IntType result = 1;
- while(exponent != 0) {
- if(exponent % 2 == 1) {
- result = mult(result, a);
- }
- a = mult(a, a);
- exponent /= 2;
- }
- return result;
- }
-
- static IntType invert(IntType x)
- { return x == 0 ? 0 : (m == 0? invert_euclidian0(x) : invert_euclidian(x)); }
-
-private:
- typedef integer_traits<IntType> traits;
- typedef typename make_unsigned<IntType>::type unsigned_type;
-
- const_mod(); // don't instantiate
-
- static IntType mult_small(IntType a, IntType x)
- {
- IntType suppress_warnings = (m == 0);
- BOOST_ASSERT(suppress_warnings == 0);
- return a*x % (m + suppress_warnings);
- }
-
- static IntType mult_schrage(IntType a, IntType value)
- {
- const IntType q = m / a;
- const IntType r = m % a;
-
- BOOST_ASSERT(r < q); // check that overflow cannot happen
-
- return sub(a*(value%q), r*(value/q));
- }
-
- static IntType mult_general(IntType a, IntType b)
- {
- IntType suppress_warnings = (m == 0);
- BOOST_ASSERT(suppress_warnings == 0);
- IntType modulus = m + suppress_warnings;
- BOOST_ASSERT(modulus == m);
- if(::boost::uintmax_t(modulus) <=
- (::std::numeric_limits< ::boost::uintmax_t>::max)() / modulus)
- {
- return static_cast<IntType>(boost::uintmax_t(a) * b % modulus);
- } else {
- return static_cast<IntType>(detail::mulmod(a, b, modulus));
- }
- }
-
- static IntType sub(IntType a, IntType b)
- {
- if(a < b)
- return m - (b - a);
- else
- return a - b;
- }
-
- static unsigned_type unsigned_m()
- {
- if(m == 0) {
- return unsigned_type((std::numeric_limits<IntType>::max)()) + 1;
- } else {
- return unsigned_type(m);
- }
- }
-
- // invert c in the finite field (mod m) (m must be prime)
- static IntType invert_euclidian(IntType c)
- {
- // we are interested in the gcd factor for c, because this is our inverse
- BOOST_ASSERT(c > 0);
- IntType l1 = 0;
- IntType l2 = 1;
- IntType n = c;
- IntType p = m;
- for(;;) {
- IntType q = p / n;
- l1 += q * l2;
- p -= q * n;
- if(p == 0)
- return l2;
- IntType q2 = n / p;
- l2 += q2 * l1;
- n -= q2 * p;
- if(n == 0)
- return m - l1;
- }
- }
-
- // invert c in the finite field (mod m) (c must be relatively prime to m)
- static IntType invert_euclidian0(IntType c)
- {
- // we are interested in the gcd factor for c, because this is our inverse
- BOOST_ASSERT(c > 0);
- if(c == 1) return 1;
- IntType l1 = 0;
- IntType l2 = 1;
- IntType n = c;
- IntType p = m;
- IntType max = (std::numeric_limits<IntType>::max)();
- IntType q = max / n;
- BOOST_ASSERT(max % n != n - 1 && "c must be relatively prime to m.");
- l1 += q * l2;
- p = max - q * n + 1;
- for(;;) {
- if(p == 0)
- return l2;
- IntType q2 = n / p;
- l2 += q2 * l1;
- n -= q2 * p;
- if(n == 0)
- return m - l1;
- q = p / n;
- l1 += q * l2;
- p -= q * n;
- }
- }
-};
-
-} // namespace random
-} // namespace boost
-
-#include <boost/random/detail/enable_warnings.hpp>
-
-#endif // BOOST_RANDOM_CONST_MOD_HPP
+/* boost random/detail/const_mod.hpp header file
+ *
+ * Copyright Jens Maurer 2000-2001
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ * Revision history
+ * 2001-02-18 moved to individual header files
+ */
+
+#ifndef BOOST_RANDOM_CONST_MOD_HPP
+#define BOOST_RANDOM_CONST_MOD_HPP
+
+#include <boost/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/integer_traits.hpp>
+#include <boost/type_traits/make_unsigned.hpp>
+#include <boost/random/detail/large_arithmetic.hpp>
+
+#include <boost/random/detail/disable_warnings.hpp>
+
+namespace boost {
+namespace random {
+
+template<class IntType, IntType m>
+class const_mod
+{
+public:
+ static IntType apply(IntType x)
+ {
+ if(((unsigned_m() - 1) & unsigned_m()) == 0)
+ return (unsigned_type(x)) & (unsigned_m() - 1);
+ else {
+ IntType suppress_warnings = (m == 0);
+ BOOST_ASSERT(suppress_warnings == 0);
+ return x % (m + suppress_warnings);
+ }
+ }
+
+ static IntType add(IntType x, IntType c)
+ {
+ if(((unsigned_m() - 1) & unsigned_m()) == 0)
+ return (unsigned_type(x) + unsigned_type(c)) & (unsigned_m() - 1);
+ else if(c == 0)
+ return x;
+ else if(x < m - c)
+ return x + c;
+ else
+ return x - (m - c);
+ }
+
+ static IntType mult(IntType a, IntType x)
+ {
+ if(((unsigned_m() - 1) & unsigned_m()) == 0)
+ return unsigned_type(a) * unsigned_type(x) & (unsigned_m() - 1);
+ else if(a == 0)
+ return 0;
+ else if(a == 1)
+ return x;
+ else if(m <= traits::const_max/a) // i.e. a*m <= max
+ return mult_small(a, x);
+ else if(traits::is_signed && (m%a < m/a))
+ return mult_schrage(a, x);
+ else
+ return mult_general(a, x);
+ }
+
+ static IntType mult_add(IntType a, IntType x, IntType c)
+ {
+ if(((unsigned_m() - 1) & unsigned_m()) == 0)
+ return (unsigned_type(a) * unsigned_type(x) + unsigned_type(c)) & (unsigned_m() - 1);
+ else if(a == 0)
+ return c;
+ else if(m <= (traits::const_max-c)/a) { // i.e. a*m+c <= max
+ IntType suppress_warnings = (m == 0);
+ BOOST_ASSERT(suppress_warnings == 0);
+ return (a*x+c) % (m + suppress_warnings);
+ } else
+ return add(mult(a, x), c);
+ }
+
+ static IntType pow(IntType a, boost::uintmax_t exponent)
+ {
+ IntType result = 1;
+ while(exponent != 0) {
+ if(exponent % 2 == 1) {
+ result = mult(result, a);
+ }
+ a = mult(a, a);
+ exponent /= 2;
+ }
+ return result;
+ }
+
+ static IntType invert(IntType x)
+ { return x == 0 ? 0 : (m == 0? invert_euclidian0(x) : invert_euclidian(x)); }
+
+private:
+ typedef integer_traits<IntType> traits;
+ typedef typename make_unsigned<IntType>::type unsigned_type;
+
+ const_mod(); // don't instantiate
+
+ static IntType mult_small(IntType a, IntType x)
+ {
+ IntType suppress_warnings = (m == 0);
+ BOOST_ASSERT(suppress_warnings == 0);
+ return a*x % (m + suppress_warnings);
+ }
+
+ static IntType mult_schrage(IntType a, IntType value)
+ {
+ const IntType q = m / a;
+ const IntType r = m % a;
+
+ BOOST_ASSERT(r < q); // check that overflow cannot happen
+
+ return sub(a*(value%q), r*(value/q));
+ }
+
+ static IntType mult_general(IntType a, IntType b)
+ {
+ IntType suppress_warnings = (m == 0);
+ BOOST_ASSERT(suppress_warnings == 0);
+ IntType modulus = m + suppress_warnings;
+ BOOST_ASSERT(modulus == m);
+ if(::boost::uintmax_t(modulus) <=
+ (::std::numeric_limits< ::boost::uintmax_t>::max)() / modulus)
+ {
+ return static_cast<IntType>(boost::uintmax_t(a) * b % modulus);
+ } else {
+ return static_cast<IntType>(detail::mulmod(a, b, modulus));
+ }
+ }
+
+ static IntType sub(IntType a, IntType b)
+ {
+ if(a < b)
+ return m - (b - a);
+ else
+ return a - b;
+ }
+
+ static unsigned_type unsigned_m()
+ {
+ if(m == 0) {
+ return unsigned_type((std::numeric_limits<IntType>::max)()) + 1;
+ } else {
+ return unsigned_type(m);
+ }
+ }
+
+ // invert c in the finite field (mod m) (m must be prime)
+ static IntType invert_euclidian(IntType c)
+ {
+ // we are interested in the gcd factor for c, because this is our inverse
+ BOOST_ASSERT(c > 0);
+ IntType l1 = 0;
+ IntType l2 = 1;
+ IntType n = c;
+ IntType p = m;
+ for(;;) {
+ IntType q = p / n;
+ l1 += q * l2;
+ p -= q * n;
+ if(p == 0)
+ return l2;
+ IntType q2 = n / p;
+ l2 += q2 * l1;
+ n -= q2 * p;
+ if(n == 0)
+ return m - l1;
+ }
+ }
+
+ // invert c in the finite field (mod m) (c must be relatively prime to m)
+ static IntType invert_euclidian0(IntType c)
+ {
+ // we are interested in the gcd factor for c, because this is our inverse
+ BOOST_ASSERT(c > 0);
+ if(c == 1) return 1;
+ IntType l1 = 0;
+ IntType l2 = 1;
+ IntType n = c;
+ IntType p = m;
+ IntType max = (std::numeric_limits<IntType>::max)();
+ IntType q = max / n;
+ BOOST_ASSERT(max % n != n - 1 && "c must be relatively prime to m.");
+ l1 += q * l2;
+ p = max - q * n + 1;
+ for(;;) {
+ if(p == 0)
+ return l2;
+ IntType q2 = n / p;
+ l2 += q2 * l1;
+ n -= q2 * p;
+ if(n == 0)
+ return m - l1;
+ q = p / n;
+ l1 += q * l2;
+ p -= q * n;
+ }
+ }
+};
+
+} // namespace random
+} // namespace boost
+
+#include <boost/random/detail/enable_warnings.hpp>
+
+#endif // BOOST_RANDOM_CONST_MOD_HPP
diff --git a/contrib/src/boost/random/detail/disable_warnings.hpp b/contrib/src/boost/random/detail/disable_warnings.hpp
index 4582dcb..8213572 100644
--- a/contrib/src/boost/random/detail/disable_warnings.hpp
+++ b/contrib/src/boost/random/detail/disable_warnings.hpp
@@ -1,29 +1,29 @@
-/* boost random/detail/disable_warnings.hpp header file
- *
- * Copyright Steven Watanabe 2009
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- */
-
-// No #include guard. This header is intended to be included multiple times.
-
-#include <boost/config.hpp>
-
-#ifdef BOOST_MSVC
-#pragma warning(push)
-#pragma warning(disable:4512)
-#pragma warning(disable:4127)
-#pragma warning(disable:4724)
-#pragma warning(disable:4800) // 'int' : forcing value to bool 'true' or 'false' (performance warning)
-#endif
-
-#if defined(BOOST_GCC) && BOOST_GCC >= 40600
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wlogical-op"
-#endif
+/* boost random/detail/disable_warnings.hpp header file
+ *
+ * Copyright Steven Watanabe 2009
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ */
+
+// No #include guard. This header is intended to be included multiple times.
+
+#include <boost/config.hpp>
+
+#ifdef BOOST_MSVC
+#pragma warning(push)
+#pragma warning(disable:4512)
+#pragma warning(disable:4127)
+#pragma warning(disable:4724)
+#pragma warning(disable:4800) // 'int' : forcing value to bool 'true' or 'false' (performance warning)
+#endif
+
+#if defined(BOOST_GCC) && BOOST_GCC >= 40600
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wlogical-op"
+#endif
diff --git a/contrib/src/boost/random/detail/enable_warnings.hpp b/contrib/src/boost/random/detail/enable_warnings.hpp
index 24f3bb3..9665606 100644
--- a/contrib/src/boost/random/detail/enable_warnings.hpp
+++ b/contrib/src/boost/random/detail/enable_warnings.hpp
@@ -1,22 +1,22 @@
-/* boost random/detail/enable_warnings.hpp header file
- *
- * Copyright Steven Watanabe 2009
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- */
-
-// No #include guard. This header is intended to be included multiple times.
-
-#ifdef BOOST_MSVC
-#pragma warning(pop)
-#endif
-
-#if defined(BOOST_GCC) && BOOST_GCC >= 40600
-#pragma GCC diagnostic pop
-#endif
+/* boost random/detail/enable_warnings.hpp header file
+ *
+ * Copyright Steven Watanabe 2009
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ */
+
+// No #include guard. This header is intended to be included multiple times.
+
+#ifdef BOOST_MSVC
+#pragma warning(pop)
+#endif
+
+#if defined(BOOST_GCC) && BOOST_GCC >= 40600
+#pragma GCC diagnostic pop
+#endif
diff --git a/contrib/src/boost/random/detail/generator_bits.hpp b/contrib/src/boost/random/detail/generator_bits.hpp
index 0527614..99de1a7 100644
--- a/contrib/src/boost/random/detail/generator_bits.hpp
+++ b/contrib/src/boost/random/detail/generator_bits.hpp
@@ -1,36 +1,36 @@
-/* boost random/detail/generator_bits.hpp header file
- *
- * Copyright Steven Watanabe 2011
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- */
-
-#ifndef BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
-#define BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
-
-#include <boost/limits.hpp>
-
-namespace boost {
-namespace random {
-namespace detail {
-
-// This is a temporary measure that retains backwards
-// compatibility.
-template<class URNG>
-struct generator_bits {
- static std::size_t value() {
- return std::numeric_limits<typename URNG::result_type>::digits;
- }
-};
-
-} // namespace detail
-} // namespace random
-} // namespace boost
-
-#endif // BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
+/* boost random/detail/generator_bits.hpp header file
+ *
+ * Copyright Steven Watanabe 2011
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
+#define BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
+
+#include <boost/limits.hpp>
+
+namespace boost {
+namespace random {
+namespace detail {
+
+// This is a temporary measure that retains backwards
+// compatibility.
+template<class URNG>
+struct generator_bits {
+ static std::size_t value() {
+ return std::numeric_limits<typename URNG::result_type>::digits;
+ }
+};
+
+} // namespace detail
+} // namespace random
+} // namespace boost
+
+#endif // BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
diff --git a/contrib/src/boost/random/detail/generator_seed_seq.hpp b/contrib/src/boost/random/detail/generator_seed_seq.hpp
index 7e13483..179c811 100644
--- a/contrib/src/boost/random/detail/generator_seed_seq.hpp
+++ b/contrib/src/boost/random/detail/generator_seed_seq.hpp
@@ -1,40 +1,40 @@
-/* boost random/mersenne_twister.hpp header file
- *
- * Copyright Jens Maurer 2000-2001
- * Copyright Steven Watanabe 2010
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- */
-
-#ifndef BOOST_RANDOM_DETAIL_GENERATOR_SEED_SEQ_HPP_INCLUDED
-#define BOOST_RANDOM_DETAIL_GENERATOR_SEED_SEQ_HPP_INCLUDED
-
-namespace boost {
-namespace random {
-namespace detail {
-
-template<class Generator>
-class generator_seed_seq {
-public:
- generator_seed_seq(Generator& g) : gen(&g) {}
- template<class It>
- void generate(It first, It last) {
- for(; first != last; ++first) {
- *first = (*gen)();
- }
- }
-private:
- Generator* gen;
-};
-
-}
-}
-}
-
-#endif
+/* boost random/mersenne_twister.hpp header file
+ *
+ * Copyright Jens Maurer 2000-2001
+ * Copyright Steven Watanabe 2010
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_GENERATOR_SEED_SEQ_HPP_INCLUDED
+#define BOOST_RANDOM_DETAIL_GENERATOR_SEED_SEQ_HPP_INCLUDED
+
+namespace boost {
+namespace random {
+namespace detail {
+
+template<class Generator>
+class generator_seed_seq {
+public:
+ generator_seed_seq(Generator& g) : gen(&g) {}
+ template<class It>
+ void generate(It first, It last) {
+ for(; first != last; ++first) {
+ *first = (*gen)();
+ }
+ }
+private:
+ Generator* gen;
+};
+
+}
+}
+}
+
+#endif
diff --git a/contrib/src/boost/random/detail/integer_log2.hpp b/contrib/src/boost/random/detail/integer_log2.hpp
index 248243a..7f8b941 100644
--- a/contrib/src/boost/random/detail/integer_log2.hpp
+++ b/contrib/src/boost/random/detail/integer_log2.hpp
@@ -1,84 +1,84 @@
-/* boost random/detail/integer_log2.hpp header file
- *
- * Copyright Steven Watanabe 2011
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- */
-
-#ifndef BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
-#define BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
-
-#include <boost/config.hpp>
-#include <boost/limits.hpp>
-#include <boost/pending/integer_log2.hpp>
-
-namespace boost {
-namespace random {
-namespace detail {
-
-#if !defined(BOOST_NO_CXX11_CONSTEXPR)
-#define BOOST_RANDOM_DETAIL_CONSTEXPR constexpr
-#elif defined(BOOST_MSVC)
-#define BOOST_RANDOM_DETAIL_CONSTEXPR __forceinline
-#elif defined(__GNUC__) && __GNUC__ >= 4
-#define BOOST_RANDOM_DETAIL_CONSTEXPR inline __attribute__((__const__)) __attribute__((__always_inline__))
-#else
-#define BOOST_RANDOM_DETAIL_CONSTEXPR inline
-#endif
-
-template<int Shift>
-struct integer_log2_impl
-{
-#if defined(BOOST_NO_CXX11_CONSTEXPR)
- template<class T>
- BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
- {
- int update = ((t >> Shift) != 0) * Shift;
- return integer_log2_impl<Shift / 2>::apply(t >> update, accum + update);
- }
-#else
- template<class T>
- BOOST_RANDOM_DETAIL_CONSTEXPR static int apply2(T t, int accum, int update)
- {
- return integer_log2_impl<Shift / 2>::apply(t >> update, accum + update);
- }
-
- template<class T>
- BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
- {
- return apply2(t, accum, ((t >> Shift) != 0) * Shift);
- }
-#endif
-};
-
-template<>
-struct integer_log2_impl<1>
-{
- template<class T>
- BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
- {
- return int(t >> 1) + accum;
- }
-};
-
-template<class T>
-BOOST_RANDOM_DETAIL_CONSTEXPR int integer_log2(T t)
-{
- return integer_log2_impl<
- ::boost::detail::max_pow2_less<
- ::std::numeric_limits<T>::digits, 4
- >::value
- >::apply(t, 0);
-}
-
-} // namespace detail
-} // namespace random
-} // namespace boost
-
-#endif // BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
+/* boost random/detail/integer_log2.hpp header file
+ *
+ * Copyright Steven Watanabe 2011
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
+#define BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
+
+#include <boost/config.hpp>
+#include <boost/limits.hpp>
+#include <boost/pending/integer_log2.hpp>
+
+namespace boost {
+namespace random {
+namespace detail {
+
+#if !defined(BOOST_NO_CXX11_CONSTEXPR)
+#define BOOST_RANDOM_DETAIL_CONSTEXPR constexpr
+#elif defined(BOOST_MSVC)
+#define BOOST_RANDOM_DETAIL_CONSTEXPR __forceinline
+#elif defined(__GNUC__) && __GNUC__ >= 4
+#define BOOST_RANDOM_DETAIL_CONSTEXPR inline __attribute__((__const__)) __attribute__((__always_inline__))
+#else
+#define BOOST_RANDOM_DETAIL_CONSTEXPR inline
+#endif
+
+template<int Shift>
+struct integer_log2_impl
+{
+#if defined(BOOST_NO_CXX11_CONSTEXPR)
+ template<class T>
+ BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
+ {
+ int update = ((t >> Shift) != 0) * Shift;
+ return integer_log2_impl<Shift / 2>::apply(t >> update, accum + update);
+ }
+#else
+ template<class T>
+ BOOST_RANDOM_DETAIL_CONSTEXPR static int apply2(T t, int accum, int update)
+ {
+ return integer_log2_impl<Shift / 2>::apply(t >> update, accum + update);
+ }
+
+ template<class T>
+ BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
+ {
+ return apply2(t, accum, ((t >> Shift) != 0) * Shift);
+ }
+#endif
+};
+
+template<>
+struct integer_log2_impl<1>
+{
+ template<class T>
+ BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
+ {
+ return int(t >> 1) + accum;
+ }
+};
+
+template<class T>
+BOOST_RANDOM_DETAIL_CONSTEXPR int integer_log2(T t)
+{
+ return integer_log2_impl<
+ ::boost::detail::max_pow2_less<
+ ::std::numeric_limits<T>::digits, 4
+ >::value
+ >::apply(t, 0);
+}
+
+} // namespace detail
+} // namespace random
+} // namespace boost
+
+#endif // BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
diff --git a/contrib/src/boost/random/detail/large_arithmetic.hpp b/contrib/src/boost/random/detail/large_arithmetic.hpp
index 66f6b4e..13aeb6f 100644
--- a/contrib/src/boost/random/detail/large_arithmetic.hpp
+++ b/contrib/src/boost/random/detail/large_arithmetic.hpp
@@ -1,122 +1,122 @@
-/* boost random/detail/large_arithmetic.hpp header file
- *
- * Copyright Steven Watanabe 2011
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- */
-
-#ifndef BOOST_RANDOM_DETAIL_LARGE_ARITHMETIC_HPP
-#define BOOST_RANDOM_DETAIL_LARGE_ARITHMETIC_HPP
-
-#include <boost/cstdint.hpp>
-#include <boost/integer.hpp>
-#include <boost/limits.hpp>
-#include <boost/random/detail/integer_log2.hpp>
-
-#include <boost/random/detail/disable_warnings.hpp>
-
-namespace boost {
-namespace random {
-namespace detail {
-
-struct div_t {
- boost::uintmax_t quotient;
- boost::uintmax_t remainder;
-};
-
-inline div_t muldivmod(boost::uintmax_t a, boost::uintmax_t b, boost::uintmax_t m)
-{
- const int bits =
- ::std::numeric_limits< ::boost::uintmax_t>::digits / 2;
- const ::boost::uintmax_t mask = (::boost::uintmax_t(1) << bits) - 1;
- typedef ::boost::uint_t<bits>::fast digit_t;
-
- int shift = std::numeric_limits< ::boost::uintmax_t>::digits - 1
- - detail::integer_log2(m);
-
- a <<= shift;
- m <<= shift;
-
- digit_t product[4] = { 0, 0, 0, 0 };
- digit_t a_[2] = { digit_t(a & mask), digit_t((a >> bits) & mask) };
- digit_t b_[2] = { digit_t(b & mask), digit_t((b >> bits) & mask) };
- digit_t m_[2] = { digit_t(m & mask), digit_t((m >> bits) & mask) };
-
- // multiply a * b
- for(int i = 0; i < 2; ++i) {
- digit_t carry = 0;
- for(int j = 0; j < 2; ++j) {
- ::boost::uint64_t temp = ::boost::uintmax_t(a_[i]) * b_[j] +
- carry + product[i + j];
- product[i + j] = digit_t(temp & mask);
- carry = digit_t(temp >> bits);
- }
- if(carry != 0) {
- product[i + 2] += carry;
- }
- }
-
- digit_t quotient[2];
-
- if(m == 0) {
- div_t result = {
- ((::boost::uintmax_t(product[3]) << bits) | product[2]),
- ((::boost::uintmax_t(product[1]) << bits) | product[0]) >> shift,
- };
- return result;
- }
-
- // divide product / m
- for(int i = 3; i >= 2; --i) {
- ::boost::uintmax_t temp =
- ::boost::uintmax_t(product[i]) << bits | product[i - 1];
-
- digit_t q = digit_t((product[i] == m_[1]) ? mask : temp / m_[1]);
-
- ::boost::uintmax_t rem =
- ((temp - ::boost::uintmax_t(q) * m_[1]) << bits) + product[i - 2];
-
- ::boost::uintmax_t diff = m_[0] * ::boost::uintmax_t(q);
-
- int error = 0;
- if(diff > rem) {
- if(diff - rem > m) {
- error = 2;
- } else {
- error = 1;
- }
- }
- q -= error;
- rem = rem + error * m - diff;
-
- quotient[i - 2] = q;
- product[i] = 0;
- product[i-1] = static_cast<digit_t>((rem >> bits) & mask);
- product[i-2] = static_cast<digit_t>(rem & mask);
- }
-
- div_t result = {
- ((::boost::uintmax_t(quotient[1]) << bits) | quotient[0]),
- ((::boost::uintmax_t(product[1]) << bits) | product[0]) >> shift,
- };
- return result;
-}
-
-inline boost::uintmax_t muldiv(boost::uintmax_t a, boost::uintmax_t b, boost::uintmax_t m)
-{ return detail::muldivmod(a, b, m).quotient; }
-
-inline boost::uintmax_t mulmod(boost::uintmax_t a, boost::uintmax_t b, boost::uintmax_t m)
-{ return detail::muldivmod(a, b, m).remainder; }
-
-} // namespace detail
-} // namespace random
-} // namespace boost
-
-#include <boost/random/detail/enable_warnings.hpp>
-
-#endif // BOOST_RANDOM_DETAIL_LARGE_ARITHMETIC_HPP
+/* boost random/detail/large_arithmetic.hpp header file
+ *
+ * Copyright Steven Watanabe 2011
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_LARGE_ARITHMETIC_HPP
+#define BOOST_RANDOM_DETAIL_LARGE_ARITHMETIC_HPP
+
+#include <boost/cstdint.hpp>
+#include <boost/integer.hpp>
+#include <boost/limits.hpp>
+#include <boost/random/detail/integer_log2.hpp>
+
+#include <boost/random/detail/disable_warnings.hpp>
+
+namespace boost {
+namespace random {
+namespace detail {
+
+struct div_t {
+ boost::uintmax_t quotient;
+ boost::uintmax_t remainder;
+};
+
+inline div_t muldivmod(boost::uintmax_t a, boost::uintmax_t b, boost::uintmax_t m)
+{
+ const int bits =
+ ::std::numeric_limits< ::boost::uintmax_t>::digits / 2;
+ const ::boost::uintmax_t mask = (::boost::uintmax_t(1) << bits) - 1;
+ typedef ::boost::uint_t<bits>::fast digit_t;
+
+ int shift = std::numeric_limits< ::boost::uintmax_t>::digits - 1
+ - detail::integer_log2(m);
+
+ a <<= shift;
+ m <<= shift;
+
+ digit_t product[4] = { 0, 0, 0, 0 };
+ digit_t a_[2] = { digit_t(a & mask), digit_t((a >> bits) & mask) };
+ digit_t b_[2] = { digit_t(b & mask), digit_t((b >> bits) & mask) };
+ digit_t m_[2] = { digit_t(m & mask), digit_t((m >> bits) & mask) };
+
+ // multiply a * b
+ for(int i = 0; i < 2; ++i) {
+ digit_t carry = 0;
+ for(int j = 0; j < 2; ++j) {
+ ::boost::uint64_t temp = ::boost::uintmax_t(a_[i]) * b_[j] +
+ carry + product[i + j];
+ product[i + j] = digit_t(temp & mask);
+ carry = digit_t(temp >> bits);
+ }
+ if(carry != 0) {
+ product[i + 2] += carry;
+ }
+ }
+
+ digit_t quotient[2];
+
+ if(m == 0) {
+ div_t result = {
+ ((::boost::uintmax_t(product[3]) << bits) | product[2]),
+ ((::boost::uintmax_t(product[1]) << bits) | product[0]) >> shift,
+ };
+ return result;
+ }
+
+ // divide product / m
+ for(int i = 3; i >= 2; --i) {
+ ::boost::uintmax_t temp =
+ ::boost::uintmax_t(product[i]) << bits | product[i - 1];
+
+ digit_t q = digit_t((product[i] == m_[1]) ? mask : temp / m_[1]);
+
+ ::boost::uintmax_t rem =
+ ((temp - ::boost::uintmax_t(q) * m_[1]) << bits) + product[i - 2];
+
+ ::boost::uintmax_t diff = m_[0] * ::boost::uintmax_t(q);
+
+ int error = 0;
+ if(diff > rem) {
+ if(diff - rem > m) {
+ error = 2;
+ } else {
+ error = 1;
+ }
+ }
+ q -= error;
+ rem = rem + error * m - diff;
+
+ quotient[i - 2] = q;
+ product[i] = 0;
+ product[i-1] = static_cast<digit_t>((rem >> bits) & mask);
+ product[i-2] = static_cast<digit_t>(rem & mask);
+ }
+
+ div_t result = {
+ ((::boost::uintmax_t(quotient[1]) << bits) | quotient[0]),
+ ((::boost::uintmax_t(product[1]) << bits) | product[0]) >> shift,
+ };
+ return result;
+}
+
+inline boost::uintmax_t muldiv(boost::uintmax_t a, boost::uintmax_t b, boost::uintmax_t m)
+{ return detail::muldivmod(a, b, m).quotient; }
+
+inline boost::uintmax_t mulmod(boost::uintmax_t a, boost::uintmax_t b, boost::uintmax_t m)
+{ return detail::muldivmod(a, b, m).remainder; }
+
+} // namespace detail
+} // namespace random
+} // namespace boost
+
+#include <boost/random/detail/enable_warnings.hpp>
+
+#endif // BOOST_RANDOM_DETAIL_LARGE_ARITHMETIC_HPP
diff --git a/contrib/src/boost/random/detail/operators.hpp b/contrib/src/boost/random/detail/operators.hpp
index 597343c..23aadfb 100644
--- a/contrib/src/boost/random/detail/operators.hpp
+++ b/contrib/src/boost/random/detail/operators.hpp
@@ -1,84 +1,84 @@
-/* boost random/detail/operators.hpp header file
- *
- * Copyright Steven Watanabe 2010-2011
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- */
-
-#ifndef BOOST_RANDOM_DETAIL_OPERATORS_HPP
-#define BOOST_RANDOM_DETAIL_OPERATORS_HPP
-
-#include <boost/random/detail/config.hpp>
-#include <boost/detail/workaround.hpp>
-
-#if BOOST_WORKAROUND(BOOST_MSVC, <= 1310) \
- || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
-
-#define BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, T, t) \
- template<class CharT, class Traits> \
- friend std::basic_ostream<CharT,Traits>& \
- operator<<(std::basic_ostream<CharT,Traits>& os, const T& t) { \
- t.print(os, t); \
- return os; \
- } \
- template<class CharT, class Traits> \
- static std::basic_ostream<CharT,Traits>& \
- print(std::basic_ostream<CharT,Traits>& os, const T& t)
-
-#define BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, T, t) \
- template<class CharT, class Traits> \
- friend std::basic_istream<CharT,Traits>& \
- operator>>(std::basic_istream<CharT,Traits>& is, T& t) { \
- t.read(is, t); \
- return is; \
- } \
- template<class CharT, class Traits> \
- static std::basic_istream<CharT,Traits>& \
- read(std::basic_istream<CharT,Traits>& is, T& t)
-
-#endif
-
-#if defined(__BORLANDC__)
-
-#define BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(T, lhs, rhs) \
- bool operator==(const T& rhs) const \
- { return T::is_equal(*this, rhs); } \
- static bool is_equal(const T& lhs, const T& rhs)
-
-#define BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(T) \
- bool operator!=(const T& rhs) const \
- { return !T::is_equal(*this, rhs); }
-
-#endif
-
-#ifndef BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR
-#define BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, T, t) \
- template<class CharT, class Traits> \
- friend std::basic_ostream<CharT,Traits>& \
- operator<<(std::basic_ostream<CharT,Traits>& os, const T& t)
-#endif
-
-#ifndef BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR
-#define BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, T, t) \
- template<class CharT, class Traits> \
- friend std::basic_istream<CharT,Traits>& \
- operator>>(std::basic_istream<CharT,Traits>& is, T& t)
-#endif
-
-#ifndef BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR
-#define BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(T, lhs, rhs) \
- friend bool operator==(const T& lhs, const T& rhs)
-#endif
-
-#ifndef BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR
-#define BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(T) \
- friend bool operator!=(const T& lhs, const T& rhs) \
- { return !(lhs == rhs); }
-#endif
-
-#endif
+/* boost random/detail/operators.hpp header file
+ *
+ * Copyright Steven Watanabe 2010-2011
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_OPERATORS_HPP
+#define BOOST_RANDOM_DETAIL_OPERATORS_HPP
+
+#include <boost/random/detail/config.hpp>
+#include <boost/detail/workaround.hpp>
+
+#if BOOST_WORKAROUND(BOOST_MSVC, <= 1310) \
+ || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
+
+#define BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, T, t) \
+ template<class CharT, class Traits> \
+ friend std::basic_ostream<CharT,Traits>& \
+ operator<<(std::basic_ostream<CharT,Traits>& os, const T& t) { \
+ t.print(os, t); \
+ return os; \
+ } \
+ template<class CharT, class Traits> \
+ static std::basic_ostream<CharT,Traits>& \
+ print(std::basic_ostream<CharT,Traits>& os, const T& t)
+
+#define BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, T, t) \
+ template<class CharT, class Traits> \
+ friend std::basic_istream<CharT,Traits>& \
+ operator>>(std::basic_istream<CharT,Traits>& is, T& t) { \
+ t.read(is, t); \
+ return is; \
+ } \
+ template<class CharT, class Traits> \
+ static std::basic_istream<CharT,Traits>& \
+ read(std::basic_istream<CharT,Traits>& is, T& t)
+
+#endif
+
+#if defined(__BORLANDC__)
+
+#define BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(T, lhs, rhs) \
+ bool operator==(const T& rhs) const \
+ { return T::is_equal(*this, rhs); } \
+ static bool is_equal(const T& lhs, const T& rhs)
+
+#define BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(T) \
+ bool operator!=(const T& rhs) const \
+ { return !T::is_equal(*this, rhs); }
+
+#endif
+
+#ifndef BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR
+#define BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, T, t) \
+ template<class CharT, class Traits> \
+ friend std::basic_ostream<CharT,Traits>& \
+ operator<<(std::basic_ostream<CharT,Traits>& os, const T& t)
+#endif
+
+#ifndef BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR
+#define BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, T, t) \
+ template<class CharT, class Traits> \
+ friend std::basic_istream<CharT,Traits>& \
+ operator>>(std::basic_istream<CharT,Traits>& is, T& t)
+#endif
+
+#ifndef BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR
+#define BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(T, lhs, rhs) \
+ friend bool operator==(const T& lhs, const T& rhs)
+#endif
+
+#ifndef BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR
+#define BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(T) \
+ friend bool operator!=(const T& lhs, const T& rhs) \
+ { return !(lhs == rhs); }
+#endif
+
+#endif
diff --git a/contrib/src/boost/random/detail/polynomial.hpp b/contrib/src/boost/random/detail/polynomial.hpp
index a8c4b26..cc4ecd9 100644
--- a/contrib/src/boost/random/detail/polynomial.hpp
+++ b/contrib/src/boost/random/detail/polynomial.hpp
@@ -1,384 +1,384 @@
-/* boost random/detail/polynomial.hpp header file
- *
- * Copyright Steven Watanabe 2014
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- */
-
-#ifndef BOOST_RANDOM_DETAIL_POLYNOMIAL_HPP
-#define BOOST_RANDOM_DETAIL_POLYNOMIAL_HPP
-
-#include <cstddef>
-#include <limits>
-#include <vector>
-#include <algorithm>
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-namespace boost {
-namespace random {
-namespace detail {
-
-class polynomial_ops {
-public:
- typedef unsigned long digit_t;
-
- static void add(std::size_t size, const digit_t * lhs,
- const digit_t * rhs, digit_t * output)
- {
- for(std::size_t i = 0; i < size; ++i) {
- output[i] = lhs[i] ^ rhs[i];
- }
- }
-
- static void add_shifted_inplace(std::size_t size, const digit_t * lhs,
- digit_t * output, std::size_t shift)
- {
- if(shift == 0) {
- add(size, lhs, output, output);
- return;
- }
- std::size_t bits = std::numeric_limits<digit_t>::digits;
- digit_t prev = 0;
- for(std::size_t i = 0; i < size; ++i) {
- digit_t tmp = lhs[i];
- output[i] ^= (tmp << shift) | (prev >> (bits-shift));
- prev = tmp;
- }
- output[size] ^= (prev >> (bits-shift));
- }
-
- static void multiply_simple(std::size_t size, const digit_t * lhs,
- const digit_t * rhs, digit_t * output)
- {
- std::size_t bits = std::numeric_limits<digit_t>::digits;
- for(std::size_t i = 0; i < 2*size; ++i) {
- output[i] = 0;
- }
- for(std::size_t i = 0; i < size; ++i) {
- for(std::size_t j = 0; j < bits; ++j) {
- if((lhs[i] & (digit_t(1) << j)) != 0) {
- add_shifted_inplace(size, rhs, output + i, j);
- }
- }
- }
- }
-
- // memory requirements: (size - cutoff) * 4 + next_smaller
- static void multiply_karatsuba(std::size_t size,
- const digit_t * lhs, const digit_t * rhs,
- digit_t * output)
- {
- if(size < 64) {
- multiply_simple(size, lhs, rhs, output);
- return;
- }
- // split in half
- std::size_t cutoff = size/2;
- multiply_karatsuba(cutoff, lhs, rhs, output);
- multiply_karatsuba(size - cutoff, lhs + cutoff, rhs + cutoff,
- output + cutoff*2);
- std::vector<digit_t> local1(size - cutoff);
- std::vector<digit_t> local2(size - cutoff);
- // combine the digits for the inner multiply
- add(cutoff, lhs, lhs + cutoff, &local1[0]);
- if(size & 1) local1[cutoff] = lhs[size - 1];
- add(cutoff, rhs + cutoff, rhs, &local2[0]);
- if(size & 1) local2[cutoff] = rhs[size - 1];
- std::vector<digit_t> local3((size - cutoff) * 2);
- multiply_karatsuba(size - cutoff, &local1[0], &local2[0], &local3[0]);
- add(cutoff * 2, output, &local3[0], &local3[0]);
- add((size - cutoff) * 2, output + cutoff*2, &local3[0], &local3[0]);
- // Finally, add the inner result
- add((size - cutoff) * 2, output + cutoff, &local3[0], output + cutoff);
- }
-
- static void multiply_add_karatsuba(std::size_t size,
- const digit_t * lhs, const digit_t * rhs,
- digit_t * output)
- {
- std::vector<digit_t> buf(size * 2);
- multiply_karatsuba(size, lhs, rhs, &buf[0]);
- add(size * 2, &buf[0], output, output);
- }
-
- static void multiply(const digit_t * lhs, std::size_t lhs_size,
- const digit_t * rhs, std::size_t rhs_size,
- digit_t * output)
- {
- std::fill_n(output, lhs_size + rhs_size, digit_t(0));
- multiply_add(lhs, lhs_size, rhs, rhs_size, output);
- }
-
- static void multiply_add(const digit_t * lhs, std::size_t lhs_size,
- const digit_t * rhs, std::size_t rhs_size,
- digit_t * output)
- {
- // split into pieces that can be passed to
- // karatsuba multiply.
- while(lhs_size != 0) {
- if(lhs_size < rhs_size) {
- std::swap(lhs, rhs);
- std::swap(lhs_size, rhs_size);
- }
-
- multiply_add_karatsuba(rhs_size, lhs, rhs, output);
-
- lhs += rhs_size;
- lhs_size -= rhs_size;
- output += rhs_size;
- }
- }
-
- static void copy_bits(const digit_t * x, std::size_t low, std::size_t high,
- digit_t * out)
- {
- const std::size_t bits = std::numeric_limits<digit_t>::digits;
- std::size_t offset = low/bits;
- x += offset;
- low -= offset*bits;
- high -= offset*bits;
- std::size_t n = (high-low)/bits;
- if(low == 0) {
- for(std::size_t i = 0; i < n; ++i) {
- out[i] = x[i];
- }
- } else {
- for(std::size_t i = 0; i < n; ++i) {
- out[i] = (x[i] >> low) | (x[i+1] << (bits-low));
- }
- }
- if((high-low)%bits) {
- digit_t low_mask = (digit_t(1) << ((high-low)%bits)) - 1;
- digit_t result = (x[n] >> low);
- if(low != 0 && (n+1)*bits < high) {
- result |= (x[n+1] << (bits-low));
- }
- out[n] = (result & low_mask);
- }
- }
-
- static void shift_left(digit_t * val, std::size_t size, std::size_t shift)
- {
- const std::size_t bits = std::numeric_limits<digit_t>::digits;
- BOOST_ASSERT(shift > 0);
- BOOST_ASSERT(shift < bits);
- digit_t prev = 0;
- for(std::size_t i = 0; i < size; ++i) {
- digit_t tmp = val[i];
- val[i] = (prev >> (bits - shift)) | (val[i] << shift);
- prev = tmp;
- }
- }
-
- static digit_t sqr(digit_t val) {
- const std::size_t bits = std::numeric_limits<digit_t>::digits;
- digit_t mask = (digit_t(1) << bits/2) - 1;
- for(std::size_t i = bits; i > 1; i /= 2) {
- val = ((val & ~mask) << i/2) | (val & mask);
- mask = mask & (mask >> i/4);
- mask = mask | (mask << i/2);
- }
- return val;
- }
-
- static void sqr(digit_t * val, std::size_t size)
- {
- const std::size_t bits = std::numeric_limits<digit_t>::digits;
- digit_t mask = (digit_t(1) << bits/2) - 1;
- for(std::size_t i = 0; i < size; ++i) {
- digit_t x = val[size - i - 1];
- val[(size - i - 1) * 2] = sqr(x & mask);
- val[(size - i - 1) * 2 + 1] = sqr(x >> bits/2);
- }
- }
-
- // optimized for the case when the modulus has few bits set.
- struct sparse_mod {
- sparse_mod(const digit_t * divisor, std::size_t divisor_bits)
- {
- const std::size_t bits = std::numeric_limits<digit_t>::digits;
- _remainder_bits = divisor_bits - 1;
- for(std::size_t i = 0; i < divisor_bits; ++i) {
- if(divisor[i/bits] & (digit_t(1) << i%bits)) {
- _bit_indices.push_back(i);
- }
- }
- BOOST_ASSERT(_bit_indices.back() == divisor_bits - 1);
- _bit_indices.pop_back();
- if(_bit_indices.empty()) {
- _block_bits = divisor_bits;
- _lower_bits = 0;
- } else {
- _block_bits = divisor_bits - _bit_indices.back() - 1;
- _lower_bits = _bit_indices.back() + 1;
- }
-
- _partial_quotient.resize((_block_bits + bits - 1)/bits);
- }
- void operator()(digit_t * dividend, std::size_t dividend_bits)
- {
- const std::size_t bits = std::numeric_limits<digit_t>::digits;
- while(dividend_bits > _remainder_bits) {
- std::size_t block_start = (std::max)(dividend_bits - _block_bits, _remainder_bits);
- std::size_t block_size = (dividend_bits - block_start + bits - 1) / bits;
- copy_bits(dividend, block_start, dividend_bits, &_partial_quotient[0]);
- for(std::size_t i = 0; i < _bit_indices.size(); ++i) {
- std::size_t pos = _bit_indices[i] + block_start - _remainder_bits;
- add_shifted_inplace(block_size, &_partial_quotient[0], dividend + pos/bits, pos%bits);
- }
- add_shifted_inplace(block_size, &_partial_quotient[0], dividend + block_start/bits, block_start%bits);
- dividend_bits = block_start;
- }
- }
- std::vector<digit_t> _partial_quotient;
- std::size_t _remainder_bits;
- std::size_t _block_bits;
- std::size_t _lower_bits;
- std::vector<std::size_t> _bit_indices;
- };
-
- // base should have the same number of bits as mod
- // base, and mod should both be able to hold a power
- // of 2 >= mod_bits. out needs to be twice as large.
- static void mod_pow_x(boost::uintmax_t exponent, const digit_t * mod, std::size_t mod_bits, digit_t * out)
- {
- const std::size_t bits = std::numeric_limits<digit_t>::digits;
- const std::size_t n = (mod_bits + bits - 1) / bits;
- const std::size_t highbit = mod_bits - 1;
- if(exponent == 0) {
- out[0] = 1;
- std::fill_n(out + 1, n - 1, digit_t(0));
- return;
- }
- boost::uintmax_t i = std::numeric_limits<boost::uintmax_t>::digits - 1;
- while(((boost::uintmax_t(1) << i) & exponent) == 0) {
- --i;
- }
- out[0] = 2;
- std::fill_n(out + 1, n - 1, digit_t(0));
- sparse_mod m(mod, mod_bits);
- while(i--) {
- sqr(out, n);
- m(out, 2 * mod_bits - 1);
- if((boost::uintmax_t(1) << i) & exponent) {
- shift_left(out, n, 1);
- if(out[highbit / bits] & (digit_t(1) << highbit%bits))
- add(n, out, mod, out);
- }
- }
- }
-};
-
-class polynomial
-{
- typedef polynomial_ops::digit_t digit_t;
-public:
- polynomial() : _size(0) {}
- class reference {
- public:
- reference(digit_t &value, int idx)
- : _value(value), _idx(idx) {}
- operator bool() const { return (_value & (digit_t(1) << _idx)) != 0; }
- reference& operator=(bool b)
- {
- if(b) {
- _value |= (digit_t(1) << _idx);
- } else {
- _value &= ~(digit_t(1) << _idx);
- }
- return *this;
- }
- reference &operator^=(bool b)
- {
- _value ^= (digit_t(b) << _idx);
- return *this;
- }
-
- reference &operator=(const reference &other)
- {
- return *this = static_cast<bool>(other);
- }
- private:
- digit_t &_value;
- int _idx;
- };
- reference operator[](std::size_t i)
- {
- static const std::size_t bits = std::numeric_limits<digit_t>::digits;
- ensure_bit(i);
- return reference(_storage[i/bits], i%bits);
- }
- bool operator[](std::size_t i) const
- {
- static const std::size_t bits = std::numeric_limits<digit_t>::digits;
- if(i < size())
- return (_storage[i/bits] & (digit_t(1) << (i%bits))) != 0;
- else
- return false;
- }
- std::size_t size() const
- {
- return _size;
- }
- void resize(std::size_t n)
- {
- static const std::size_t bits = std::numeric_limits<digit_t>::digits;
- _storage.resize((n + bits - 1)/bits);
- // clear the high order bits in case we're shrinking.
- if(n%bits) {
- _storage.back() &= ((digit_t(1) << (n%bits)) - 1);
- }
- _size = n;
- }
- friend polynomial operator*(const polynomial &lhs, const polynomial &rhs);
- friend polynomial mod_pow_x(boost::uintmax_t exponent, polynomial mod);
-private:
- std::vector<polynomial_ops::digit_t> _storage;
- std::size_t _size;
- void ensure_bit(std::size_t i)
- {
- if(i >= size()) {
- resize(i + 1);
- }
- }
- void normalize()
- {
- while(size() && (*this)[size() - 1] == 0)
- resize(size() - 1);
- }
-};
-
-inline polynomial operator*(const polynomial &lhs, const polynomial &rhs)
-{
- polynomial result;
- result._storage.resize(lhs._storage.size() + rhs._storage.size());
- polynomial_ops::multiply(&lhs._storage[0], lhs._storage.size(),
- &rhs._storage[0], rhs._storage.size(),
- &result._storage[0]);
- result._size = lhs._size + rhs._size;
- return result;
-}
-
-inline polynomial mod_pow_x(boost::uintmax_t exponent, polynomial mod)
-{
- polynomial result;
- mod.normalize();
- std::size_t mod_size = mod.size();
- result._storage.resize(mod._storage.size() * 2);
- result._size = mod.size() * 2;
- polynomial_ops::mod_pow_x(exponent, &mod._storage[0], mod_size, &result._storage[0]);
- result.resize(mod.size() - 1);
- return result;
-}
-
-}
-}
-}
-
-#endif // BOOST_RANDOM_DETAIL_POLYNOMIAL_HPP
+/* boost random/detail/polynomial.hpp header file
+ *
+ * Copyright Steven Watanabe 2014
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_POLYNOMIAL_HPP
+#define BOOST_RANDOM_DETAIL_POLYNOMIAL_HPP
+
+#include <cstddef>
+#include <limits>
+#include <vector>
+#include <algorithm>
+#include <boost/assert.hpp>
+#include <boost/cstdint.hpp>
+
+namespace boost {
+namespace random {
+namespace detail {
+
+class polynomial_ops {
+public:
+ typedef unsigned long digit_t;
+
+ static void add(std::size_t size, const digit_t * lhs,
+ const digit_t * rhs, digit_t * output)
+ {
+ for(std::size_t i = 0; i < size; ++i) {
+ output[i] = lhs[i] ^ rhs[i];
+ }
+ }
+
+ static void add_shifted_inplace(std::size_t size, const digit_t * lhs,
+ digit_t * output, std::size_t shift)
+ {
+ if(shift == 0) {
+ add(size, lhs, output, output);
+ return;
+ }
+ std::size_t bits = std::numeric_limits<digit_t>::digits;
+ digit_t prev = 0;
+ for(std::size_t i = 0; i < size; ++i) {
+ digit_t tmp = lhs[i];
+ output[i] ^= (tmp << shift) | (prev >> (bits-shift));
+ prev = tmp;
+ }
+ output[size] ^= (prev >> (bits-shift));
+ }
+
+ static void multiply_simple(std::size_t size, const digit_t * lhs,
+ const digit_t * rhs, digit_t * output)
+ {
+ std::size_t bits = std::numeric_limits<digit_t>::digits;
+ for(std::size_t i = 0; i < 2*size; ++i) {
+ output[i] = 0;
+ }
+ for(std::size_t i = 0; i < size; ++i) {
+ for(std::size_t j = 0; j < bits; ++j) {
+ if((lhs[i] & (digit_t(1) << j)) != 0) {
+ add_shifted_inplace(size, rhs, output + i, j);
+ }
+ }
+ }
+ }
+
+ // memory requirements: (size - cutoff) * 4 + next_smaller
+ static void multiply_karatsuba(std::size_t size,
+ const digit_t * lhs, const digit_t * rhs,
+ digit_t * output)
+ {
+ if(size < 64) {
+ multiply_simple(size, lhs, rhs, output);
+ return;
+ }
+ // split in half
+ std::size_t cutoff = size/2;
+ multiply_karatsuba(cutoff, lhs, rhs, output);
+ multiply_karatsuba(size - cutoff, lhs + cutoff, rhs + cutoff,
+ output + cutoff*2);
+ std::vector<digit_t> local1(size - cutoff);
+ std::vector<digit_t> local2(size - cutoff);
+ // combine the digits for the inner multiply
+ add(cutoff, lhs, lhs + cutoff, &local1[0]);
+ if(size & 1) local1[cutoff] = lhs[size - 1];
+ add(cutoff, rhs + cutoff, rhs, &local2[0]);
+ if(size & 1) local2[cutoff] = rhs[size - 1];
+ std::vector<digit_t> local3((size - cutoff) * 2);
+ multiply_karatsuba(size - cutoff, &local1[0], &local2[0], &local3[0]);
+ add(cutoff * 2, output, &local3[0], &local3[0]);
+ add((size - cutoff) * 2, output + cutoff*2, &local3[0], &local3[0]);
+ // Finally, add the inner result
+ add((size - cutoff) * 2, output + cutoff, &local3[0], output + cutoff);
+ }
+
+ static void multiply_add_karatsuba(std::size_t size,
+ const digit_t * lhs, const digit_t * rhs,
+ digit_t * output)
+ {
+ std::vector<digit_t> buf(size * 2);
+ multiply_karatsuba(size, lhs, rhs, &buf[0]);
+ add(size * 2, &buf[0], output, output);
+ }
+
+ static void multiply(const digit_t * lhs, std::size_t lhs_size,
+ const digit_t * rhs, std::size_t rhs_size,
+ digit_t * output)
+ {
+ std::fill_n(output, lhs_size + rhs_size, digit_t(0));
+ multiply_add(lhs, lhs_size, rhs, rhs_size, output);
+ }
+
+ static void multiply_add(const digit_t * lhs, std::size_t lhs_size,
+ const digit_t * rhs, std::size_t rhs_size,
+ digit_t * output)
+ {
+ // split into pieces that can be passed to
+ // karatsuba multiply.
+ while(lhs_size != 0) {
+ if(lhs_size < rhs_size) {
+ std::swap(lhs, rhs);
+ std::swap(lhs_size, rhs_size);
+ }
+
+ multiply_add_karatsuba(rhs_size, lhs, rhs, output);
+
+ lhs += rhs_size;
+ lhs_size -= rhs_size;
+ output += rhs_size;
+ }
+ }
+
+ static void copy_bits(const digit_t * x, std::size_t low, std::size_t high,
+ digit_t * out)
+ {
+ const std::size_t bits = std::numeric_limits<digit_t>::digits;
+ std::size_t offset = low/bits;
+ x += offset;
+ low -= offset*bits;
+ high -= offset*bits;
+ std::size_t n = (high-low)/bits;
+ if(low == 0) {
+ for(std::size_t i = 0; i < n; ++i) {
+ out[i] = x[i];
+ }
+ } else {
+ for(std::size_t i = 0; i < n; ++i) {
+ out[i] = (x[i] >> low) | (x[i+1] << (bits-low));
+ }
+ }
+ if((high-low)%bits) {
+ digit_t low_mask = (digit_t(1) << ((high-low)%bits)) - 1;
+ digit_t result = (x[n] >> low);
+ if(low != 0 && (n+1)*bits < high) {
+ result |= (x[n+1] << (bits-low));
+ }
+ out[n] = (result & low_mask);
+ }
+ }
+
+ static void shift_left(digit_t * val, std::size_t size, std::size_t shift)
+ {
+ const std::size_t bits = std::numeric_limits<digit_t>::digits;
+ BOOST_ASSERT(shift > 0);
+ BOOST_ASSERT(shift < bits);
+ digit_t prev = 0;
+ for(std::size_t i = 0; i < size; ++i) {
+ digit_t tmp = val[i];
+ val[i] = (prev >> (bits - shift)) | (val[i] << shift);
+ prev = tmp;
+ }
+ }
+
+ static digit_t sqr(digit_t val) {
+ const std::size_t bits = std::numeric_limits<digit_t>::digits;
+ digit_t mask = (digit_t(1) << bits/2) - 1;
+ for(std::size_t i = bits; i > 1; i /= 2) {
+ val = ((val & ~mask) << i/2) | (val & mask);
+ mask = mask & (mask >> i/4);
+ mask = mask | (mask << i/2);
+ }
+ return val;
+ }
+
+ static void sqr(digit_t * val, std::size_t size)
+ {
+ const std::size_t bits = std::numeric_limits<digit_t>::digits;
+ digit_t mask = (digit_t(1) << bits/2) - 1;
+ for(std::size_t i = 0; i < size; ++i) {
+ digit_t x = val[size - i - 1];
+ val[(size - i - 1) * 2] = sqr(x & mask);
+ val[(size - i - 1) * 2 + 1] = sqr(x >> bits/2);
+ }
+ }
+
+ // optimized for the case when the modulus has few bits set.
+ struct sparse_mod {
+ sparse_mod(const digit_t * divisor, std::size_t divisor_bits)
+ {
+ const std::size_t bits = std::numeric_limits<digit_t>::digits;
+ _remainder_bits = divisor_bits - 1;
+ for(std::size_t i = 0; i < divisor_bits; ++i) {
+ if(divisor[i/bits] & (digit_t(1) << i%bits)) {
+ _bit_indices.push_back(i);
+ }
+ }
+ BOOST_ASSERT(_bit_indices.back() == divisor_bits - 1);
+ _bit_indices.pop_back();
+ if(_bit_indices.empty()) {
+ _block_bits = divisor_bits;
+ _lower_bits = 0;
+ } else {
+ _block_bits = divisor_bits - _bit_indices.back() - 1;
+ _lower_bits = _bit_indices.back() + 1;
+ }
+
+ _partial_quotient.resize((_block_bits + bits - 1)/bits);
+ }
+ void operator()(digit_t * dividend, std::size_t dividend_bits)
+ {
+ const std::size_t bits = std::numeric_limits<digit_t>::digits;
+ while(dividend_bits > _remainder_bits) {
+ std::size_t block_start = (std::max)(dividend_bits - _block_bits, _remainder_bits);
+ std::size_t block_size = (dividend_bits - block_start + bits - 1) / bits;
+ copy_bits(dividend, block_start, dividend_bits, &_partial_quotient[0]);
+ for(std::size_t i = 0; i < _bit_indices.size(); ++i) {
+ std::size_t pos = _bit_indices[i] + block_start - _remainder_bits;
+ add_shifted_inplace(block_size, &_partial_quotient[0], dividend + pos/bits, pos%bits);
+ }
+ add_shifted_inplace(block_size, &_partial_quotient[0], dividend + block_start/bits, block_start%bits);
+ dividend_bits = block_start;
+ }
+ }
+ std::vector<digit_t> _partial_quotient;
+ std::size_t _remainder_bits;
+ std::size_t _block_bits;
+ std::size_t _lower_bits;
+ std::vector<std::size_t> _bit_indices;
+ };
+
+ // base should have the same number of bits as mod
+ // base, and mod should both be able to hold a power
+ // of 2 >= mod_bits. out needs to be twice as large.
+ static void mod_pow_x(boost::uintmax_t exponent, const digit_t * mod, std::size_t mod_bits, digit_t * out)
+ {
+ const std::size_t bits = std::numeric_limits<digit_t>::digits;
+ const std::size_t n = (mod_bits + bits - 1) / bits;
+ const std::size_t highbit = mod_bits - 1;
+ if(exponent == 0) {
+ out[0] = 1;
+ std::fill_n(out + 1, n - 1, digit_t(0));
+ return;
+ }
+ boost::uintmax_t i = std::numeric_limits<boost::uintmax_t>::digits - 1;
+ while(((boost::uintmax_t(1) << i) & exponent) == 0) {
+ --i;
+ }
+ out[0] = 2;
+ std::fill_n(out + 1, n - 1, digit_t(0));
+ sparse_mod m(mod, mod_bits);
+ while(i--) {
+ sqr(out, n);
+ m(out, 2 * mod_bits - 1);
+ if((boost::uintmax_t(1) << i) & exponent) {
+ shift_left(out, n, 1);
+ if(out[highbit / bits] & (digit_t(1) << highbit%bits))
+ add(n, out, mod, out);
+ }
+ }
+ }
+};
+
+class polynomial
+{
+ typedef polynomial_ops::digit_t digit_t;
+public:
+ polynomial() : _size(0) {}
+ class reference {
+ public:
+ reference(digit_t &value, int idx)
+ : _value(value), _idx(idx) {}
+ operator bool() const { return (_value & (digit_t(1) << _idx)) != 0; }
+ reference& operator=(bool b)
+ {
+ if(b) {
+ _value |= (digit_t(1) << _idx);
+ } else {
+ _value &= ~(digit_t(1) << _idx);
+ }
+ return *this;
+ }
+ reference &operator^=(bool b)
+ {
+ _value ^= (digit_t(b) << _idx);
+ return *this;
+ }
+
+ reference &operator=(const reference &other)
+ {
+ return *this = static_cast<bool>(other);
+ }
+ private:
+ digit_t &_value;
+ int _idx;
+ };
+ reference operator[](std::size_t i)
+ {
+ static const std::size_t bits = std::numeric_limits<digit_t>::digits;
+ ensure_bit(i);
+ return reference(_storage[i/bits], i%bits);
+ }
+ bool operator[](std::size_t i) const
+ {
+ static const std::size_t bits = std::numeric_limits<digit_t>::digits;
+ if(i < size())
+ return (_storage[i/bits] & (digit_t(1) << (i%bits))) != 0;
+ else
+ return false;
+ }
+ std::size_t size() const
+ {
+ return _size;
+ }
+ void resize(std::size_t n)
+ {
+ static const std::size_t bits = std::numeric_limits<digit_t>::digits;
+ _storage.resize((n + bits - 1)/bits);
+ // clear the high order bits in case we're shrinking.
+ if(n%bits) {
+ _storage.back() &= ((digit_t(1) << (n%bits)) - 1);
+ }
+ _size = n;
+ }
+ friend polynomial operator*(const polynomial &lhs, const polynomial &rhs);
+ friend polynomial mod_pow_x(boost::uintmax_t exponent, polynomial mod);
+private:
+ std::vector<polynomial_ops::digit_t> _storage;
+ std::size_t _size;
+ void ensure_bit(std::size_t i)
+ {
+ if(i >= size()) {
+ resize(i + 1);
+ }
+ }
+ void normalize()
+ {
+ while(size() && (*this)[size() - 1] == 0)
+ resize(size() - 1);
+ }
+};
+
+inline polynomial operator*(const polynomial &lhs, const polynomial &rhs)
+{
+ polynomial result;
+ result._storage.resize(lhs._storage.size() + rhs._storage.size());
+ polynomial_ops::multiply(&lhs._storage[0], lhs._storage.size(),
+ &rhs._storage[0], rhs._storage.size(),
+ &result._storage[0]);
+ result._size = lhs._size + rhs._size;
+ return result;
+}
+
+inline polynomial mod_pow_x(boost::uintmax_t exponent, polynomial mod)
+{
+ polynomial result;
+ mod.normalize();
+ std::size_t mod_size = mod.size();
+ result._storage.resize(mod._storage.size() * 2);
+ result._size = mod.size() * 2;
+ polynomial_ops::mod_pow_x(exponent, &mod._storage[0], mod_size, &result._storage[0]);
+ result.resize(mod.size() - 1);
+ return result;
+}
+
+}
+}
+}
+
+#endif // BOOST_RANDOM_DETAIL_POLYNOMIAL_HPP
diff --git a/contrib/src/boost/random/detail/ptr_helper.hpp b/contrib/src/boost/random/detail/ptr_helper.hpp
index f1b983d..0a3cb22 100644
--- a/contrib/src/boost/random/detail/ptr_helper.hpp
+++ b/contrib/src/boost/random/detail/ptr_helper.hpp
@@ -1,67 +1,67 @@
-/* boost random/detail/ptr_helper.hpp header file
- *
- * Copyright Jens Maurer 2002
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- */
-
-#ifndef BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
-#define BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
-
-#include <boost/config.hpp>
-
-
-namespace boost {
-namespace random {
-namespace detail {
-
-// type_traits could help here, but I don't want to depend on type_traits.
-template<class T>
-struct ptr_helper
-{
- typedef T value_type;
- typedef T& reference_type;
- typedef const T& rvalue_type;
- static reference_type ref(T& r) { return r; }
- static const T& ref(const T& r) { return r; }
-};
-
-template<class T>
-struct ptr_helper<T&>
-{
- typedef T value_type;
- typedef T& reference_type;
- typedef T& rvalue_type;
- static reference_type ref(T& r) { return r; }
- static const T& ref(const T& r) { return r; }
-};
-
-template<class T>
-struct ptr_helper<T*>
-{
- typedef T value_type;
- typedef T& reference_type;
- typedef T* rvalue_type;
- static reference_type ref(T * p) { return *p; }
- static const T& ref(const T * p) { return *p; }
-};
-
-} // namespace detail
-} // namespace random
-} // namespace boost
-
-//
-// BOOST_RANDOM_PTR_HELPER_SPEC --
-//
-// Helper macro for broken compilers defines specializations of
-// ptr_helper.
-//
-# define BOOST_RANDOM_PTR_HELPER_SPEC(T)
-
-#endif // BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
+/* boost random/detail/ptr_helper.hpp header file
+ *
+ * Copyright Jens Maurer 2002
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
+#define BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
+
+#include <boost/config.hpp>
+
+
+namespace boost {
+namespace random {
+namespace detail {
+
+// type_traits could help here, but I don't want to depend on type_traits.
+template<class T>
+struct ptr_helper
+{
+ typedef T value_type;
+ typedef T& reference_type;
+ typedef const T& rvalue_type;
+ static reference_type ref(T& r) { return r; }
+ static const T& ref(const T& r) { return r; }
+};
+
+template<class T>
+struct ptr_helper<T&>
+{
+ typedef T value_type;
+ typedef T& reference_type;
+ typedef T& rvalue_type;
+ static reference_type ref(T& r) { return r; }
+ static const T& ref(const T& r) { return r; }
+};
+
+template<class T>
+struct ptr_helper<T*>
+{
+ typedef T value_type;
+ typedef T& reference_type;
+ typedef T* rvalue_type;
+ static reference_type ref(T * p) { return *p; }
+ static const T& ref(const T * p) { return *p; }
+};
+
+} // namespace detail
+} // namespace random
+} // namespace boost
+
+//
+// BOOST_RANDOM_PTR_HELPER_SPEC --
+//
+// Helper macro for broken compilers defines specializations of
+// ptr_helper.
+//
+# define BOOST_RANDOM_PTR_HELPER_SPEC(T)
+
+#endif // BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
diff --git a/contrib/src/boost/random/detail/seed.hpp b/contrib/src/boost/random/detail/seed.hpp
index 557482a..1c01f92 100644
--- a/contrib/src/boost/random/detail/seed.hpp
+++ b/contrib/src/boost/random/detail/seed.hpp
@@ -1,115 +1,115 @@
-/* boost random/detail/seed.hpp header file
- *
- * Copyright Steven Watanabe 2009
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- */
-
-#ifndef BOOST_RANDOM_DETAIL_SEED_HPP
-#define BOOST_RANDOM_DETAIL_SEED_HPP
-
-#include <boost/config.hpp>
-
-// Sun seems to have trouble with the use of SFINAE for the
-// templated constructor. So does Borland.
-#if !defined(BOOST_NO_SFINAE) && !defined(__SUNPRO_CC) && !defined(__BORLANDC__)
-
-#include <boost/utility/enable_if.hpp>
-#include <boost/type_traits/is_arithmetic.hpp>
-#include <boost/mpl/bool.hpp>
-
-namespace boost {
-namespace random {
-namespace detail {
-
-template<class T>
-struct disable_seed : boost::disable_if<boost::is_arithmetic<T> > {};
-
-template<class Engine, class T>
-struct disable_constructor : disable_seed<T> {};
-
-template<class Engine>
-struct disable_constructor<Engine, Engine> {};
-
-#define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
- template<class Generator> \
- explicit Self(Generator& gen, typename ::boost::random::detail::disable_constructor<Self, Generator>::type* = 0)
-
-#define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
- template<class Generator> \
- void seed(Generator& gen, typename ::boost::random::detail::disable_seed<Generator>::type* = 0)
-
-#define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
- template<class SeedSeq> \
- explicit Self(SeedSeq& seq, typename ::boost::random::detail::disable_constructor<Self, SeedSeq>::type* = 0)
-
-#define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
- template<class SeedSeq> \
- void seed(SeedSeq& seq, typename ::boost::random::detail::disable_seed<SeedSeq>::type* = 0)
-
-#define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
- explicit Self(const T& x)
-
-#define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
- void seed(const T& x)
-}
-}
-}
-
-#else
-
-#include <boost/type_traits/is_arithmetic.hpp>
-#include <boost/mpl/bool.hpp>
-
-#define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
- Self(Self& other) { *this = other; } \
- Self(const Self& other) { *this = other; } \
- template<class Generator> \
- explicit Self(Generator& gen) { \
- boost_random_constructor_impl(gen, ::boost::is_arithmetic<Generator>());\
- } \
- template<class Generator> \
- void boost_random_constructor_impl(Generator& gen, ::boost::mpl::false_)
-
-#define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
- template<class Generator> \
- void seed(Generator& gen) { \
- boost_random_seed_impl(gen, ::boost::is_arithmetic<Generator>());\
- }\
- template<class Generator>\
- void boost_random_seed_impl(Generator& gen, ::boost::mpl::false_)
-
-#define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
- Self(Self& other) { *this = other; } \
- Self(const Self& other) { *this = other; } \
- template<class SeedSeq> \
- explicit Self(SeedSeq& seq) { \
- boost_random_constructor_impl(seq, ::boost::is_arithmetic<SeedSeq>());\
- } \
- template<class SeedSeq> \
- void boost_random_constructor_impl(SeedSeq& seq, ::boost::mpl::false_)
-
-#define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
- template<class SeedSeq> \
- void seed(SeedSeq& seq) { \
- boost_random_seed_impl(seq, ::boost::is_arithmetic<SeedSeq>()); \
- } \
- template<class SeedSeq> \
- void boost_random_seed_impl(SeedSeq& seq, ::boost::mpl::false_)
-
-#define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
- explicit Self(const T& x) { boost_random_constructor_impl(x, ::boost::mpl::true_()); }\
- void boost_random_constructor_impl(const T& x, ::boost::mpl::true_)
-
-#define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
- void seed(const T& x) { boost_random_seed_impl(x, ::boost::mpl::true_()); }\
- void boost_random_seed_impl(const T& x, ::boost::mpl::true_)
-
-#endif
-
-#endif
+/* boost random/detail/seed.hpp header file
+ *
+ * Copyright Steven Watanabe 2009
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_SEED_HPP
+#define BOOST_RANDOM_DETAIL_SEED_HPP
+
+#include <boost/config.hpp>
+
+// Sun seems to have trouble with the use of SFINAE for the
+// templated constructor. So does Borland.
+#if !defined(BOOST_NO_SFINAE) && !defined(__SUNPRO_CC) && !defined(__BORLANDC__)
+
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_arithmetic.hpp>
+#include <boost/mpl/bool.hpp>
+
+namespace boost {
+namespace random {
+namespace detail {
+
+template<class T>
+struct disable_seed : boost::disable_if<boost::is_arithmetic<T> > {};
+
+template<class Engine, class T>
+struct disable_constructor : disable_seed<T> {};
+
+template<class Engine>
+struct disable_constructor<Engine, Engine> {};
+
+#define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
+ template<class Generator> \
+ explicit Self(Generator& gen, typename ::boost::random::detail::disable_constructor<Self, Generator>::type* = 0)
+
+#define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
+ template<class Generator> \
+ void seed(Generator& gen, typename ::boost::random::detail::disable_seed<Generator>::type* = 0)
+
+#define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
+ template<class SeedSeq> \
+ explicit Self(SeedSeq& seq, typename ::boost::random::detail::disable_constructor<Self, SeedSeq>::type* = 0)
+
+#define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
+ template<class SeedSeq> \
+ void seed(SeedSeq& seq, typename ::boost::random::detail::disable_seed<SeedSeq>::type* = 0)
+
+#define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
+ explicit Self(const T& x)
+
+#define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
+ void seed(const T& x)
+}
+}
+}
+
+#else
+
+#include <boost/type_traits/is_arithmetic.hpp>
+#include <boost/mpl/bool.hpp>
+
+#define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
+ Self(Self& other) { *this = other; } \
+ Self(const Self& other) { *this = other; } \
+ template<class Generator> \
+ explicit Self(Generator& gen) { \
+ boost_random_constructor_impl(gen, ::boost::is_arithmetic<Generator>());\
+ } \
+ template<class Generator> \
+ void boost_random_constructor_impl(Generator& gen, ::boost::mpl::false_)
+
+#define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
+ template<class Generator> \
+ void seed(Generator& gen) { \
+ boost_random_seed_impl(gen, ::boost::is_arithmetic<Generator>());\
+ }\
+ template<class Generator>\
+ void boost_random_seed_impl(Generator& gen, ::boost::mpl::false_)
+
+#define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
+ Self(Self& other) { *this = other; } \
+ Self(const Self& other) { *this = other; } \
+ template<class SeedSeq> \
+ explicit Self(SeedSeq& seq) { \
+ boost_random_constructor_impl(seq, ::boost::is_arithmetic<SeedSeq>());\
+ } \
+ template<class SeedSeq> \
+ void boost_random_constructor_impl(SeedSeq& seq, ::boost::mpl::false_)
+
+#define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
+ template<class SeedSeq> \
+ void seed(SeedSeq& seq) { \
+ boost_random_seed_impl(seq, ::boost::is_arithmetic<SeedSeq>()); \
+ } \
+ template<class SeedSeq> \
+ void boost_random_seed_impl(SeedSeq& seq, ::boost::mpl::false_)
+
+#define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
+ explicit Self(const T& x) { boost_random_constructor_impl(x, ::boost::mpl::true_()); }\
+ void boost_random_constructor_impl(const T& x, ::boost::mpl::true_)
+
+#define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
+ void seed(const T& x) { boost_random_seed_impl(x, ::boost::mpl::true_()); }\
+ void boost_random_seed_impl(const T& x, ::boost::mpl::true_)
+
+#endif
+
+#endif
diff --git a/contrib/src/boost/random/detail/seed_impl.hpp b/contrib/src/boost/random/detail/seed_impl.hpp
index 918a294..f697cd7 100644
--- a/contrib/src/boost/random/detail/seed_impl.hpp
+++ b/contrib/src/boost/random/detail/seed_impl.hpp
@@ -1,398 +1,398 @@
-/* boost random/detail/seed.hpp header file
- *
- * Copyright Steven Watanabe 2009
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- */
-
-#ifndef BOOST_RANDOM_DETAIL_SEED_IMPL_HPP
-#define BOOST_RANDOM_DETAIL_SEED_IMPL_HPP
-
-#include <stdexcept>
-#include <boost/cstdint.hpp>
-#include <boost/throw_exception.hpp>
-#include <boost/config/no_tr1/cmath.hpp>
-#include <boost/integer/integer_mask.hpp>
-#include <boost/integer/static_log2.hpp>
-#include <boost/random/traits.hpp>
-#include <boost/mpl/bool.hpp>
-#include <boost/mpl/if.hpp>
-#include <boost/mpl/int.hpp>
-#include <boost/random/detail/const_mod.hpp>
-#include <boost/random/detail/integer_log2.hpp>
-#include <boost/random/detail/signed_unsigned_tools.hpp>
-#include <boost/random/detail/generator_bits.hpp>
-
-#include <boost/random/detail/disable_warnings.hpp>
-
-namespace boost {
-namespace random {
-namespace detail {
-
-// finds the seed type of an engine, given its
-// result_type. If the result_type is integral
-// the seed type is the same. If the result_type
-// is floating point, the seed type is uint32_t
-template<class T>
-struct seed_type
-{
- typedef typename boost::mpl::if_<boost::is_integral<T>,
- T,
- boost::uint32_t
- >::type type;
-};
-
-template<int N>
-struct const_pow_impl
-{
- template<class T>
- static T call(T arg, int n, T result)
- {
- return const_pow_impl<N / 2>::call(T(arg * arg), n / 2,
- n%2 == 0? result : T(result * arg));
- }
-};
-
-template<>
-struct const_pow_impl<0>
-{
- template<class T>
- static T call(T, int, T result)
- {
- return result;
- }
-};
-
-// requires N is an upper bound on n
-template<int N, class T>
-inline T const_pow(T arg, int n) { return const_pow_impl<N>::call(arg, n, T(1)); }
-
-template<class T>
-inline T pow2(int n)
-{
- typedef unsigned int_type;
- const int max_bits = std::numeric_limits<int_type>::digits;
- T multiplier = T(int_type(1) << (max_bits - 1)) * 2;
- return (int_type(1) << (n % max_bits)) *
- const_pow<std::numeric_limits<T>::digits / max_bits>(multiplier, n / max_bits);
-}
-
-template<class Engine, class Iter>
-void generate_from_real(Engine& eng, Iter begin, Iter end)
-{
- using std::fmod;
- typedef typename Engine::result_type RealType;
- const int Bits = detail::generator_bits<Engine>::value();
- int remaining_bits = 0;
- boost::uint_least32_t saved_bits = 0;
- RealType multiplier = pow2<RealType>( Bits);
- RealType mult32 = RealType(4294967296.0); // 2^32
- while(true) {
- RealType val = eng() * multiplier;
- int available_bits = Bits;
- // Make sure the compiler can optimize this out
- // if it isn't possible.
- if(Bits < 32 && available_bits < 32 - remaining_bits) {
- saved_bits |= boost::uint_least32_t(val) << remaining_bits;
- remaining_bits += Bits;
- } else {
- // If Bits < 32, then remaining_bits != 0, since
- // if remaining_bits == 0, available_bits < 32 - 0,
- // and we won't get here to begin with.
- if(Bits < 32 || remaining_bits != 0) {
- boost::uint_least32_t divisor =
- (boost::uint_least32_t(1) << (32 - remaining_bits));
- boost::uint_least32_t extra_bits = boost::uint_least32_t(fmod(val, mult32)) & (divisor - 1);
- val = val / divisor;
- *begin++ = saved_bits | (extra_bits << remaining_bits);
- if(begin == end) return;
- available_bits -= 32 - remaining_bits;
- remaining_bits = 0;
- }
- // If Bits < 32 we should never enter this loop
- if(Bits >= 32) {
- for(; available_bits >= 32; available_bits -= 32) {
- boost::uint_least32_t word = boost::uint_least32_t(fmod(val, mult32));
- val /= mult32;
- *begin++ = word;
- if(begin == end) return;
- }
- }
- remaining_bits = available_bits;
- saved_bits = static_cast<boost::uint_least32_t>(val);
- }
- }
-}
-
-template<class Engine, class Iter>
-void generate_from_int(Engine& eng, Iter begin, Iter end)
-{
- typedef typename Engine::result_type IntType;
- typedef typename boost::random::traits::make_unsigned<IntType>::type unsigned_type;
- int remaining_bits = 0;
- boost::uint_least32_t saved_bits = 0;
- unsigned_type range = boost::random::detail::subtract<IntType>()((eng.max)(), (eng.min)());
-
- int bits =
- (range == (std::numeric_limits<unsigned_type>::max)()) ?
- std::numeric_limits<unsigned_type>::digits :
- detail::integer_log2(range + 1);
-
- {
- int discarded_bits = detail::integer_log2(bits);
- unsigned_type excess = (range + 1) >> (bits - discarded_bits);
- if(excess != 0) {
- int extra_bits = detail::integer_log2((excess - 1) ^ excess);
- bits = bits - discarded_bits + extra_bits;
- }
- }
-
- unsigned_type mask = (static_cast<unsigned_type>(2) << (bits - 1)) - 1;
- unsigned_type limit = ((range + 1) & ~mask) - 1;
-
- while(true) {
- unsigned_type val;
- do {
- val = boost::random::detail::subtract<IntType>()(eng(), (eng.min)());
- } while(limit != range && val > limit);
- val &= mask;
- int available_bits = bits;
- if(available_bits == 32) {
- *begin++ = static_cast<boost::uint_least32_t>(val) & 0xFFFFFFFFu;
- if(begin == end) return;
- } else if(available_bits % 32 == 0) {
- for(int i = 0; i < available_bits / 32; ++i) {
- boost::uint_least32_t word = boost::uint_least32_t(val) & 0xFFFFFFFFu;
- int suppress_warning = (bits >= 32);
- BOOST_ASSERT(suppress_warning == 1);
- val >>= (32 * suppress_warning);
- *begin++ = word;
- if(begin == end) return;
- }
- } else if(bits < 32 && available_bits < 32 - remaining_bits) {
- saved_bits |= boost::uint_least32_t(val) << remaining_bits;
- remaining_bits += bits;
- } else {
- if(bits < 32 || remaining_bits != 0) {
- boost::uint_least32_t extra_bits = boost::uint_least32_t(val) & ((boost::uint_least32_t(1) << (32 - remaining_bits)) - 1);
- val >>= 32 - remaining_bits;
- *begin++ = saved_bits | (extra_bits << remaining_bits);
- if(begin == end) return;
- available_bits -= 32 - remaining_bits;
- remaining_bits = 0;
- }
- if(bits >= 32) {
- for(; available_bits >= 32; available_bits -= 32) {
- boost::uint_least32_t word = boost::uint_least32_t(val) & 0xFFFFFFFFu;
- int suppress_warning = (bits >= 32);
- BOOST_ASSERT(suppress_warning == 1);
- val >>= (32 * suppress_warning);
- *begin++ = word;
- if(begin == end) return;
- }
- }
- remaining_bits = available_bits;
- saved_bits = static_cast<boost::uint_least32_t>(val);
- }
- }
-}
-
-template<class Engine, class Iter>
-void generate_impl(Engine& eng, Iter first, Iter last, boost::mpl::true_)
-{
- return detail::generate_from_int(eng, first, last);
-}
-
-template<class Engine, class Iter>
-void generate_impl(Engine& eng, Iter first, Iter last, boost::mpl::false_)
-{
- return detail::generate_from_real(eng, first, last);
-}
-
-template<class Engine, class Iter>
-void generate(Engine& eng, Iter first, Iter last)
-{
- return detail::generate_impl(eng, first, last, boost::random::traits::is_integral<typename Engine::result_type>());
-}
-
-
-
-template<class IntType, IntType m, class SeedSeq>
-IntType seed_one_int(SeedSeq& seq)
-{
- static const int log = ::boost::mpl::if_c<(m == 0),
- ::boost::mpl::int_<(::std::numeric_limits<IntType>::digits)>,
- ::boost::static_log2<m> >::type::value;
- static const int k =
- (log + ((~(static_cast<IntType>(2) << (log - 1)) & m)? 32 : 31)) / 32;
- ::boost::uint_least32_t array[log / 32 + 4];
- seq.generate(&array[0], &array[0] + k + 3);
- IntType s = 0;
- for(int j = 0; j < k; ++j) {
- IntType digit = const_mod<IntType, m>::apply(IntType(array[j+3]));
- IntType mult = IntType(1) << 32*j;
- s = const_mod<IntType, m>::mult_add(mult, digit, s);
- }
- return s;
-}
-
-template<class IntType, IntType m, class Iter>
-IntType get_one_int(Iter& first, Iter last)
-{
- static const int log = ::boost::mpl::if_c<(m == 0),
- ::boost::mpl::int_<(::std::numeric_limits<IntType>::digits)>,
- ::boost::static_log2<m> >::type::value;
- static const int k =
- (log + ((~(static_cast<IntType>(2) << (log - 1)) & m)? 32 : 31)) / 32;
- IntType s = 0;
- for(int j = 0; j < k; ++j) {
- if(first == last) {
- boost::throw_exception(::std::invalid_argument("Not enough elements in call to seed."));
- }
- IntType digit = const_mod<IntType, m>::apply(IntType(*first++));
- IntType mult = IntType(1) << 32*j;
- s = const_mod<IntType, m>::mult_add(mult, digit, s);
- }
- return s;
-}
-
-// TODO: work in-place whenever possible
-template<int w, std::size_t n, class SeedSeq, class UIntType>
-void seed_array_int_impl(SeedSeq& seq, UIntType (&x)[n])
-{
- boost::uint_least32_t storage[((w+31)/32) * n];
- seq.generate(&storage[0], &storage[0] + ((w+31)/32) * n);
- for(std::size_t j = 0; j < n; j++) {
- UIntType val = 0;
- for(std::size_t k = 0; k < (w+31)/32; ++k) {
- val += static_cast<UIntType>(storage[(w+31)/32*j + k]) << 32*k;
- }
- x[j] = val & ::boost::low_bits_mask_t<w>::sig_bits;
- }
-}
-
-template<int w, std::size_t n, class SeedSeq, class IntType>
-inline void seed_array_int_impl(SeedSeq& seq, IntType (&x)[n], boost::mpl::true_)
-{
- BOOST_STATIC_ASSERT_MSG(boost::is_integral<IntType>::value, "Sorry but this routine has not been ported to non built-in integers as it relies on a reinterpret_cast.");
- typedef typename boost::make_unsigned<IntType>::type unsigned_array[n];
- seed_array_int_impl<w>(seq, reinterpret_cast<unsigned_array&>(x));
-}
-
-template<int w, std::size_t n, class SeedSeq, class IntType>
-inline void seed_array_int_impl(SeedSeq& seq, IntType (&x)[n], boost::mpl::false_)
-{
- seed_array_int_impl<w>(seq, x);
-}
-
-template<int w, std::size_t n, class SeedSeq, class IntType>
-inline void seed_array_int(SeedSeq& seq, IntType (&x)[n])
-{
- seed_array_int_impl<w>(seq, x, boost::random::traits::is_signed<IntType>());
-}
-
-template<int w, std::size_t n, class Iter, class UIntType>
-void fill_array_int_impl(Iter& first, Iter last, UIntType (&x)[n])
-{
- for(std::size_t j = 0; j < n; j++) {
- UIntType val = 0;
- for(std::size_t k = 0; k < (w+31)/32; ++k) {
- if(first == last) {
- boost::throw_exception(std::invalid_argument("Not enough elements in call to seed."));
- }
- val += static_cast<UIntType>(*first++) << 32*k;
- }
- x[j] = val & ::boost::low_bits_mask_t<w>::sig_bits;
- }
-}
-
-template<int w, std::size_t n, class Iter, class IntType>
-inline void fill_array_int_impl(Iter& first, Iter last, IntType (&x)[n], boost::mpl::true_)
-{
- BOOST_STATIC_ASSERT_MSG(boost::is_integral<IntType>::value, "Sorry but this routine has not been ported to non built-in integers as it relies on a reinterpret_cast.");
- typedef typename boost::make_unsigned<IntType>::type unsigned_array[n];
- fill_array_int_impl<w>(first, last, reinterpret_cast<unsigned_array&>(x));
-}
-
-template<int w, std::size_t n, class Iter, class IntType>
-inline void fill_array_int_impl(Iter& first, Iter last, IntType (&x)[n], boost::mpl::false_)
-{
- fill_array_int_impl<w>(first, last, x);
-}
-
-template<int w, std::size_t n, class Iter, class IntType>
-inline void fill_array_int(Iter& first, Iter last, IntType (&x)[n])
-{
- fill_array_int_impl<w>(first, last, x, boost::random::traits::is_signed<IntType>());
-}
-
-template<int w, std::size_t n, class RealType>
-void seed_array_real_impl(const boost::uint_least32_t* storage, RealType (&x)[n])
-{
- boost::uint_least32_t mask = ~((~boost::uint_least32_t(0)) << (w%32));
- RealType two32 = 4294967296.0;
- const RealType divisor = RealType(1)/detail::pow2<RealType>(w);
- unsigned int j;
- for(j = 0; j < n; ++j) {
- RealType val = RealType(0);
- RealType mult = divisor;
- for(int k = 0; k < w/32; ++k) {
- val += *storage++ * mult;
- mult *= two32;
- }
- if(mask != 0) {
- val += (*storage++ & mask) * mult;
- }
- BOOST_ASSERT(val >= 0);
- BOOST_ASSERT(val < 1);
- x[j] = val;
- }
-}
-
-template<int w, std::size_t n, class SeedSeq, class RealType>
-void seed_array_real(SeedSeq& seq, RealType (&x)[n])
-{
- using std::pow;
- boost::uint_least32_t storage[((w+31)/32) * n];
- seq.generate(&storage[0], &storage[0] + ((w+31)/32) * n);
- seed_array_real_impl<w>(storage, x);
-}
-
-template<int w, std::size_t n, class Iter, class RealType>
-void fill_array_real(Iter& first, Iter last, RealType (&x)[n])
-{
- boost::uint_least32_t mask = ~((~boost::uint_least32_t(0)) << (w%32));
- RealType two32 = 4294967296.0;
- const RealType divisor = RealType(1)/detail::pow2<RealType>(w);
- unsigned int j;
- for(j = 0; j < n; ++j) {
- RealType val = RealType(0);
- RealType mult = divisor;
- for(int k = 0; k < w/32; ++k, ++first) {
- if(first == last) boost::throw_exception(std::invalid_argument("Not enough elements in call to seed."));
- val += *first * mult;
- mult *= two32;
- }
- if(mask != 0) {
- if(first == last) boost::throw_exception(std::invalid_argument("Not enough elements in call to seed."));
- val += (*first & mask) * mult;
- ++first;
- }
- BOOST_ASSERT(val >= 0);
- BOOST_ASSERT(val < 1);
- x[j] = val;
- }
-}
-
-}
-}
-}
-
-#include <boost/random/detail/enable_warnings.hpp>
-
-#endif
+/* boost random/detail/seed.hpp header file
+ *
+ * Copyright Steven Watanabe 2009
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_SEED_IMPL_HPP
+#define BOOST_RANDOM_DETAIL_SEED_IMPL_HPP
+
+#include <stdexcept>
+#include <boost/cstdint.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/config/no_tr1/cmath.hpp>
+#include <boost/integer/integer_mask.hpp>
+#include <boost/integer/static_log2.hpp>
+#include <boost/random/traits.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/int.hpp>
+#include <boost/random/detail/const_mod.hpp>
+#include <boost/random/detail/integer_log2.hpp>
+#include <boost/random/detail/signed_unsigned_tools.hpp>
+#include <boost/random/detail/generator_bits.hpp>
+
+#include <boost/random/detail/disable_warnings.hpp>
+
+namespace boost {
+namespace random {
+namespace detail {
+
+// finds the seed type of an engine, given its
+// result_type. If the result_type is integral
+// the seed type is the same. If the result_type
+// is floating point, the seed type is uint32_t
+template<class T>
+struct seed_type
+{
+ typedef typename boost::mpl::if_<boost::is_integral<T>,
+ T,
+ boost::uint32_t
+ >::type type;
+};
+
+template<int N>
+struct const_pow_impl
+{
+ template<class T>
+ static T call(T arg, int n, T result)
+ {
+ return const_pow_impl<N / 2>::call(T(arg * arg), n / 2,
+ n%2 == 0? result : T(result * arg));
+ }
+};
+
+template<>
+struct const_pow_impl<0>
+{
+ template<class T>
+ static T call(T, int, T result)
+ {
+ return result;
+ }
+};
+
+// requires N is an upper bound on n
+template<int N, class T>
+inline T const_pow(T arg, int n) { return const_pow_impl<N>::call(arg, n, T(1)); }
+
+template<class T>
+inline T pow2(int n)
+{
+ typedef unsigned int_type;
+ const int max_bits = std::numeric_limits<int_type>::digits;
+ T multiplier = T(int_type(1) << (max_bits - 1)) * 2;
+ return (int_type(1) << (n % max_bits)) *
+ const_pow<std::numeric_limits<T>::digits / max_bits>(multiplier, n / max_bits);
+}
+
+template<class Engine, class Iter>
+void generate_from_real(Engine& eng, Iter begin, Iter end)
+{
+ using std::fmod;
+ typedef typename Engine::result_type RealType;
+ const int Bits = detail::generator_bits<Engine>::value();
+ int remaining_bits = 0;
+ boost::uint_least32_t saved_bits = 0;
+ RealType multiplier = pow2<RealType>( Bits);
+ RealType mult32 = RealType(4294967296.0); // 2^32
+ while(true) {
+ RealType val = eng() * multiplier;
+ int available_bits = Bits;
+ // Make sure the compiler can optimize this out
+ // if it isn't possible.
+ if(Bits < 32 && available_bits < 32 - remaining_bits) {
+ saved_bits |= boost::uint_least32_t(val) << remaining_bits;
+ remaining_bits += Bits;
+ } else {
+ // If Bits < 32, then remaining_bits != 0, since
+ // if remaining_bits == 0, available_bits < 32 - 0,
+ // and we won't get here to begin with.
+ if(Bits < 32 || remaining_bits != 0) {
+ boost::uint_least32_t divisor =
+ (boost::uint_least32_t(1) << (32 - remaining_bits));
+ boost::uint_least32_t extra_bits = boost::uint_least32_t(fmod(val, mult32)) & (divisor - 1);
+ val = val / divisor;
+ *begin++ = saved_bits | (extra_bits << remaining_bits);
+ if(begin == end) return;
+ available_bits -= 32 - remaining_bits;
+ remaining_bits = 0;
+ }
+ // If Bits < 32 we should never enter this loop
+ if(Bits >= 32) {
+ for(; available_bits >= 32; available_bits -= 32) {
+ boost::uint_least32_t word = boost::uint_least32_t(fmod(val, mult32));
+ val /= mult32;
+ *begin++ = word;
+ if(begin == end) return;
+ }
+ }
+ remaining_bits = available_bits;
+ saved_bits = static_cast<boost::uint_least32_t>(val);
+ }
+ }
+}
+
+template<class Engine, class Iter>
+void generate_from_int(Engine& eng, Iter begin, Iter end)
+{
+ typedef typename Engine::result_type IntType;
+ typedef typename boost::random::traits::make_unsigned<IntType>::type unsigned_type;
+ int remaining_bits = 0;
+ boost::uint_least32_t saved_bits = 0;
+ unsigned_type range = boost::random::detail::subtract<IntType>()((eng.max)(), (eng.min)());
+
+ int bits =
+ (range == (std::numeric_limits<unsigned_type>::max)()) ?
+ std::numeric_limits<unsigned_type>::digits :
+ detail::integer_log2(range + 1);
+
+ {
+ int discarded_bits = detail::integer_log2(bits);
+ unsigned_type excess = (range + 1) >> (bits - discarded_bits);
+ if(excess != 0) {
+ int extra_bits = detail::integer_log2((excess - 1) ^ excess);
+ bits = bits - discarded_bits + extra_bits;
+ }
+ }
+
+ unsigned_type mask = (static_cast<unsigned_type>(2) << (bits - 1)) - 1;
+ unsigned_type limit = ((range + 1) & ~mask) - 1;
+
+ while(true) {
+ unsigned_type val;
+ do {
+ val = boost::random::detail::subtract<IntType>()(eng(), (eng.min)());
+ } while(limit != range && val > limit);
+ val &= mask;
+ int available_bits = bits;
+ if(available_bits == 32) {
+ *begin++ = static_cast<boost::uint_least32_t>(val) & 0xFFFFFFFFu;
+ if(begin == end) return;
+ } else if(available_bits % 32 == 0) {
+ for(int i = 0; i < available_bits / 32; ++i) {
+ boost::uint_least32_t word = boost::uint_least32_t(val) & 0xFFFFFFFFu;
+ int suppress_warning = (bits >= 32);
+ BOOST_ASSERT(suppress_warning == 1);
+ val >>= (32 * suppress_warning);
+ *begin++ = word;
+ if(begin == end) return;
+ }
+ } else if(bits < 32 && available_bits < 32 - remaining_bits) {
+ saved_bits |= boost::uint_least32_t(val) << remaining_bits;
+ remaining_bits += bits;
+ } else {
+ if(bits < 32 || remaining_bits != 0) {
+ boost::uint_least32_t extra_bits = boost::uint_least32_t(val) & ((boost::uint_least32_t(1) << (32 - remaining_bits)) - 1);
+ val >>= 32 - remaining_bits;
+ *begin++ = saved_bits | (extra_bits << remaining_bits);
+ if(begin == end) return;
+ available_bits -= 32 - remaining_bits;
+ remaining_bits = 0;
+ }
+ if(bits >= 32) {
+ for(; available_bits >= 32; available_bits -= 32) {
+ boost::uint_least32_t word = boost::uint_least32_t(val) & 0xFFFFFFFFu;
+ int suppress_warning = (bits >= 32);
+ BOOST_ASSERT(suppress_warning == 1);
+ val >>= (32 * suppress_warning);
+ *begin++ = word;
+ if(begin == end) return;
+ }
+ }
+ remaining_bits = available_bits;
+ saved_bits = static_cast<boost::uint_least32_t>(val);
+ }
+ }
+}
+
+template<class Engine, class Iter>
+void generate_impl(Engine& eng, Iter first, Iter last, boost::mpl::true_)
+{
+ return detail::generate_from_int(eng, first, last);
+}
+
+template<class Engine, class Iter>
+void generate_impl(Engine& eng, Iter first, Iter last, boost::mpl::false_)
+{
+ return detail::generate_from_real(eng, first, last);
+}
+
+template<class Engine, class Iter>
+void generate(Engine& eng, Iter first, Iter last)
+{
+ return detail::generate_impl(eng, first, last, boost::random::traits::is_integral<typename Engine::result_type>());
+}
+
+
+
+template<class IntType, IntType m, class SeedSeq>
+IntType seed_one_int(SeedSeq& seq)
+{
+ static const int log = ::boost::mpl::if_c<(m == 0),
+ ::boost::mpl::int_<(::std::numeric_limits<IntType>::digits)>,
+ ::boost::static_log2<m> >::type::value;
+ static const int k =
+ (log + ((~(static_cast<IntType>(2) << (log - 1)) & m)? 32 : 31)) / 32;
+ ::boost::uint_least32_t array[log / 32 + 4];
+ seq.generate(&array[0], &array[0] + k + 3);
+ IntType s = 0;
+ for(int j = 0; j < k; ++j) {
+ IntType digit = const_mod<IntType, m>::apply(IntType(array[j+3]));
+ IntType mult = IntType(1) << 32*j;
+ s = const_mod<IntType, m>::mult_add(mult, digit, s);
+ }
+ return s;
+}
+
+template<class IntType, IntType m, class Iter>
+IntType get_one_int(Iter& first, Iter last)
+{
+ static const int log = ::boost::mpl::if_c<(m == 0),
+ ::boost::mpl::int_<(::std::numeric_limits<IntType>::digits)>,
+ ::boost::static_log2<m> >::type::value;
+ static const int k =
+ (log + ((~(static_cast<IntType>(2) << (log - 1)) & m)? 32 : 31)) / 32;
+ IntType s = 0;
+ for(int j = 0; j < k; ++j) {
+ if(first == last) {
+ boost::throw_exception(::std::invalid_argument("Not enough elements in call to seed."));
+ }
+ IntType digit = const_mod<IntType, m>::apply(IntType(*first++));
+ IntType mult = IntType(1) << 32*j;
+ s = const_mod<IntType, m>::mult_add(mult, digit, s);
+ }
+ return s;
+}
+
+// TODO: work in-place whenever possible
+template<int w, std::size_t n, class SeedSeq, class UIntType>
+void seed_array_int_impl(SeedSeq& seq, UIntType (&x)[n])
+{
+ boost::uint_least32_t storage[((w+31)/32) * n];
+ seq.generate(&storage[0], &storage[0] + ((w+31)/32) * n);
+ for(std::size_t j = 0; j < n; j++) {
+ UIntType val = 0;
+ for(std::size_t k = 0; k < (w+31)/32; ++k) {
+ val += static_cast<UIntType>(storage[(w+31)/32*j + k]) << 32*k;
+ }
+ x[j] = val & ::boost::low_bits_mask_t<w>::sig_bits;
+ }
+}
+
+template<int w, std::size_t n, class SeedSeq, class IntType>
+inline void seed_array_int_impl(SeedSeq& seq, IntType (&x)[n], boost::mpl::true_)
+{
+ BOOST_STATIC_ASSERT_MSG(boost::is_integral<IntType>::value, "Sorry but this routine has not been ported to non built-in integers as it relies on a reinterpret_cast.");
+ typedef typename boost::make_unsigned<IntType>::type unsigned_array[n];
+ seed_array_int_impl<w>(seq, reinterpret_cast<unsigned_array&>(x));
+}
+
+template<int w, std::size_t n, class SeedSeq, class IntType>
+inline void seed_array_int_impl(SeedSeq& seq, IntType (&x)[n], boost::mpl::false_)
+{
+ seed_array_int_impl<w>(seq, x);
+}
+
+template<int w, std::size_t n, class SeedSeq, class IntType>
+inline void seed_array_int(SeedSeq& seq, IntType (&x)[n])
+{
+ seed_array_int_impl<w>(seq, x, boost::random::traits::is_signed<IntType>());
+}
+
+template<int w, std::size_t n, class Iter, class UIntType>
+void fill_array_int_impl(Iter& first, Iter last, UIntType (&x)[n])
+{
+ for(std::size_t j = 0; j < n; j++) {
+ UIntType val = 0;
+ for(std::size_t k = 0; k < (w+31)/32; ++k) {
+ if(first == last) {
+ boost::throw_exception(std::invalid_argument("Not enough elements in call to seed."));
+ }
+ val += static_cast<UIntType>(*first++) << 32*k;
+ }
+ x[j] = val & ::boost::low_bits_mask_t<w>::sig_bits;
+ }
+}
+
+template<int w, std::size_t n, class Iter, class IntType>
+inline void fill_array_int_impl(Iter& first, Iter last, IntType (&x)[n], boost::mpl::true_)
+{
+ BOOST_STATIC_ASSERT_MSG(boost::is_integral<IntType>::value, "Sorry but this routine has not been ported to non built-in integers as it relies on a reinterpret_cast.");
+ typedef typename boost::make_unsigned<IntType>::type unsigned_array[n];
+ fill_array_int_impl<w>(first, last, reinterpret_cast<unsigned_array&>(x));
+}
+
+template<int w, std::size_t n, class Iter, class IntType>
+inline void fill_array_int_impl(Iter& first, Iter last, IntType (&x)[n], boost::mpl::false_)
+{
+ fill_array_int_impl<w>(first, last, x);
+}
+
+template<int w, std::size_t n, class Iter, class IntType>
+inline void fill_array_int(Iter& first, Iter last, IntType (&x)[n])
+{
+ fill_array_int_impl<w>(first, last, x, boost::random::traits::is_signed<IntType>());
+}
+
+template<int w, std::size_t n, class RealType>
+void seed_array_real_impl(const boost::uint_least32_t* storage, RealType (&x)[n])
+{
+ boost::uint_least32_t mask = ~((~boost::uint_least32_t(0)) << (w%32));
+ RealType two32 = 4294967296.0;
+ const RealType divisor = RealType(1)/detail::pow2<RealType>(w);
+ unsigned int j;
+ for(j = 0; j < n; ++j) {
+ RealType val = RealType(0);
+ RealType mult = divisor;
+ for(int k = 0; k < w/32; ++k) {
+ val += *storage++ * mult;
+ mult *= two32;
+ }
+ if(mask != 0) {
+ val += (*storage++ & mask) * mult;
+ }
+ BOOST_ASSERT(val >= 0);
+ BOOST_ASSERT(val < 1);
+ x[j] = val;
+ }
+}
+
+template<int w, std::size_t n, class SeedSeq, class RealType>
+void seed_array_real(SeedSeq& seq, RealType (&x)[n])
+{
+ using std::pow;
+ boost::uint_least32_t storage[((w+31)/32) * n];
+ seq.generate(&storage[0], &storage[0] + ((w+31)/32) * n);
+ seed_array_real_impl<w>(storage, x);
+}
+
+template<int w, std::size_t n, class Iter, class RealType>
+void fill_array_real(Iter& first, Iter last, RealType (&x)[n])
+{
+ boost::uint_least32_t mask = ~((~boost::uint_least32_t(0)) << (w%32));
+ RealType two32 = 4294967296.0;
+ const RealType divisor = RealType(1)/detail::pow2<RealType>(w);
+ unsigned int j;
+ for(j = 0; j < n; ++j) {
+ RealType val = RealType(0);
+ RealType mult = divisor;
+ for(int k = 0; k < w/32; ++k, ++first) {
+ if(first == last) boost::throw_exception(std::invalid_argument("Not enough elements in call to seed."));
+ val += *first * mult;
+ mult *= two32;
+ }
+ if(mask != 0) {
+ if(first == last) boost::throw_exception(std::invalid_argument("Not enough elements in call to seed."));
+ val += (*first & mask) * mult;
+ ++first;
+ }
+ BOOST_ASSERT(val >= 0);
+ BOOST_ASSERT(val < 1);
+ x[j] = val;
+ }
+}
+
+}
+}
+}
+
+#include <boost/random/detail/enable_warnings.hpp>
+
+#endif
diff --git a/contrib/src/boost/random/detail/signed_unsigned_tools.hpp b/contrib/src/boost/random/detail/signed_unsigned_tools.hpp
index 1979908..4b2f722 100644
--- a/contrib/src/boost/random/detail/signed_unsigned_tools.hpp
+++ b/contrib/src/boost/random/detail/signed_unsigned_tools.hpp
@@ -1,89 +1,89 @@
-/* boost random/detail/signed_unsigned_tools.hpp header file
- *
- * Copyright Jens Maurer 2006
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- */
-
-#ifndef BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
-#define BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
-
-#include <boost/limits.hpp>
-#include <boost/config.hpp>
-#include <boost/random/traits.hpp>
-
-namespace boost {
-namespace random {
-namespace detail {
-
-
-/*
- * Compute x - y, we know that x >= y, return an unsigned value.
- */
-
-template<class T, bool sgn = std::numeric_limits<T>::is_signed && std::numeric_limits<T>::is_bounded>
-struct subtract { };
-
-template<class T>
-struct subtract<T, /* signed */ false>
-{
- typedef T result_type;
- result_type operator()(T x, T y) { return x - y; }
-};
-
-template<class T>
-struct subtract<T, /* signed */ true>
-{
- typedef typename boost::random::traits::make_unsigned_or_unbounded<T>::type result_type;
- result_type operator()(T x, T y)
- {
- if (y >= 0) // because x >= y, it follows that x >= 0, too
- return result_type(x) - result_type(y);
- if (x >= 0) // y < 0
- // avoid the nasty two's complement case for y == min()
- return result_type(x) + result_type(-(y+1)) + 1;
- // both x and y are negative: no signed overflow
- return result_type(x - y);
- }
-};
-
-/*
- * Compute x + y, x is unsigned, result fits in type of "y".
- */
-
-template<class T1, class T2, bool sgn = (std::numeric_limits<T2>::is_signed && (std::numeric_limits<T1>::digits >= std::numeric_limits<T2>::digits))>
-struct add { };
-
-template<class T1, class T2>
-struct add<T1, T2, /* signed or else T2 has more digits than T1 so the cast always works - needed when T2 is a multiprecision type and T1 is a native integer */ false>
-{
- typedef T2 result_type;
- result_type operator()(T1 x, T2 y) { return T2(x) + y; }
-};
-
-template<class T1, class T2>
-struct add<T1, T2, /* signed */ true>
-{
- typedef T2 result_type;
- result_type operator()(T1 x, T2 y)
- {
- if (y >= 0)
- return T2(x) + y;
- // y < 0
- if (x > T1(-(y+1))) // result >= 0 after subtraction
- // avoid the nasty two's complement edge case for y == min()
- return T2(x - T1(-(y+1)) - 1);
- // abs(x) < abs(y), thus T2 able to represent x
- return T2(x) + y;
- }
-};
-
-} // namespace detail
-} // namespace random
-} // namespace boost
-
-#endif // BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
-
+/* boost random/detail/signed_unsigned_tools.hpp header file
+ *
+ * Copyright Jens Maurer 2006
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
+#define BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
+
+#include <boost/limits.hpp>
+#include <boost/config.hpp>
+#include <boost/random/traits.hpp>
+
+namespace boost {
+namespace random {
+namespace detail {
+
+
+/*
+ * Compute x - y, we know that x >= y, return an unsigned value.
+ */
+
+template<class T, bool sgn = std::numeric_limits<T>::is_signed && std::numeric_limits<T>::is_bounded>
+struct subtract { };
+
+template<class T>
+struct subtract<T, /* signed */ false>
+{
+ typedef T result_type;
+ result_type operator()(T x, T y) { return x - y; }
+};
+
+template<class T>
+struct subtract<T, /* signed */ true>
+{
+ typedef typename boost::random::traits::make_unsigned_or_unbounded<T>::type result_type;
+ result_type operator()(T x, T y)
+ {
+ if (y >= 0) // because x >= y, it follows that x >= 0, too
+ return result_type(x) - result_type(y);
+ if (x >= 0) // y < 0
+ // avoid the nasty two's complement case for y == min()
+ return result_type(x) + result_type(-(y+1)) + 1;
+ // both x and y are negative: no signed overflow
+ return result_type(x - y);
+ }
+};
+
+/*
+ * Compute x + y, x is unsigned, result fits in type of "y".
+ */
+
+template<class T1, class T2, bool sgn = (std::numeric_limits<T2>::is_signed && (std::numeric_limits<T1>::digits >= std::numeric_limits<T2>::digits))>
+struct add { };
+
+template<class T1, class T2>
+struct add<T1, T2, /* signed or else T2 has more digits than T1 so the cast always works - needed when T2 is a multiprecision type and T1 is a native integer */ false>
+{
+ typedef T2 result_type;
+ result_type operator()(T1 x, T2 y) { return T2(x) + y; }
+};
+
+template<class T1, class T2>
+struct add<T1, T2, /* signed */ true>
+{
+ typedef T2 result_type;
+ result_type operator()(T1 x, T2 y)
+ {
+ if (y >= 0)
+ return T2(x) + y;
+ // y < 0
+ if (x > T1(-(y+1))) // result >= 0 after subtraction
+ // avoid the nasty two's complement edge case for y == min()
+ return T2(x - T1(-(y+1)) - 1);
+ // abs(x) < abs(y), thus T2 able to represent x
+ return T2(x) + y;
+ }
+};
+
+} // namespace detail
+} // namespace random
+} // namespace boost
+
+#endif // BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
+
diff --git a/contrib/src/boost/random/detail/uniform_int_float.hpp b/contrib/src/boost/random/detail/uniform_int_float.hpp
index 393c455..893e471 100644
--- a/contrib/src/boost/random/detail/uniform_int_float.hpp
+++ b/contrib/src/boost/random/detail/uniform_int_float.hpp
@@ -1,76 +1,76 @@
-/* boost random/detail/uniform_int_float.hpp header file
- *
- * Copyright Jens Maurer 2000-2001
- * Copyright Steven Watanabe 2011
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- */
-
-#ifndef BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
-#define BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
-
-#include <boost/limits.hpp>
-#include <boost/config.hpp>
-#include <boost/integer.hpp>
-#include <boost/random/detail/config.hpp>
-#include <boost/random/detail/generator_bits.hpp>
-
-#include <boost/random/detail/disable_warnings.hpp>
-
-namespace boost {
-namespace random {
-namespace detail {
-
-template<class URNG>
-class uniform_int_float
-{
-public:
- typedef URNG base_type;
- typedef typename base_type::result_type base_result;
-
- typedef typename boost::uint_t<
- (std::numeric_limits<boost::uintmax_t>::digits <
- std::numeric_limits<base_result>::digits)?
- std::numeric_limits<boost::uintmax_t>::digits :
- std::numeric_limits<base_result>::digits
- >::fast result_type;
-
- uniform_int_float(base_type& rng)
- : _rng(rng) {}
-
- static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
- { return 0; }
- static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
- {
- std::size_t digits = std::numeric_limits<result_type>::digits;
- if(detail::generator_bits<URNG>::value() < digits) {
- digits = detail::generator_bits<URNG>::value();
- }
- return (result_type(2) << (digits - 1)) - 1;
- }
- base_type& base() { return _rng; }
- const base_type& base() const { return _rng; }
-
- result_type operator()()
- {
- base_result range = static_cast<base_result>((max)())+1;
- return static_cast<result_type>(_rng() * range);
- }
-
-private:
- base_type& _rng;
-};
-
-} // namespace detail
-} // namespace random
-} // namespace boost
-
-#include <boost/random/detail/enable_warnings.hpp>
-
-#endif // BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
+/* boost random/detail/uniform_int_float.hpp header file
+ *
+ * Copyright Jens Maurer 2000-2001
+ * Copyright Steven Watanabe 2011
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
+#define BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
+
+#include <boost/limits.hpp>
+#include <boost/config.hpp>
+#include <boost/integer.hpp>
+#include <boost/random/detail/config.hpp>
+#include <boost/random/detail/generator_bits.hpp>
+
+#include <boost/random/detail/disable_warnings.hpp>
+
+namespace boost {
+namespace random {
+namespace detail {
+
+template<class URNG>
+class uniform_int_float
+{
+public:
+ typedef URNG base_type;
+ typedef typename base_type::result_type base_result;
+
+ typedef typename boost::uint_t<
+ (std::numeric_limits<boost::uintmax_t>::digits <
+ std::numeric_limits<base_result>::digits)?
+ std::numeric_limits<boost::uintmax_t>::digits :
+ std::numeric_limits<base_result>::digits
+ >::fast result_type;
+
+ uniform_int_float(base_type& rng)
+ : _rng(rng) {}
+
+ static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ { return 0; }
+ static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ {
+ std::size_t digits = std::numeric_limits<result_type>::digits;
+ if(detail::generator_bits<URNG>::value() < digits) {
+ digits = detail::generator_bits<URNG>::value();
+ }
+ return (result_type(2) << (digits - 1)) - 1;
+ }
+ base_type& base() { return _rng; }
+ const base_type& base() const { return _rng; }
+
+ result_type operator()()
+ {
+ base_result range = static_cast<base_result>((max)())+1;
+ return static_cast<result_type>(_rng() * range);
+ }
+
+private:
+ base_type& _rng;
+};
+
+} // namespace detail
+} // namespace random
+} // namespace boost
+
+#include <boost/random/detail/enable_warnings.hpp>
+
+#endif // BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
diff --git a/contrib/src/boost/random/mersenne_twister.hpp b/contrib/src/boost/random/mersenne_twister.hpp
index ce73e68..c52060e 100644
--- a/contrib/src/boost/random/mersenne_twister.hpp
+++ b/contrib/src/boost/random/mersenne_twister.hpp
@@ -1,682 +1,682 @@
-/* boost random/mersenne_twister.hpp header file
- *
- * Copyright Jens Maurer 2000-2001
- * Copyright Steven Watanabe 2010
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- * Revision history
- * 2013-10-14 fixed some warnings with Wshadow (mgaunard)
- * 2001-02-18 moved to individual header files
- */
-
-#ifndef BOOST_RANDOM_MERSENNE_TWISTER_HPP
-#define BOOST_RANDOM_MERSENNE_TWISTER_HPP
-
-#include <iosfwd>
-#include <istream>
-#include <stdexcept>
-#include <boost/config.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/integer/integer_mask.hpp>
-#include <boost/random/detail/config.hpp>
-#include <boost/random/detail/ptr_helper.hpp>
-#include <boost/random/detail/seed.hpp>
-#include <boost/random/detail/seed_impl.hpp>
-#include <boost/random/detail/generator_seed_seq.hpp>
-#include <boost/random/detail/polynomial.hpp>
-
-#include <boost/random/detail/disable_warnings.hpp>
-
-namespace boost {
-namespace random {
-
-/**
- * Instantiations of class template mersenne_twister_engine model a
- * \pseudo_random_number_generator. It uses the algorithm described in
- *
- * @blockquote
- * "Mersenne Twister: A 623-dimensionally equidistributed uniform
- * pseudo-random number generator", Makoto Matsumoto and Takuji Nishimura,
- * ACM Transactions on Modeling and Computer Simulation: Special Issue on
- * Uniform Random Number Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
- * @endblockquote
- *
- * @xmlnote
- * The boost variant has been implemented from scratch and does not
- * derive from or use mt19937.c provided on the above WWW site. However, it
- * was verified that both produce identical output.
- * @endxmlnote
- *
- * The seeding from an integer was changed in April 2005 to address a
- * <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html">weakness</a>.
- *
- * The quality of the generator crucially depends on the choice of the
- * parameters. User code should employ one of the sensibly parameterized
- * generators such as \mt19937 instead.
- *
- * The generator requires considerable amounts of memory for the storage of
- * its state array. For example, \mt11213b requires about 1408 bytes and
- * \mt19937 requires about 2496 bytes.
- */
-template<class UIntType,
- std::size_t w, std::size_t n, std::size_t m, std::size_t r,
- UIntType a, std::size_t u, UIntType d, std::size_t s,
- UIntType b, std::size_t t,
- UIntType c, std::size_t l, UIntType f>
-class mersenne_twister_engine
-{
-public:
- typedef UIntType result_type;
- BOOST_STATIC_CONSTANT(std::size_t, word_size = w);
- BOOST_STATIC_CONSTANT(std::size_t, state_size = n);
- BOOST_STATIC_CONSTANT(std::size_t, shift_size = m);
- BOOST_STATIC_CONSTANT(std::size_t, mask_bits = r);
- BOOST_STATIC_CONSTANT(UIntType, xor_mask = a);
- BOOST_STATIC_CONSTANT(std::size_t, tempering_u = u);
- BOOST_STATIC_CONSTANT(UIntType, tempering_d = d);
- BOOST_STATIC_CONSTANT(std::size_t, tempering_s = s);
- BOOST_STATIC_CONSTANT(UIntType, tempering_b = b);
- BOOST_STATIC_CONSTANT(std::size_t, tempering_t = t);
- BOOST_STATIC_CONSTANT(UIntType, tempering_c = c);
- BOOST_STATIC_CONSTANT(std::size_t, tempering_l = l);
- BOOST_STATIC_CONSTANT(UIntType, initialization_multiplier = f);
- BOOST_STATIC_CONSTANT(UIntType, default_seed = 5489u);
-
- // backwards compatibility
- BOOST_STATIC_CONSTANT(UIntType, parameter_a = a);
- BOOST_STATIC_CONSTANT(std::size_t, output_u = u);
- BOOST_STATIC_CONSTANT(std::size_t, output_s = s);
- BOOST_STATIC_CONSTANT(UIntType, output_b = b);
- BOOST_STATIC_CONSTANT(std::size_t, output_t = t);
- BOOST_STATIC_CONSTANT(UIntType, output_c = c);
- BOOST_STATIC_CONSTANT(std::size_t, output_l = l);
-
- // old Boost.Random concept requirements
- BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
-
-
- /**
- * Constructs a @c mersenne_twister_engine and calls @c seed().
- */
- mersenne_twister_engine() { seed(); }
-
- /**
- * Constructs a @c mersenne_twister_engine and calls @c seed(value).
- */
- BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(mersenne_twister_engine,
- UIntType, value)
- { seed(value); }
- template<class It> mersenne_twister_engine(It& first, It last)
- { seed(first,last); }
-
- /**
- * Constructs a mersenne_twister_engine and calls @c seed(gen).
- *
- * @xmlnote
- * The copy constructor will always be preferred over
- * the templated constructor.
- * @endxmlnote
- */
- BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(mersenne_twister_engine,
- SeedSeq, seq)
- { seed(seq); }
-
- // compiler-generated copy ctor and assignment operator are fine
-
- /** Calls @c seed(default_seed). */
- void seed() { seed(default_seed); }
-
- /**
- * Sets the state x(0) to v mod 2w. Then, iteratively,
- * sets x(i) to
- * (i + f * (x(i-1) xor (x(i-1) rshift w-2))) mod 2<sup>w</sup>
- * for i = 1 .. n-1. x(n) is the first value to be returned by operator().
- */
- BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(mersenne_twister_engine, UIntType, value)
- {
- // New seeding algorithm from
- // http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html
- // In the previous versions, MSBs of the seed affected only MSBs of the
- // state x[].
- const UIntType mask = (max)();
- x[0] = value & mask;
- for (i = 1; i < n; i++) {
- // See Knuth "The Art of Computer Programming"
- // Vol. 2, 3rd ed., page 106
- x[i] = (f * (x[i-1] ^ (x[i-1] >> (w-2))) + i) & mask;
- }
-
- normalize_state();
- }
-
- /**
- * Seeds a mersenne_twister_engine using values produced by seq.generate().
- */
- BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(mersenne_twister_engine, SeeqSeq, seq)
- {
- detail::seed_array_int<w>(seq, x);
- i = n;
-
- normalize_state();
- }
-
- /** Sets the state of the generator using values from an iterator range. */
- template<class It>
- void seed(It& first, It last)
- {
- detail::fill_array_int<w>(first, last, x);
- i = n;
-
- normalize_state();
- }
-
- /** Returns the smallest value that the generator can produce. */
- static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
- { return 0; }
- /** Returns the largest value that the generator can produce. */
- static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
- { return boost::low_bits_mask_t<w>::sig_bits; }
-
- /** Produces the next value of the generator. */
- result_type operator()();
-
- /** Fills a range with random values */
- template<class Iter>
- void generate(Iter first, Iter last)
- { detail::generate_from_int(*this, first, last); }
-
- /**
- * Advances the state of the generator by @c z steps. Equivalent to
- *
- * @code
- * for(unsigned long long i = 0; i < z; ++i) {
- * gen();
- * }
- * @endcode
- */
- void discard(boost::uintmax_t z)
- {
-#ifndef BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD
-#define BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD 10000000
-#endif
- if(z > BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD) {
- discard_many(z);
- } else {
- for(boost::uintmax_t j = 0; j < z; ++j) {
- (*this)();
- }
- }
- }
-
-#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
- /** Writes a mersenne_twister_engine to a @c std::ostream */
- template<class CharT, class Traits>
- friend std::basic_ostream<CharT,Traits>&
- operator<<(std::basic_ostream<CharT,Traits>& os,
- const mersenne_twister_engine& mt)
- {
- mt.print(os);
- return os;
- }
-
- /** Reads a mersenne_twister_engine from a @c std::istream */
- template<class CharT, class Traits>
- friend std::basic_istream<CharT,Traits>&
- operator>>(std::basic_istream<CharT,Traits>& is,
- mersenne_twister_engine& mt)
- {
- for(std::size_t j = 0; j < mt.state_size; ++j)
- is >> mt.x[j] >> std::ws;
- // MSVC (up to 7.1) and Borland (up to 5.64) don't handle the template
- // value parameter "n" available from the class template scope, so use
- // the static constant with the same value
- mt.i = mt.state_size;
- return is;
- }
-#endif
-
- /**
- * Returns true if the two generators are in the same state,
- * and will thus produce identical sequences.
- */
- friend bool operator==(const mersenne_twister_engine& x_,
- const mersenne_twister_engine& y_)
- {
- if(x_.i < y_.i) return x_.equal_imp(y_);
- else return y_.equal_imp(x_);
- }
-
- /**
- * Returns true if the two generators are in different states.
- */
- friend bool operator!=(const mersenne_twister_engine& x_,
- const mersenne_twister_engine& y_)
- { return !(x_ == y_); }
-
-private:
- /// \cond show_private
-
- void twist();
-
- /**
- * Does the work of operator==. This is in a member function
- * for portability. Some compilers, such as msvc 7.1 and
- * Sun CC 5.10 can't access template parameters or static
- * members of the class from inline friend functions.
- *
- * requires i <= other.i
- */
- bool equal_imp(const mersenne_twister_engine& other) const
- {
- UIntType back[n];
- std::size_t offset = other.i - i;
- for(std::size_t j = 0; j + offset < n; ++j)
- if(x[j] != other.x[j+offset])
- return false;
- rewind(&back[n-1], offset);
- for(std::size_t j = 0; j < offset; ++j)
- if(back[j + n - offset] != other.x[j])
- return false;
- return true;
- }
-
- /**
- * Does the work of operator<<. This is in a member function
- * for portability.
- */
- template<class CharT, class Traits>
- void print(std::basic_ostream<CharT, Traits>& os) const
- {
- UIntType data[n];
- for(std::size_t j = 0; j < i; ++j) {
- data[j + n - i] = x[j];
- }
- if(i != n) {
- rewind(&data[n - i - 1], n - i);
- }
- os << data[0];
- for(std::size_t j = 1; j < n; ++j) {
- os << ' ' << data[j];
- }
- }
-
- /**
- * Copies z elements of the state preceding x[0] into
- * the array whose last element is last.
- */
- void rewind(UIntType* last, std::size_t z) const
- {
- const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
- const UIntType lower_mask = ~upper_mask;
- UIntType y0 = x[m-1] ^ x[n-1];
- if(y0 & (static_cast<UIntType>(1) << (w-1))) {
- y0 = ((y0 ^ a) << 1) | 1;
- } else {
- y0 = y0 << 1;
- }
- for(std::size_t sz = 0; sz < z; ++sz) {
- UIntType y1 =
- rewind_find(last, sz, m-1) ^ rewind_find(last, sz, n-1);
- if(y1 & (static_cast<UIntType>(1) << (w-1))) {
- y1 = ((y1 ^ a) << 1) | 1;
- } else {
- y1 = y1 << 1;
- }
- *(last - sz) = (y0 & upper_mask) | (y1 & lower_mask);
- y0 = y1;
- }
- }
-
- /**
- * Converts an arbitrary array into a valid generator state.
- * First we normalize x[0], so that it contains the same
- * value we would get by running the generator forwards
- * and then in reverse. (The low order r bits are redundant).
- * Then, if the state consists of all zeros, we set the
- * high order bit of x[0] to 1. This function only needs to
- * be called by seed, since the state transform preserves
- * this relationship.
- */
- void normalize_state()
- {
- const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
- const UIntType lower_mask = ~upper_mask;
- UIntType y0 = x[m-1] ^ x[n-1];
- if(y0 & (static_cast<UIntType>(1) << (w-1))) {
- y0 = ((y0 ^ a) << 1) | 1;
- } else {
- y0 = y0 << 1;
- }
- x[0] = (x[0] & upper_mask) | (y0 & lower_mask);
-
- // fix up the state if it's all zeroes.
- for(std::size_t j = 0; j < n; ++j) {
- if(x[j] != 0) return;
- }
- x[0] = static_cast<UIntType>(1) << (w-1);
- }
-
- /**
- * Given a pointer to the last element of the rewind array,
- * and the current size of the rewind array, finds an element
- * relative to the next available slot in the rewind array.
- */
- UIntType
- rewind_find(UIntType* last, std::size_t size, std::size_t j) const
- {
- std::size_t index = (j + n - size + n - 1) % n;
- if(index < n - size) {
- return x[index];
- } else {
- return *(last - (n - 1 - index));
- }
- }
-
- /**
- * Optimized algorithm for large jumps.
- *
- * Hiroshi Haramoto, Makoto Matsumoto, and Pierre L'Ecuyer. 2008.
- * A Fast Jump Ahead Algorithm for Linear Recurrences in a Polynomial
- * Space. In Proceedings of the 5th international conference on
- * Sequences and Their Applications (SETA '08).
- * DOI=10.1007/978-3-540-85912-3_26
- */
- void discard_many(boost::uintmax_t z)
- {
- // Compute the minimal polynomial, phi(t)
- // This depends only on the transition function,
- // which is constant. The characteristic
- // polynomial is the same as the minimal
- // polynomial for a maximum period generator
- // (which should be all specializations of
- // mersenne_twister.) Even if it weren't,
- // the characteristic polynomial is guaranteed
- // to be a multiple of the minimal polynomial,
- // which is good enough.
- detail::polynomial phi = get_characteristic_polynomial();
-
- // calculate g(t) = t^z % phi(t)
- detail::polynomial g = mod_pow_x(z, phi);
-
- // h(s_0, t) = \sum_{i=0}^{2k-1}o(s_i)t^{2k-i-1}
- detail::polynomial h;
- const std::size_t num_bits = w*n - r;
- for(std::size_t j = 0; j < num_bits * 2; ++j) {
- // Yes, we're advancing the generator state
- // here, but it doesn't matter because
- // we're going to overwrite it completely
- // in reconstruct_state.
- if(i >= n) twist();
- h[2*num_bits - j - 1] = x[i++] & UIntType(1);
- }
- // g(t)h(s_0, t)
- detail::polynomial gh = g * h;
- detail::polynomial result;
- for(std::size_t j = 0; j <= num_bits; ++j) {
- result[j] = gh[2*num_bits - j - 1];
- }
- reconstruct_state(result);
- }
- static detail::polynomial get_characteristic_polynomial()
- {
- const std::size_t num_bits = w*n - r;
- detail::polynomial helper;
- helper[num_bits - 1] = 1;
- mersenne_twister_engine tmp;
- tmp.reconstruct_state(helper);
- // Skip the first num_bits elements, since we
- // already know what they are.
- for(std::size_t j = 0; j < num_bits; ++j) {
- if(tmp.i >= n) tmp.twist();
- if(j == num_bits - 1)
- assert((tmp.x[tmp.i] & 1) == 1);
- else
- assert((tmp.x[tmp.i] & 1) == 0);
- ++tmp.i;
- }
- detail::polynomial phi;
- phi[num_bits] = 1;
- detail::polynomial next_bits = tmp.as_polynomial(num_bits);
- for(std::size_t j = 0; j < num_bits; ++j) {
- int val = next_bits[j] ^ phi[num_bits-j-1];
- phi[num_bits-j-1] = val;
- if(val) {
- for(std::size_t k = j + 1; k < num_bits; ++k) {
- phi[num_bits-k-1] ^= next_bits[k-j-1];
- }
- }
- }
- return phi;
- }
- detail::polynomial as_polynomial(std::size_t size) {
- detail::polynomial result;
- for(std::size_t j = 0; j < size; ++j) {
- if(i >= n) twist();
- result[j] = x[i++] & UIntType(1);
- }
- return result;
- }
- void reconstruct_state(const detail::polynomial& p)
- {
- const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
- const UIntType lower_mask = ~upper_mask;
- const std::size_t num_bits = w*n - r;
- for(std::size_t j = num_bits - n + 1; j <= num_bits; ++j)
- x[j % n] = p[j];
-
- UIntType y0 = 0;
- for(std::size_t j = num_bits + 1; j >= n - 1; --j) {
- UIntType y1 = x[j % n] ^ x[(j + m) % n];
- if(p[j - n + 1])
- y1 = (y1 ^ a) << UIntType(1) | UIntType(1);
- else
- y1 = y1 << UIntType(1);
- x[(j + 1) % n] = (y0 & upper_mask) | (y1 & lower_mask);
- y0 = y1;
- }
- i = 0;
- }
-
- /// \endcond
-
- // state representation: next output is o(x(i))
- // x[0] ... x[k] x[k+1] ... x[n-1] represents
- // x(i-k) ... x(i) x(i+1) ... x(i-k+n-1)
-
- UIntType x[n];
- std::size_t i;
-};
-
-/// \cond show_private
-
-#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
-// A definition is required even for integral static constants
-#define BOOST_RANDOM_MT_DEFINE_CONSTANT(type, name) \
-template<class UIntType, std::size_t w, std::size_t n, std::size_t m, \
- std::size_t r, UIntType a, std::size_t u, UIntType d, std::size_t s, \
- UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f> \
-const type mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::name
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, word_size);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, state_size);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, shift_size);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, mask_bits);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, xor_mask);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_u);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_d);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_s);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_b);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_t);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_c);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_l);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, initialization_multiplier);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, default_seed);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, parameter_a);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_u );
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_s);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, output_b);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_t);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, output_c);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_l);
-BOOST_RANDOM_MT_DEFINE_CONSTANT(bool, has_fixed_range);
-#undef BOOST_RANDOM_MT_DEFINE_CONSTANT
-#endif
-
-template<class UIntType,
- std::size_t w, std::size_t n, std::size_t m, std::size_t r,
- UIntType a, std::size_t u, UIntType d, std::size_t s,
- UIntType b, std::size_t t,
- UIntType c, std::size_t l, UIntType f>
-void
-mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::twist()
-{
- const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
- const UIntType lower_mask = ~upper_mask;
-
- const std::size_t unroll_factor = 6;
- const std::size_t unroll_extra1 = (n-m) % unroll_factor;
- const std::size_t unroll_extra2 = (m-1) % unroll_factor;
-
- // split loop to avoid costly modulo operations
- { // extra scope for MSVC brokenness w.r.t. for scope
- for(std::size_t j = 0; j < n-m-unroll_extra1; j++) {
- UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
- x[j] = x[j+m] ^ (y >> 1) ^ ((x[j+1]&1) * a);
- }
- }
- {
- for(std::size_t j = n-m-unroll_extra1; j < n-m; j++) {
- UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
- x[j] = x[j+m] ^ (y >> 1) ^ ((x[j+1]&1) * a);
- }
- }
- {
- for(std::size_t j = n-m; j < n-1-unroll_extra2; j++) {
- UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
- x[j] = x[j-(n-m)] ^ (y >> 1) ^ ((x[j+1]&1) * a);
- }
- }
- {
- for(std::size_t j = n-1-unroll_extra2; j < n-1; j++) {
- UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
- x[j] = x[j-(n-m)] ^ (y >> 1) ^ ((x[j+1]&1) * a);
- }
- }
- // last iteration
- UIntType y = (x[n-1] & upper_mask) | (x[0] & lower_mask);
- x[n-1] = x[m-1] ^ (y >> 1) ^ ((x[0]&1) * a);
- i = 0;
-}
-/// \endcond
-
-template<class UIntType,
- std::size_t w, std::size_t n, std::size_t m, std::size_t r,
- UIntType a, std::size_t u, UIntType d, std::size_t s,
- UIntType b, std::size_t t,
- UIntType c, std::size_t l, UIntType f>
-inline typename
-mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::result_type
-mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::operator()()
-{
- if(i == n)
- twist();
- // Step 4
- UIntType z = x[i];
- ++i;
- z ^= ((z >> u) & d);
- z ^= ((z << s) & b);
- z ^= ((z << t) & c);
- z ^= (z >> l);
- return z;
-}
-
-/**
- * The specializations \mt11213b and \mt19937 are from
- *
- * @blockquote
- * "Mersenne Twister: A 623-dimensionally equidistributed
- * uniform pseudo-random number generator", Makoto Matsumoto
- * and Takuji Nishimura, ACM Transactions on Modeling and
- * Computer Simulation: Special Issue on Uniform Random Number
- * Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
- * @endblockquote
- */
-typedef mersenne_twister_engine<uint32_t,32,351,175,19,0xccab8ee7,
- 11,0xffffffff,7,0x31b6ab00,15,0xffe50000,17,1812433253> mt11213b;
-
-/**
- * The specializations \mt11213b and \mt19937 are from
- *
- * @blockquote
- * "Mersenne Twister: A 623-dimensionally equidistributed
- * uniform pseudo-random number generator", Makoto Matsumoto
- * and Takuji Nishimura, ACM Transactions on Modeling and
- * Computer Simulation: Special Issue on Uniform Random Number
- * Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
- * @endblockquote
- */
-typedef mersenne_twister_engine<uint32_t,32,624,397,31,0x9908b0df,
- 11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253> mt19937;
-
-#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T)
-typedef mersenne_twister_engine<uint64_t,64,312,156,31,
- UINT64_C(0xb5026f5aa96619e9),29,UINT64_C(0x5555555555555555),17,
- UINT64_C(0x71d67fffeda60000),37,UINT64_C(0xfff7eee000000000),43,
- UINT64_C(6364136223846793005)> mt19937_64;
-#endif
-
-/// \cond show_deprecated
-
-template<class UIntType,
- int w, int n, int m, int r,
- UIntType a, int u, std::size_t s,
- UIntType b, int t,
- UIntType c, int l, UIntType v>
-class mersenne_twister :
- public mersenne_twister_engine<UIntType,
- w, n, m, r, a, u, ~(UIntType)0, s, b, t, c, l, 1812433253>
-{
- typedef mersenne_twister_engine<UIntType,
- w, n, m, r, a, u, ~(UIntType)0, s, b, t, c, l, 1812433253> base_type;
-public:
- mersenne_twister() {}
- BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(mersenne_twister, Gen, gen)
- { seed(gen); }
- BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(mersenne_twister, UIntType, val)
- { seed(val); }
- template<class It>
- mersenne_twister(It& first, It last) : base_type(first, last) {}
- void seed() { base_type::seed(); }
- BOOST_RANDOM_DETAIL_GENERATOR_SEED(mersenne_twister, Gen, gen)
- {
- detail::generator_seed_seq<Gen> seq(gen);
- base_type::seed(seq);
- }
- BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(mersenne_twister, UIntType, val)
- { base_type::seed(val); }
- template<class It>
- void seed(It& first, It last) { base_type::seed(first, last); }
-};
-
-/// \endcond
-
-} // namespace random
-
-using random::mt11213b;
-using random::mt19937;
-using random::mt19937_64;
-
-} // namespace boost
-
-BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt11213b)
-BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt19937)
-BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt19937_64)
-
-#include <boost/random/detail/enable_warnings.hpp>
-
-#endif // BOOST_RANDOM_MERSENNE_TWISTER_HPP
+/* boost random/mersenne_twister.hpp header file
+ *
+ * Copyright Jens Maurer 2000-2001
+ * Copyright Steven Watanabe 2010
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ * Revision history
+ * 2013-10-14 fixed some warnings with Wshadow (mgaunard)
+ * 2001-02-18 moved to individual header files
+ */
+
+#ifndef BOOST_RANDOM_MERSENNE_TWISTER_HPP
+#define BOOST_RANDOM_MERSENNE_TWISTER_HPP
+
+#include <iosfwd>
+#include <istream>
+#include <stdexcept>
+#include <boost/config.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/integer/integer_mask.hpp>
+#include <boost/random/detail/config.hpp>
+#include <boost/random/detail/ptr_helper.hpp>
+#include <boost/random/detail/seed.hpp>
+#include <boost/random/detail/seed_impl.hpp>
+#include <boost/random/detail/generator_seed_seq.hpp>
+#include <boost/random/detail/polynomial.hpp>
+
+#include <boost/random/detail/disable_warnings.hpp>
+
+namespace boost {
+namespace random {
+
+/**
+ * Instantiations of class template mersenne_twister_engine model a
+ * \pseudo_random_number_generator. It uses the algorithm described in
+ *
+ * @blockquote
+ * "Mersenne Twister: A 623-dimensionally equidistributed uniform
+ * pseudo-random number generator", Makoto Matsumoto and Takuji Nishimura,
+ * ACM Transactions on Modeling and Computer Simulation: Special Issue on
+ * Uniform Random Number Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
+ * @endblockquote
+ *
+ * @xmlnote
+ * The boost variant has been implemented from scratch and does not
+ * derive from or use mt19937.c provided on the above WWW site. However, it
+ * was verified that both produce identical output.
+ * @endxmlnote
+ *
+ * The seeding from an integer was changed in April 2005 to address a
+ * <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html">weakness</a>.
+ *
+ * The quality of the generator crucially depends on the choice of the
+ * parameters. User code should employ one of the sensibly parameterized
+ * generators such as \mt19937 instead.
+ *
+ * The generator requires considerable amounts of memory for the storage of
+ * its state array. For example, \mt11213b requires about 1408 bytes and
+ * \mt19937 requires about 2496 bytes.
+ */
+template<class UIntType,
+ std::size_t w, std::size_t n, std::size_t m, std::size_t r,
+ UIntType a, std::size_t u, UIntType d, std::size_t s,
+ UIntType b, std::size_t t,
+ UIntType c, std::size_t l, UIntType f>
+class mersenne_twister_engine
+{
+public:
+ typedef UIntType result_type;
+ BOOST_STATIC_CONSTANT(std::size_t, word_size = w);
+ BOOST_STATIC_CONSTANT(std::size_t, state_size = n);
+ BOOST_STATIC_CONSTANT(std::size_t, shift_size = m);
+ BOOST_STATIC_CONSTANT(std::size_t, mask_bits = r);
+ BOOST_STATIC_CONSTANT(UIntType, xor_mask = a);
+ BOOST_STATIC_CONSTANT(std::size_t, tempering_u = u);
+ BOOST_STATIC_CONSTANT(UIntType, tempering_d = d);
+ BOOST_STATIC_CONSTANT(std::size_t, tempering_s = s);
+ BOOST_STATIC_CONSTANT(UIntType, tempering_b = b);
+ BOOST_STATIC_CONSTANT(std::size_t, tempering_t = t);
+ BOOST_STATIC_CONSTANT(UIntType, tempering_c = c);
+ BOOST_STATIC_CONSTANT(std::size_t, tempering_l = l);
+ BOOST_STATIC_CONSTANT(UIntType, initialization_multiplier = f);
+ BOOST_STATIC_CONSTANT(UIntType, default_seed = 5489u);
+
+ // backwards compatibility
+ BOOST_STATIC_CONSTANT(UIntType, parameter_a = a);
+ BOOST_STATIC_CONSTANT(std::size_t, output_u = u);
+ BOOST_STATIC_CONSTANT(std::size_t, output_s = s);
+ BOOST_STATIC_CONSTANT(UIntType, output_b = b);
+ BOOST_STATIC_CONSTANT(std::size_t, output_t = t);
+ BOOST_STATIC_CONSTANT(UIntType, output_c = c);
+ BOOST_STATIC_CONSTANT(std::size_t, output_l = l);
+
+ // old Boost.Random concept requirements
+ BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
+
+
+ /**
+ * Constructs a @c mersenne_twister_engine and calls @c seed().
+ */
+ mersenne_twister_engine() { seed(); }
+
+ /**
+ * Constructs a @c mersenne_twister_engine and calls @c seed(value).
+ */
+ BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(mersenne_twister_engine,
+ UIntType, value)
+ { seed(value); }
+ template<class It> mersenne_twister_engine(It& first, It last)
+ { seed(first,last); }
+
+ /**
+ * Constructs a mersenne_twister_engine and calls @c seed(gen).
+ *
+ * @xmlnote
+ * The copy constructor will always be preferred over
+ * the templated constructor.
+ * @endxmlnote
+ */
+ BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(mersenne_twister_engine,
+ SeedSeq, seq)
+ { seed(seq); }
+
+ // compiler-generated copy ctor and assignment operator are fine
+
+ /** Calls @c seed(default_seed). */
+ void seed() { seed(default_seed); }
+
+ /**
+ * Sets the state x(0) to v mod 2w. Then, iteratively,
+ * sets x(i) to
+ * (i + f * (x(i-1) xor (x(i-1) rshift w-2))) mod 2<sup>w</sup>
+ * for i = 1 .. n-1. x(n) is the first value to be returned by operator().
+ */
+ BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(mersenne_twister_engine, UIntType, value)
+ {
+ // New seeding algorithm from
+ // http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html
+ // In the previous versions, MSBs of the seed affected only MSBs of the
+ // state x[].
+ const UIntType mask = (max)();
+ x[0] = value & mask;
+ for (i = 1; i < n; i++) {
+ // See Knuth "The Art of Computer Programming"
+ // Vol. 2, 3rd ed., page 106
+ x[i] = (f * (x[i-1] ^ (x[i-1] >> (w-2))) + i) & mask;
+ }
+
+ normalize_state();
+ }
+
+ /**
+ * Seeds a mersenne_twister_engine using values produced by seq.generate().
+ */
+ BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(mersenne_twister_engine, SeeqSeq, seq)
+ {
+ detail::seed_array_int<w>(seq, x);
+ i = n;
+
+ normalize_state();
+ }
+
+ /** Sets the state of the generator using values from an iterator range. */
+ template<class It>
+ void seed(It& first, It last)
+ {
+ detail::fill_array_int<w>(first, last, x);
+ i = n;
+
+ normalize_state();
+ }
+
+ /** Returns the smallest value that the generator can produce. */
+ static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ { return 0; }
+ /** Returns the largest value that the generator can produce. */
+ static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ { return boost::low_bits_mask_t<w>::sig_bits; }
+
+ /** Produces the next value of the generator. */
+ result_type operator()();
+
+ /** Fills a range with random values */
+ template<class Iter>
+ void generate(Iter first, Iter last)
+ { detail::generate_from_int(*this, first, last); }
+
+ /**
+ * Advances the state of the generator by @c z steps. Equivalent to
+ *
+ * @code
+ * for(unsigned long long i = 0; i < z; ++i) {
+ * gen();
+ * }
+ * @endcode
+ */
+ void discard(boost::uintmax_t z)
+ {
+#ifndef BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD
+#define BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD 10000000
+#endif
+ if(z > BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD) {
+ discard_many(z);
+ } else {
+ for(boost::uintmax_t j = 0; j < z; ++j) {
+ (*this)();
+ }
+ }
+ }
+
+#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
+ /** Writes a mersenne_twister_engine to a @c std::ostream */
+ template<class CharT, class Traits>
+ friend std::basic_ostream<CharT,Traits>&
+ operator<<(std::basic_ostream<CharT,Traits>& os,
+ const mersenne_twister_engine& mt)
+ {
+ mt.print(os);
+ return os;
+ }
+
+ /** Reads a mersenne_twister_engine from a @c std::istream */
+ template<class CharT, class Traits>
+ friend std::basic_istream<CharT,Traits>&
+ operator>>(std::basic_istream<CharT,Traits>& is,
+ mersenne_twister_engine& mt)
+ {
+ for(std::size_t j = 0; j < mt.state_size; ++j)
+ is >> mt.x[j] >> std::ws;
+ // MSVC (up to 7.1) and Borland (up to 5.64) don't handle the template
+ // value parameter "n" available from the class template scope, so use
+ // the static constant with the same value
+ mt.i = mt.state_size;
+ return is;
+ }
+#endif
+
+ /**
+ * Returns true if the two generators are in the same state,
+ * and will thus produce identical sequences.
+ */
+ friend bool operator==(const mersenne_twister_engine& x_,
+ const mersenne_twister_engine& y_)
+ {
+ if(x_.i < y_.i) return x_.equal_imp(y_);
+ else return y_.equal_imp(x_);
+ }
+
+ /**
+ * Returns true if the two generators are in different states.
+ */
+ friend bool operator!=(const mersenne_twister_engine& x_,
+ const mersenne_twister_engine& y_)
+ { return !(x_ == y_); }
+
+private:
+ /// \cond show_private
+
+ void twist();
+
+ /**
+ * Does the work of operator==. This is in a member function
+ * for portability. Some compilers, such as msvc 7.1 and
+ * Sun CC 5.10 can't access template parameters or static
+ * members of the class from inline friend functions.
+ *
+ * requires i <= other.i
+ */
+ bool equal_imp(const mersenne_twister_engine& other) const
+ {
+ UIntType back[n];
+ std::size_t offset = other.i - i;
+ for(std::size_t j = 0; j + offset < n; ++j)
+ if(x[j] != other.x[j+offset])
+ return false;
+ rewind(&back[n-1], offset);
+ for(std::size_t j = 0; j < offset; ++j)
+ if(back[j + n - offset] != other.x[j])
+ return false;
+ return true;
+ }
+
+ /**
+ * Does the work of operator<<. This is in a member function
+ * for portability.
+ */
+ template<class CharT, class Traits>
+ void print(std::basic_ostream<CharT, Traits>& os) const
+ {
+ UIntType data[n];
+ for(std::size_t j = 0; j < i; ++j) {
+ data[j + n - i] = x[j];
+ }
+ if(i != n) {
+ rewind(&data[n - i - 1], n - i);
+ }
+ os << data[0];
+ for(std::size_t j = 1; j < n; ++j) {
+ os << ' ' << data[j];
+ }
+ }
+
+ /**
+ * Copies z elements of the state preceding x[0] into
+ * the array whose last element is last.
+ */
+ void rewind(UIntType* last, std::size_t z) const
+ {
+ const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
+ const UIntType lower_mask = ~upper_mask;
+ UIntType y0 = x[m-1] ^ x[n-1];
+ if(y0 & (static_cast<UIntType>(1) << (w-1))) {
+ y0 = ((y0 ^ a) << 1) | 1;
+ } else {
+ y0 = y0 << 1;
+ }
+ for(std::size_t sz = 0; sz < z; ++sz) {
+ UIntType y1 =
+ rewind_find(last, sz, m-1) ^ rewind_find(last, sz, n-1);
+ if(y1 & (static_cast<UIntType>(1) << (w-1))) {
+ y1 = ((y1 ^ a) << 1) | 1;
+ } else {
+ y1 = y1 << 1;
+ }
+ *(last - sz) = (y0 & upper_mask) | (y1 & lower_mask);
+ y0 = y1;
+ }
+ }
+
+ /**
+ * Converts an arbitrary array into a valid generator state.
+ * First we normalize x[0], so that it contains the same
+ * value we would get by running the generator forwards
+ * and then in reverse. (The low order r bits are redundant).
+ * Then, if the state consists of all zeros, we set the
+ * high order bit of x[0] to 1. This function only needs to
+ * be called by seed, since the state transform preserves
+ * this relationship.
+ */
+ void normalize_state()
+ {
+ const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
+ const UIntType lower_mask = ~upper_mask;
+ UIntType y0 = x[m-1] ^ x[n-1];
+ if(y0 & (static_cast<UIntType>(1) << (w-1))) {
+ y0 = ((y0 ^ a) << 1) | 1;
+ } else {
+ y0 = y0 << 1;
+ }
+ x[0] = (x[0] & upper_mask) | (y0 & lower_mask);
+
+ // fix up the state if it's all zeroes.
+ for(std::size_t j = 0; j < n; ++j) {
+ if(x[j] != 0) return;
+ }
+ x[0] = static_cast<UIntType>(1) << (w-1);
+ }
+
+ /**
+ * Given a pointer to the last element of the rewind array,
+ * and the current size of the rewind array, finds an element
+ * relative to the next available slot in the rewind array.
+ */
+ UIntType
+ rewind_find(UIntType* last, std::size_t size, std::size_t j) const
+ {
+ std::size_t index = (j + n - size + n - 1) % n;
+ if(index < n - size) {
+ return x[index];
+ } else {
+ return *(last - (n - 1 - index));
+ }
+ }
+
+ /**
+ * Optimized algorithm for large jumps.
+ *
+ * Hiroshi Haramoto, Makoto Matsumoto, and Pierre L'Ecuyer. 2008.
+ * A Fast Jump Ahead Algorithm for Linear Recurrences in a Polynomial
+ * Space. In Proceedings of the 5th international conference on
+ * Sequences and Their Applications (SETA '08).
+ * DOI=10.1007/978-3-540-85912-3_26
+ */
+ void discard_many(boost::uintmax_t z)
+ {
+ // Compute the minimal polynomial, phi(t)
+ // This depends only on the transition function,
+ // which is constant. The characteristic
+ // polynomial is the same as the minimal
+ // polynomial for a maximum period generator
+ // (which should be all specializations of
+ // mersenne_twister.) Even if it weren't,
+ // the characteristic polynomial is guaranteed
+ // to be a multiple of the minimal polynomial,
+ // which is good enough.
+ detail::polynomial phi = get_characteristic_polynomial();
+
+ // calculate g(t) = t^z % phi(t)
+ detail::polynomial g = mod_pow_x(z, phi);
+
+ // h(s_0, t) = \sum_{i=0}^{2k-1}o(s_i)t^{2k-i-1}
+ detail::polynomial h;
+ const std::size_t num_bits = w*n - r;
+ for(std::size_t j = 0; j < num_bits * 2; ++j) {
+ // Yes, we're advancing the generator state
+ // here, but it doesn't matter because
+ // we're going to overwrite it completely
+ // in reconstruct_state.
+ if(i >= n) twist();
+ h[2*num_bits - j - 1] = x[i++] & UIntType(1);
+ }
+ // g(t)h(s_0, t)
+ detail::polynomial gh = g * h;
+ detail::polynomial result;
+ for(std::size_t j = 0; j <= num_bits; ++j) {
+ result[j] = gh[2*num_bits - j - 1];
+ }
+ reconstruct_state(result);
+ }
+ static detail::polynomial get_characteristic_polynomial()
+ {
+ const std::size_t num_bits = w*n - r;
+ detail::polynomial helper;
+ helper[num_bits - 1] = 1;
+ mersenne_twister_engine tmp;
+ tmp.reconstruct_state(helper);
+ // Skip the first num_bits elements, since we
+ // already know what they are.
+ for(std::size_t j = 0; j < num_bits; ++j) {
+ if(tmp.i >= n) tmp.twist();
+ if(j == num_bits - 1)
+ assert((tmp.x[tmp.i] & 1) == 1);
+ else
+ assert((tmp.x[tmp.i] & 1) == 0);
+ ++tmp.i;
+ }
+ detail::polynomial phi;
+ phi[num_bits] = 1;
+ detail::polynomial next_bits = tmp.as_polynomial(num_bits);
+ for(std::size_t j = 0; j < num_bits; ++j) {
+ int val = next_bits[j] ^ phi[num_bits-j-1];
+ phi[num_bits-j-1] = val;
+ if(val) {
+ for(std::size_t k = j + 1; k < num_bits; ++k) {
+ phi[num_bits-k-1] ^= next_bits[k-j-1];
+ }
+ }
+ }
+ return phi;
+ }
+ detail::polynomial as_polynomial(std::size_t size) {
+ detail::polynomial result;
+ for(std::size_t j = 0; j < size; ++j) {
+ if(i >= n) twist();
+ result[j] = x[i++] & UIntType(1);
+ }
+ return result;
+ }
+ void reconstruct_state(const detail::polynomial& p)
+ {
+ const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
+ const UIntType lower_mask = ~upper_mask;
+ const std::size_t num_bits = w*n - r;
+ for(std::size_t j = num_bits - n + 1; j <= num_bits; ++j)
+ x[j % n] = p[j];
+
+ UIntType y0 = 0;
+ for(std::size_t j = num_bits + 1; j >= n - 1; --j) {
+ UIntType y1 = x[j % n] ^ x[(j + m) % n];
+ if(p[j - n + 1])
+ y1 = (y1 ^ a) << UIntType(1) | UIntType(1);
+ else
+ y1 = y1 << UIntType(1);
+ x[(j + 1) % n] = (y0 & upper_mask) | (y1 & lower_mask);
+ y0 = y1;
+ }
+ i = 0;
+ }
+
+ /// \endcond
+
+ // state representation: next output is o(x(i))
+ // x[0] ... x[k] x[k+1] ... x[n-1] represents
+ // x(i-k) ... x(i) x(i+1) ... x(i-k+n-1)
+
+ UIntType x[n];
+ std::size_t i;
+};
+
+/// \cond show_private
+
+#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
+// A definition is required even for integral static constants
+#define BOOST_RANDOM_MT_DEFINE_CONSTANT(type, name) \
+template<class UIntType, std::size_t w, std::size_t n, std::size_t m, \
+ std::size_t r, UIntType a, std::size_t u, UIntType d, std::size_t s, \
+ UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f> \
+const type mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::name
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, word_size);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, state_size);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, shift_size);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, mask_bits);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, xor_mask);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_u);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_d);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_s);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_b);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_t);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_c);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_l);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, initialization_multiplier);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, default_seed);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, parameter_a);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_u );
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_s);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, output_b);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_t);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, output_c);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_l);
+BOOST_RANDOM_MT_DEFINE_CONSTANT(bool, has_fixed_range);
+#undef BOOST_RANDOM_MT_DEFINE_CONSTANT
+#endif
+
+template<class UIntType,
+ std::size_t w, std::size_t n, std::size_t m, std::size_t r,
+ UIntType a, std::size_t u, UIntType d, std::size_t s,
+ UIntType b, std::size_t t,
+ UIntType c, std::size_t l, UIntType f>
+void
+mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::twist()
+{
+ const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
+ const UIntType lower_mask = ~upper_mask;
+
+ const std::size_t unroll_factor = 6;
+ const std::size_t unroll_extra1 = (n-m) % unroll_factor;
+ const std::size_t unroll_extra2 = (m-1) % unroll_factor;
+
+ // split loop to avoid costly modulo operations
+ { // extra scope for MSVC brokenness w.r.t. for scope
+ for(std::size_t j = 0; j < n-m-unroll_extra1; j++) {
+ UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
+ x[j] = x[j+m] ^ (y >> 1) ^ ((x[j+1]&1) * a);
+ }
+ }
+ {
+ for(std::size_t j = n-m-unroll_extra1; j < n-m; j++) {
+ UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
+ x[j] = x[j+m] ^ (y >> 1) ^ ((x[j+1]&1) * a);
+ }
+ }
+ {
+ for(std::size_t j = n-m; j < n-1-unroll_extra2; j++) {
+ UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
+ x[j] = x[j-(n-m)] ^ (y >> 1) ^ ((x[j+1]&1) * a);
+ }
+ }
+ {
+ for(std::size_t j = n-1-unroll_extra2; j < n-1; j++) {
+ UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
+ x[j] = x[j-(n-m)] ^ (y >> 1) ^ ((x[j+1]&1) * a);
+ }
+ }
+ // last iteration
+ UIntType y = (x[n-1] & upper_mask) | (x[0] & lower_mask);
+ x[n-1] = x[m-1] ^ (y >> 1) ^ ((x[0]&1) * a);
+ i = 0;
+}
+/// \endcond
+
+template<class UIntType,
+ std::size_t w, std::size_t n, std::size_t m, std::size_t r,
+ UIntType a, std::size_t u, UIntType d, std::size_t s,
+ UIntType b, std::size_t t,
+ UIntType c, std::size_t l, UIntType f>
+inline typename
+mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::result_type
+mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::operator()()
+{
+ if(i == n)
+ twist();
+ // Step 4
+ UIntType z = x[i];
+ ++i;
+ z ^= ((z >> u) & d);
+ z ^= ((z << s) & b);
+ z ^= ((z << t) & c);
+ z ^= (z >> l);
+ return z;
+}
+
+/**
+ * The specializations \mt11213b and \mt19937 are from
+ *
+ * @blockquote
+ * "Mersenne Twister: A 623-dimensionally equidistributed
+ * uniform pseudo-random number generator", Makoto Matsumoto
+ * and Takuji Nishimura, ACM Transactions on Modeling and
+ * Computer Simulation: Special Issue on Uniform Random Number
+ * Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
+ * @endblockquote
+ */
+typedef mersenne_twister_engine<uint32_t,32,351,175,19,0xccab8ee7,
+ 11,0xffffffff,7,0x31b6ab00,15,0xffe50000,17,1812433253> mt11213b;
+
+/**
+ * The specializations \mt11213b and \mt19937 are from
+ *
+ * @blockquote
+ * "Mersenne Twister: A 623-dimensionally equidistributed
+ * uniform pseudo-random number generator", Makoto Matsumoto
+ * and Takuji Nishimura, ACM Transactions on Modeling and
+ * Computer Simulation: Special Issue on Uniform Random Number
+ * Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
+ * @endblockquote
+ */
+typedef mersenne_twister_engine<uint32_t,32,624,397,31,0x9908b0df,
+ 11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253> mt19937;
+
+#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T)
+typedef mersenne_twister_engine<uint64_t,64,312,156,31,
+ UINT64_C(0xb5026f5aa96619e9),29,UINT64_C(0x5555555555555555),17,
+ UINT64_C(0x71d67fffeda60000),37,UINT64_C(0xfff7eee000000000),43,
+ UINT64_C(6364136223846793005)> mt19937_64;
+#endif
+
+/// \cond show_deprecated
+
+template<class UIntType,
+ int w, int n, int m, int r,
+ UIntType a, int u, std::size_t s,
+ UIntType b, int t,
+ UIntType c, int l, UIntType v>
+class mersenne_twister :
+ public mersenne_twister_engine<UIntType,
+ w, n, m, r, a, u, ~(UIntType)0, s, b, t, c, l, 1812433253>
+{
+ typedef mersenne_twister_engine<UIntType,
+ w, n, m, r, a, u, ~(UIntType)0, s, b, t, c, l, 1812433253> base_type;
+public:
+ mersenne_twister() {}
+ BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(mersenne_twister, Gen, gen)
+ { seed(gen); }
+ BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(mersenne_twister, UIntType, val)
+ { seed(val); }
+ template<class It>
+ mersenne_twister(It& first, It last) : base_type(first, last) {}
+ void seed() { base_type::seed(); }
+ BOOST_RANDOM_DETAIL_GENERATOR_SEED(mersenne_twister, Gen, gen)
+ {
+ detail::generator_seed_seq<Gen> seq(gen);
+ base_type::seed(seq);
+ }
+ BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(mersenne_twister, UIntType, val)
+ { base_type::seed(val); }
+ template<class It>
+ void seed(It& first, It last) { base_type::seed(first, last); }
+};
+
+/// \endcond
+
+} // namespace random
+
+using random::mt11213b;
+using random::mt19937;
+using random::mt19937_64;
+
+} // namespace boost
+
+BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt11213b)
+BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt19937)
+BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt19937_64)
+
+#include <boost/random/detail/enable_warnings.hpp>
+
+#endif // BOOST_RANDOM_MERSENNE_TWISTER_HPP
diff --git a/contrib/src/boost/random/traits.hpp b/contrib/src/boost/random/traits.hpp
index 975421a..971327b 100644
--- a/contrib/src/boost/random/traits.hpp
+++ b/contrib/src/boost/random/traits.hpp
@@ -1,107 +1,107 @@
-/* boost random/traits.hpp header file
- *
- * Copyright John Maddock 2015
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * These traits classes serve two purposes: they are designed to mostly
- * work out of the box for multiprecision types (ie number types that are
- * C++ class types and not integers or floats from type-traits point of view),
- * they are also a potential point of specialization for user-defined
- * number types.
- *
- * $Id$
- */
-
-#ifndef BOOST_RANDOM_TRAITS_HPP
-#define BOOST_RANDOM_TRAITS_HPP
-
-#include <boost/type_traits/is_signed.hpp>
-#include <boost/type_traits/is_integral.hpp>
-#include <boost/type_traits/make_unsigned.hpp>
-#include <boost/mpl/bool.hpp>
-#include <limits>
-
-namespace boost {
-namespace random {
-namespace traits {
- // \cond show_private
- template <class T, bool intrinsic>
- struct make_unsigned_imp
- {
- typedef typename boost::make_unsigned<T>::type type;
- };
- template <class T>
- struct make_unsigned_imp<T, false>
- {
- BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
- BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_signed == false);
- BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_integer == true);
- typedef T type;
- };
- // \endcond
- /** \brief Converts the argument type T to an unsigned type.
- *
- * This trait has a single member `type` which is the unsigned type corresponding to T.
- * Note that
- * if T is signed, then member `type` *should define a type with one more bit precision than T*. For built-in
- * types this trait defaults to `boost::make_unsigned<T>::type`. For user defined types it simply asserts that
- * the argument type T is an unsigned integer (using std::numeric_limits).
- * User defined specializations may be provided for other cases.
- */
- template <class T>
- struct make_unsigned
- // \cond show_private
- : public make_unsigned_imp < T, boost::is_integral<T>::value >
- // \endcond
- {};
- // \cond show_private
- template <class T, bool intrinsic>
- struct make_unsigned_or_unbounded_imp
- {
- typedef typename boost::make_unsigned<T>::type type;
- };
- template <class T>
- struct make_unsigned_or_unbounded_imp<T, false>
- {
- BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
- BOOST_STATIC_ASSERT((std::numeric_limits<T>::is_signed == false) || (std::numeric_limits<T>::is_bounded == false));
- BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_integer == true);
- typedef T type;
- };
- // \endcond
- /** \brief Converts the argument type T to either an unsigned type or an unbounded integer type.
- *
- * This trait has a single member `type` which is either the unsigned type corresponding to T or an unbounded
- * integer type. This trait is used to generate types suitable for the calculation of a range: as a result
- * if T is signed, then member `type` *should define a type with one more bit precision than T*. For built-in
- * types this trait defaults to `boost::make_unsigned<T>::type`. For user defined types it simply asserts that
- * the argument type T is either an unbounded integer, or an unsigned one (using std::numeric_limits).
- * User defined specializations may be provided for other cases.
- */
- template <class T>
- struct make_unsigned_or_unbounded
- // \cond show_private
- : public make_unsigned_or_unbounded_imp < T, boost::is_integral<T>::value >
- // \endcond
- {};
- /** \brief Traits class that indicates whether type T is an integer
- */
- template <class T>
- struct is_integral
- : public mpl::bool_<boost::is_integral<T>::value || (std::numeric_limits<T>::is_integer)>
- {};
- /** \brief Traits class that indicates whether type T is a signed integer
- */
- template <class T> struct is_signed
- : public mpl::bool_ < boost::is_signed<T>::value || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer && std::numeric_limits<T>::is_signed)>
- {};
-
-}
-}
-}
-
-#endif
+/* boost random/traits.hpp header file
+ *
+ * Copyright John Maddock 2015
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * These traits classes serve two purposes: they are designed to mostly
+ * work out of the box for multiprecision types (ie number types that are
+ * C++ class types and not integers or floats from type-traits point of view),
+ * they are also a potential point of specialization for user-defined
+ * number types.
+ *
+ * $Id$
+ */
+
+#ifndef BOOST_RANDOM_TRAITS_HPP
+#define BOOST_RANDOM_TRAITS_HPP
+
+#include <boost/type_traits/is_signed.hpp>
+#include <boost/type_traits/is_integral.hpp>
+#include <boost/type_traits/make_unsigned.hpp>
+#include <boost/mpl/bool.hpp>
+#include <limits>
+
+namespace boost {
+namespace random {
+namespace traits {
+ // \cond show_private
+ template <class T, bool intrinsic>
+ struct make_unsigned_imp
+ {
+ typedef typename boost::make_unsigned<T>::type type;
+ };
+ template <class T>
+ struct make_unsigned_imp<T, false>
+ {
+ BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
+ BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_signed == false);
+ BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_integer == true);
+ typedef T type;
+ };
+ // \endcond
+ /** \brief Converts the argument type T to an unsigned type.
+ *
+ * This trait has a single member `type` which is the unsigned type corresponding to T.
+ * Note that
+ * if T is signed, then member `type` *should define a type with one more bit precision than T*. For built-in
+ * types this trait defaults to `boost::make_unsigned<T>::type`. For user defined types it simply asserts that
+ * the argument type T is an unsigned integer (using std::numeric_limits).
+ * User defined specializations may be provided for other cases.
+ */
+ template <class T>
+ struct make_unsigned
+ // \cond show_private
+ : public make_unsigned_imp < T, boost::is_integral<T>::value >
+ // \endcond
+ {};
+ // \cond show_private
+ template <class T, bool intrinsic>
+ struct make_unsigned_or_unbounded_imp
+ {
+ typedef typename boost::make_unsigned<T>::type type;
+ };
+ template <class T>
+ struct make_unsigned_or_unbounded_imp<T, false>
+ {
+ BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
+ BOOST_STATIC_ASSERT((std::numeric_limits<T>::is_signed == false) || (std::numeric_limits<T>::is_bounded == false));
+ BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_integer == true);
+ typedef T type;
+ };
+ // \endcond
+ /** \brief Converts the argument type T to either an unsigned type or an unbounded integer type.
+ *
+ * This trait has a single member `type` which is either the unsigned type corresponding to T or an unbounded
+ * integer type. This trait is used to generate types suitable for the calculation of a range: as a result
+ * if T is signed, then member `type` *should define a type with one more bit precision than T*. For built-in
+ * types this trait defaults to `boost::make_unsigned<T>::type`. For user defined types it simply asserts that
+ * the argument type T is either an unbounded integer, or an unsigned one (using std::numeric_limits).
+ * User defined specializations may be provided for other cases.
+ */
+ template <class T>
+ struct make_unsigned_or_unbounded
+ // \cond show_private
+ : public make_unsigned_or_unbounded_imp < T, boost::is_integral<T>::value >
+ // \endcond
+ {};
+ /** \brief Traits class that indicates whether type T is an integer
+ */
+ template <class T>
+ struct is_integral
+ : public mpl::bool_<boost::is_integral<T>::value || (std::numeric_limits<T>::is_integer)>
+ {};
+ /** \brief Traits class that indicates whether type T is a signed integer
+ */
+ template <class T> struct is_signed
+ : public mpl::bool_ < boost::is_signed<T>::value || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer && std::numeric_limits<T>::is_signed)>
+ {};
+
+}
+}
+}
+
+#endif
diff --git a/contrib/src/boost/random/uniform_int.hpp b/contrib/src/boost/random/uniform_int.hpp
index 4362652..3eac137 100644
--- a/contrib/src/boost/random/uniform_int.hpp
+++ b/contrib/src/boost/random/uniform_int.hpp
@@ -1,99 +1,99 @@
-/* boost random/uniform_int.hpp header file
- *
- * Copyright Jens Maurer 2000-2001
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- * Revision history
- * 2001-04-08 added min<max assertion (N. Becker)
- * 2001-02-18 moved to individual header files
- */
-
-#ifndef BOOST_RANDOM_UNIFORM_INT_HPP
-#define BOOST_RANDOM_UNIFORM_INT_HPP
-
-#include <boost/assert.hpp>
-#include <boost/random/uniform_int_distribution.hpp>
-
-namespace boost {
-
-/**
- * The distribution function uniform_int models a \random_distribution.
- * On each invocation, it returns a random integer value uniformly
- * distributed in the set of integer numbers {min, min+1, min+2, ..., max}.
- *
- * The template parameter IntType shall denote an integer-like value type.
- *
- * This class is deprecated. Please use @c uniform_int_distribution in
- * new code.
- */
-template<class IntType = int>
-class uniform_int : public random::uniform_int_distribution<IntType>
-{
- typedef random::uniform_int_distribution<IntType> base_type;
-public:
-
- class param_type : public base_type::param_type
- {
- public:
- typedef uniform_int distribution_type;
- /**
- * Constructs the parameters of a uniform_int distribution.
- *
- * Requires: min <= max
- */
- explicit param_type(IntType min_arg = 0, IntType max_arg = 9)
- : base_type::param_type(min_arg, max_arg)
- {}
- };
-
- /**
- * Constructs a uniform_int object. @c min and @c max are
- * the parameters of the distribution.
- *
- * Requires: min <= max
- */
- explicit uniform_int(IntType min_arg = 0, IntType max_arg = 9)
- : base_type(min_arg, max_arg)
- {}
-
- /** Constructs a uniform_int distribution from its parameters. */
- explicit uniform_int(const param_type& parm)
- : base_type(parm)
- {}
-
- /** Returns the parameters of the distribution */
- param_type param() const { return param_type(this->a(), this->b()); }
- /** Sets the parameters of the distribution. */
- void param(const param_type& parm) { this->base_type::param(parm); }
-
- // Codergear seems to have trouble with a using declaration here
-
- template<class Engine>
- IntType operator()(Engine& eng) const
- {
- return static_cast<const base_type&>(*this)(eng);
- }
-
- template<class Engine>
- IntType operator()(Engine& eng, const param_type& parm) const
- {
- return static_cast<const base_type&>(*this)(eng, parm);
- }
-
- template<class Engine>
- IntType operator()(Engine& eng, IntType n) const
- {
- BOOST_ASSERT(n > 0);
- return static_cast<const base_type&>(*this)(eng, param_type(0, n - 1));
- }
-};
-
-} // namespace boost
-
-#endif // BOOST_RANDOM_UNIFORM_INT_HPP
+/* boost random/uniform_int.hpp header file
+ *
+ * Copyright Jens Maurer 2000-2001
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ * Revision history
+ * 2001-04-08 added min<max assertion (N. Becker)
+ * 2001-02-18 moved to individual header files
+ */
+
+#ifndef BOOST_RANDOM_UNIFORM_INT_HPP
+#define BOOST_RANDOM_UNIFORM_INT_HPP
+
+#include <boost/assert.hpp>
+#include <boost/random/uniform_int_distribution.hpp>
+
+namespace boost {
+
+/**
+ * The distribution function uniform_int models a \random_distribution.
+ * On each invocation, it returns a random integer value uniformly
+ * distributed in the set of integer numbers {min, min+1, min+2, ..., max}.
+ *
+ * The template parameter IntType shall denote an integer-like value type.
+ *
+ * This class is deprecated. Please use @c uniform_int_distribution in
+ * new code.
+ */
+template<class IntType = int>
+class uniform_int : public random::uniform_int_distribution<IntType>
+{
+ typedef random::uniform_int_distribution<IntType> base_type;
+public:
+
+ class param_type : public base_type::param_type
+ {
+ public:
+ typedef uniform_int distribution_type;
+ /**
+ * Constructs the parameters of a uniform_int distribution.
+ *
+ * Requires: min <= max
+ */
+ explicit param_type(IntType min_arg = 0, IntType max_arg = 9)
+ : base_type::param_type(min_arg, max_arg)
+ {}
+ };
+
+ /**
+ * Constructs a uniform_int object. @c min and @c max are
+ * the parameters of the distribution.
+ *
+ * Requires: min <= max
+ */
+ explicit uniform_int(IntType min_arg = 0, IntType max_arg = 9)
+ : base_type(min_arg, max_arg)
+ {}
+
+ /** Constructs a uniform_int distribution from its parameters. */
+ explicit uniform_int(const param_type& parm)
+ : base_type(parm)
+ {}
+
+ /** Returns the parameters of the distribution */
+ param_type param() const { return param_type(this->a(), this->b()); }
+ /** Sets the parameters of the distribution. */
+ void param(const param_type& parm) { this->base_type::param(parm); }
+
+ // Codergear seems to have trouble with a using declaration here
+
+ template<class Engine>
+ IntType operator()(Engine& eng) const
+ {
+ return static_cast<const base_type&>(*this)(eng);
+ }
+
+ template<class Engine>
+ IntType operator()(Engine& eng, const param_type& parm) const
+ {
+ return static_cast<const base_type&>(*this)(eng, parm);
+ }
+
+ template<class Engine>
+ IntType operator()(Engine& eng, IntType n) const
+ {
+ BOOST_ASSERT(n > 0);
+ return static_cast<const base_type&>(*this)(eng, param_type(0, n - 1));
+ }
+};
+
+} // namespace boost
+
+#endif // BOOST_RANDOM_UNIFORM_INT_HPP
diff --git a/contrib/src/boost/random/uniform_int_distribution.hpp b/contrib/src/boost/random/uniform_int_distribution.hpp
index e0d3a9b..be6d89d 100644
--- a/contrib/src/boost/random/uniform_int_distribution.hpp
+++ b/contrib/src/boost/random/uniform_int_distribution.hpp
@@ -1,419 +1,419 @@
-/* boost random/uniform_int_distribution.hpp header file
- *
- * Copyright Jens Maurer 2000-2001
- * Copyright Steven Watanabe 2011
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- * Revision history
- * 2001-04-08 added min<max assertion (N. Becker)
- * 2001-02-18 moved to individual header files
- */
-
-#ifndef BOOST_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
-#define BOOST_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
-
-#include <iosfwd>
-#include <ios>
-#include <istream>
-#include <boost/config.hpp>
-#include <boost/limits.hpp>
-#include <boost/assert.hpp>
-#include <boost/random/detail/config.hpp>
-#include <boost/random/detail/operators.hpp>
-#include <boost/random/detail/uniform_int_float.hpp>
-#include <boost/random/detail/signed_unsigned_tools.hpp>
-#include <boost/random/traits.hpp>
-#include <boost/mpl/bool.hpp>
-#ifdef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
-#include <boost/mpl/if.hpp>
-#endif
-
-namespace boost {
-namespace random {
-namespace detail {
-
-
-#ifdef BOOST_MSVC
-#pragma warning(push)
-// disable division by zero warning, since we can't
-// actually divide by zero.
-#pragma warning(disable:4723)
-#endif
-
-template<class Engine, class T>
-T generate_uniform_int(
- Engine& eng, T min_value, T max_value,
- boost::mpl::true_ /** is_integral<Engine::result_type> */)
-{
- typedef T result_type;
- typedef typename boost::random::traits::make_unsigned_or_unbounded<T>::type range_type;
- typedef typename Engine::result_type base_result;
- // ranges are always unsigned or unbounded
- typedef typename boost::random::traits::make_unsigned_or_unbounded<base_result>::type base_unsigned;
- const range_type range = random::detail::subtract<result_type>()(max_value, min_value);
- const base_result bmin = (eng.min)();
- const base_unsigned brange =
- random::detail::subtract<base_result>()((eng.max)(), (eng.min)());
-
- if(range == 0) {
- return min_value;
- } else if(brange == range) {
- // this will probably never happen in real life
- // basically nothing to do; just take care we don't overflow / underflow
- base_unsigned v = random::detail::subtract<base_result>()(eng(), bmin);
- return random::detail::add<base_unsigned, result_type>()(v, min_value);
- } else if(brange < range) {
- // use rejection method to handle things like 0..3 --> 0..4
- for(;;) {
- // concatenate several invocations of the base RNG
- // take extra care to avoid overflows
-
- // limit == floor((range+1)/(brange+1))
- // Therefore limit*(brange+1) <= range+1
- range_type limit;
- if(range == (std::numeric_limits<range_type>::max)()) {
- limit = range/(range_type(brange)+1);
- if(range % (range_type(brange)+1) == range_type(brange))
- ++limit;
- } else {
- limit = (range+1)/(range_type(brange)+1);
- }
-
- // We consider "result" as expressed to base (brange+1):
- // For every power of (brange+1), we determine a random factor
- range_type result = range_type(0);
- range_type mult = range_type(1);
-
- // loop invariants:
- // result < mult
- // mult <= range
- while(mult <= limit) {
- // Postcondition: result <= range, thus no overflow
- //
- // limit*(brange+1)<=range+1 def. of limit (1)
- // eng()-bmin<=brange eng() post. (2)
- // and mult<=limit. loop condition (3)
- // Therefore mult*(eng()-bmin+1)<=range+1 by (1),(2),(3) (4)
- // Therefore mult*(eng()-bmin)+mult<=range+1 rearranging (4) (5)
- // result<mult loop invariant (6)
- // Therefore result+mult*(eng()-bmin)<range+1 by (5), (6) (7)
- //
- // Postcondition: result < mult*(brange+1)
- //
- // result<mult loop invariant (1)
- // eng()-bmin<=brange eng() post. (2)
- // Therefore result+mult*(eng()-bmin) <
- // mult+mult*(eng()-bmin) by (1) (3)
- // Therefore result+(eng()-bmin)*mult <
- // mult+mult*brange by (2), (3) (4)
- // Therefore result+(eng()-bmin)*mult <
- // mult*(brange+1) by (4)
- result += static_cast<range_type>(static_cast<range_type>(random::detail::subtract<base_result>()(eng(), bmin)) * mult);
-
- // equivalent to (mult * (brange+1)) == range+1, but avoids overflow.
- if(mult * range_type(brange) == range - mult + 1) {
- // The destination range is an integer power of
- // the generator's range.
- return(result);
- }
-
- // Postcondition: mult <= range
- //
- // limit*(brange+1)<=range+1 def. of limit (1)
- // mult<=limit loop condition (2)
- // Therefore mult*(brange+1)<=range+1 by (1), (2) (3)
- // mult*(brange+1)!=range+1 preceding if (4)
- // Therefore mult*(brange+1)<range+1 by (3), (4) (5)
- //
- // Postcondition: result < mult
- //
- // See the second postcondition on the change to result.
- mult *= range_type(brange)+range_type(1);
- }
- // loop postcondition: range/mult < brange+1
- //
- // mult > limit loop condition (1)
- // Suppose range/mult >= brange+1 Assumption (2)
- // range >= mult*(brange+1) by (2) (3)
- // range+1 > mult*(brange+1) by (3) (4)
- // range+1 > (limit+1)*(brange+1) by (1), (4) (5)
- // (range+1)/(brange+1) > limit+1 by (5) (6)
- // limit < floor((range+1)/(brange+1)) by (6) (7)
- // limit==floor((range+1)/(brange+1)) def. of limit (8)
- // not (2) reductio (9)
- //
- // loop postcondition: (range/mult)*mult+(mult-1) >= range
- //
- // (range/mult)*mult + range%mult == range identity (1)
- // range%mult < mult def. of % (2)
- // (range/mult)*mult+mult > range by (1), (2) (3)
- // (range/mult)*mult+(mult-1) >= range by (3) (4)
- //
- // Note that the maximum value of result at this point is (mult-1),
- // so after this final step, we generate numbers that can be
- // at least as large as range. We have to really careful to avoid
- // overflow in this final addition and in the rejection. Anything
- // that overflows is larger than range and can thus be rejected.
-
- // range/mult < brange+1 -> no endless loop
- range_type result_increment =
- generate_uniform_int(
- eng,
- static_cast<range_type>(0),
- static_cast<range_type>(range/mult),
- boost::mpl::true_());
- if(std::numeric_limits<range_type>::is_bounded && ((std::numeric_limits<range_type>::max)() / mult < result_increment)) {
- // The multiplcation would overflow. Reject immediately.
- continue;
- }
- result_increment *= mult;
- // unsigned integers are guaranteed to wrap on overflow.
- result += result_increment;
- if(result < result_increment) {
- // The addition overflowed. Reject.
- continue;
- }
- if(result > range) {
- // Too big. Reject.
- continue;
- }
- return random::detail::add<range_type, result_type>()(result, min_value);
- }
- } else { // brange > range
-#ifdef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
- typedef typename mpl::if_c<
- std::numeric_limits<range_type>::is_specialized && std::numeric_limits<base_unsigned>::is_specialized
- && (std::numeric_limits<range_type>::digits >= std::numeric_limits<base_unsigned>::digits),
- range_type, base_unsigned>::type mixed_range_type;
-#else
- typedef base_unsigned mixed_range_type;
-#endif
-
- mixed_range_type bucket_size;
- // it's safe to add 1 to range, as long as we cast it first,
- // because we know that it is less than brange. However,
- // we do need to be careful not to cause overflow by adding 1
- // to brange. We use mixed_range_type throughout for mixed
- // arithmetic between base_unsigned and range_type - in the case
- // that range_type has more bits than base_unsigned it is always
- // safe to use range_type for this albeit it may be more effient
- // to use base_unsigned. The latter is a narrowing conversion though
- // which may be disallowed if range_type is a multiprecision type
- // and there are no explicit converison operators.
-
- if(brange == (std::numeric_limits<base_unsigned>::max)()) {
- bucket_size = static_cast<mixed_range_type>(brange) / (static_cast<mixed_range_type>(range)+1);
- if(static_cast<mixed_range_type>(brange) % (static_cast<mixed_range_type>(range)+1) == static_cast<mixed_range_type>(range)) {
- ++bucket_size;
- }
- } else {
- bucket_size = static_cast<mixed_range_type>(brange + 1) / (static_cast<mixed_range_type>(range)+1);
- }
- for(;;) {
- mixed_range_type result =
- random::detail::subtract<base_result>()(eng(), bmin);
- result /= bucket_size;
- // result and range are non-negative, and result is possibly larger
- // than range, so the cast is safe
- if(result <= static_cast<mixed_range_type>(range))
- return random::detail::add<mixed_range_type, result_type>()(result, min_value);
- }
- }
-}
-
-#ifdef BOOST_MSVC
-#pragma warning(pop)
-#endif
-
-template<class Engine, class T>
-inline T generate_uniform_int(
- Engine& eng, T min_value, T max_value,
- boost::mpl::false_ /** is_integral<Engine::result_type> */)
-{
- uniform_int_float<Engine> wrapper(eng);
- return generate_uniform_int(wrapper, min_value, max_value, boost::mpl::true_());
-}
-
-template<class Engine, class T>
-inline T generate_uniform_int(Engine& eng, T min_value, T max_value)
-{
- typedef typename Engine::result_type base_result;
- return generate_uniform_int(eng, min_value, max_value,
- boost::random::traits::is_integral<base_result>());
-}
-
-}
-
-/**
- * The class template uniform_int_distribution models a \random_distribution.
- * On each invocation, it returns a random integer value uniformly
- * distributed in the set of integers {min, min+1, min+2, ..., max}.
- *
- * The template parameter IntType shall denote an integer-like value type.
- */
-template<class IntType = int>
-class uniform_int_distribution
-{
-public:
- typedef IntType input_type;
- typedef IntType result_type;
-
- class param_type
- {
- public:
-
- typedef uniform_int_distribution distribution_type;
-
- /**
- * Constructs the parameters of a uniform_int_distribution.
- *
- * Requires min <= max
- */
- explicit param_type(
- IntType min_arg = 0,
- IntType max_arg = (std::numeric_limits<IntType>::max)())
- : _min(min_arg), _max(max_arg)
- {
- BOOST_ASSERT(_min <= _max);
- }
-
- /** Returns the minimum value of the distribution. */
- IntType a() const { return _min; }
- /** Returns the maximum value of the distribution. */
- IntType b() const { return _max; }
-
- /** Writes the parameters to a @c std::ostream. */
- BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
- {
- os << parm._min << " " << parm._max;
- return os;
- }
-
- /** Reads the parameters from a @c std::istream. */
- BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
- {
- IntType min_in, max_in;
- if(is >> min_in >> std::ws >> max_in) {
- if(min_in <= max_in) {
- parm._min = min_in;
- parm._max = max_in;
- } else {
- is.setstate(std::ios_base::failbit);
- }
- }
- return is;
- }
-
- /** Returns true if the two sets of parameters are equal. */
- BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
- { return lhs._min == rhs._min && lhs._max == rhs._max; }
-
- /** Returns true if the two sets of parameters are different. */
- BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
-
- private:
-
- IntType _min;
- IntType _max;
- };
-
- /**
- * Constructs a uniform_int_distribution. @c min and @c max are
- * the parameters of the distribution.
- *
- * Requires: min <= max
- */
- explicit uniform_int_distribution(
- IntType min_arg = 0,
- IntType max_arg = (std::numeric_limits<IntType>::max)())
- : _min(min_arg), _max(max_arg)
- {
- BOOST_ASSERT(min_arg <= max_arg);
- }
- /** Constructs a uniform_int_distribution from its parameters. */
- explicit uniform_int_distribution(const param_type& parm)
- : _min(parm.a()), _max(parm.b()) {}
-
- /** Returns the minimum value of the distribution */
- IntType min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
- /** Returns the maximum value of the distribution */
- IntType max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
-
- /** Returns the minimum value of the distribution */
- IntType a() const { return _min; }
- /** Returns the maximum value of the distribution */
- IntType b() const { return _max; }
-
- /** Returns the parameters of the distribution. */
- param_type param() const { return param_type(_min, _max); }
- /** Sets the parameters of the distribution. */
- void param(const param_type& parm)
- {
- _min = parm.a();
- _max = parm.b();
- }
-
- /**
- * Effects: Subsequent uses of the distribution do not depend
- * on values produced by any engine prior to invoking reset.
- */
- void reset() { }
-
- /** Returns an integer uniformly distributed in the range [min, max]. */
- template<class Engine>
- result_type operator()(Engine& eng) const
- { return detail::generate_uniform_int(eng, _min, _max); }
-
- /**
- * Returns an integer uniformly distributed in the range
- * [param.a(), param.b()].
- */
- template<class Engine>
- result_type operator()(Engine& eng, const param_type& parm) const
- { return detail::generate_uniform_int(eng, parm.a(), parm.b()); }
-
- /** Writes the distribution to a @c std::ostream. */
- BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, uniform_int_distribution, ud)
- {
- os << ud.param();
- return os;
- }
-
- /** Reads the distribution from a @c std::istream. */
- BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, uniform_int_distribution, ud)
- {
- param_type parm;
- if(is >> parm) {
- ud.param(parm);
- }
- return is;
- }
-
- /**
- * Returns true if the two distributions will produce identical sequences
- * of values given equal generators.
- */
- BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(uniform_int_distribution, lhs, rhs)
- { return lhs._min == rhs._min && lhs._max == rhs._max; }
-
- /**
- * Returns true if the two distributions may produce different sequences
- * of values given equal generators.
- */
- BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(uniform_int_distribution)
-
-private:
- IntType _min;
- IntType _max;
-};
-
-} // namespace random
-} // namespace boost
-
-#endif // BOOST_RANDOM_UNIFORM_INT_HPP
+/* boost random/uniform_int_distribution.hpp header file
+ *
+ * Copyright Jens Maurer 2000-2001
+ * Copyright Steven Watanabe 2011
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ * Revision history
+ * 2001-04-08 added min<max assertion (N. Becker)
+ * 2001-02-18 moved to individual header files
+ */
+
+#ifndef BOOST_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
+#define BOOST_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
+
+#include <iosfwd>
+#include <ios>
+#include <istream>
+#include <boost/config.hpp>
+#include <boost/limits.hpp>
+#include <boost/assert.hpp>
+#include <boost/random/detail/config.hpp>
+#include <boost/random/detail/operators.hpp>
+#include <boost/random/detail/uniform_int_float.hpp>
+#include <boost/random/detail/signed_unsigned_tools.hpp>
+#include <boost/random/traits.hpp>
+#include <boost/mpl/bool.hpp>
+#ifdef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
+#include <boost/mpl/if.hpp>
+#endif
+
+namespace boost {
+namespace random {
+namespace detail {
+
+
+#ifdef BOOST_MSVC
+#pragma warning(push)
+// disable division by zero warning, since we can't
+// actually divide by zero.
+#pragma warning(disable:4723)
+#endif
+
+template<class Engine, class T>
+T generate_uniform_int(
+ Engine& eng, T min_value, T max_value,
+ boost::mpl::true_ /** is_integral<Engine::result_type> */)
+{
+ typedef T result_type;
+ typedef typename boost::random::traits::make_unsigned_or_unbounded<T>::type range_type;
+ typedef typename Engine::result_type base_result;
+ // ranges are always unsigned or unbounded
+ typedef typename boost::random::traits::make_unsigned_or_unbounded<base_result>::type base_unsigned;
+ const range_type range = random::detail::subtract<result_type>()(max_value, min_value);
+ const base_result bmin = (eng.min)();
+ const base_unsigned brange =
+ random::detail::subtract<base_result>()((eng.max)(), (eng.min)());
+
+ if(range == 0) {
+ return min_value;
+ } else if(brange == range) {
+ // this will probably never happen in real life
+ // basically nothing to do; just take care we don't overflow / underflow
+ base_unsigned v = random::detail::subtract<base_result>()(eng(), bmin);
+ return random::detail::add<base_unsigned, result_type>()(v, min_value);
+ } else if(brange < range) {
+ // use rejection method to handle things like 0..3 --> 0..4
+ for(;;) {
+ // concatenate several invocations of the base RNG
+ // take extra care to avoid overflows
+
+ // limit == floor((range+1)/(brange+1))
+ // Therefore limit*(brange+1) <= range+1
+ range_type limit;
+ if(range == (std::numeric_limits<range_type>::max)()) {
+ limit = range/(range_type(brange)+1);
+ if(range % (range_type(brange)+1) == range_type(brange))
+ ++limit;
+ } else {
+ limit = (range+1)/(range_type(brange)+1);
+ }
+
+ // We consider "result" as expressed to base (brange+1):
+ // For every power of (brange+1), we determine a random factor
+ range_type result = range_type(0);
+ range_type mult = range_type(1);
+
+ // loop invariants:
+ // result < mult
+ // mult <= range
+ while(mult <= limit) {
+ // Postcondition: result <= range, thus no overflow
+ //
+ // limit*(brange+1)<=range+1 def. of limit (1)
+ // eng()-bmin<=brange eng() post. (2)
+ // and mult<=limit. loop condition (3)
+ // Therefore mult*(eng()-bmin+1)<=range+1 by (1),(2),(3) (4)
+ // Therefore mult*(eng()-bmin)+mult<=range+1 rearranging (4) (5)
+ // result<mult loop invariant (6)
+ // Therefore result+mult*(eng()-bmin)<range+1 by (5), (6) (7)
+ //
+ // Postcondition: result < mult*(brange+1)
+ //
+ // result<mult loop invariant (1)
+ // eng()-bmin<=brange eng() post. (2)
+ // Therefore result+mult*(eng()-bmin) <
+ // mult+mult*(eng()-bmin) by (1) (3)
+ // Therefore result+(eng()-bmin)*mult <
+ // mult+mult*brange by (2), (3) (4)
+ // Therefore result+(eng()-bmin)*mult <
+ // mult*(brange+1) by (4)
+ result += static_cast<range_type>(static_cast<range_type>(random::detail::subtract<base_result>()(eng(), bmin)) * mult);
+
+ // equivalent to (mult * (brange+1)) == range+1, but avoids overflow.
+ if(mult * range_type(brange) == range - mult + 1) {
+ // The destination range is an integer power of
+ // the generator's range.
+ return(result);
+ }
+
+ // Postcondition: mult <= range
+ //
+ // limit*(brange+1)<=range+1 def. of limit (1)
+ // mult<=limit loop condition (2)
+ // Therefore mult*(brange+1)<=range+1 by (1), (2) (3)
+ // mult*(brange+1)!=range+1 preceding if (4)
+ // Therefore mult*(brange+1)<range+1 by (3), (4) (5)
+ //
+ // Postcondition: result < mult
+ //
+ // See the second postcondition on the change to result.
+ mult *= range_type(brange)+range_type(1);
+ }
+ // loop postcondition: range/mult < brange+1
+ //
+ // mult > limit loop condition (1)
+ // Suppose range/mult >= brange+1 Assumption (2)
+ // range >= mult*(brange+1) by (2) (3)
+ // range+1 > mult*(brange+1) by (3) (4)
+ // range+1 > (limit+1)*(brange+1) by (1), (4) (5)
+ // (range+1)/(brange+1) > limit+1 by (5) (6)
+ // limit < floor((range+1)/(brange+1)) by (6) (7)
+ // limit==floor((range+1)/(brange+1)) def. of limit (8)
+ // not (2) reductio (9)
+ //
+ // loop postcondition: (range/mult)*mult+(mult-1) >= range
+ //
+ // (range/mult)*mult + range%mult == range identity (1)
+ // range%mult < mult def. of % (2)
+ // (range/mult)*mult+mult > range by (1), (2) (3)
+ // (range/mult)*mult+(mult-1) >= range by (3) (4)
+ //
+ // Note that the maximum value of result at this point is (mult-1),
+ // so after this final step, we generate numbers that can be
+ // at least as large as range. We have to really careful to avoid
+ // overflow in this final addition and in the rejection. Anything
+ // that overflows is larger than range and can thus be rejected.
+
+ // range/mult < brange+1 -> no endless loop
+ range_type result_increment =
+ generate_uniform_int(
+ eng,
+ static_cast<range_type>(0),
+ static_cast<range_type>(range/mult),
+ boost::mpl::true_());
+ if(std::numeric_limits<range_type>::is_bounded && ((std::numeric_limits<range_type>::max)() / mult < result_increment)) {
+ // The multiplcation would overflow. Reject immediately.
+ continue;
+ }
+ result_increment *= mult;
+ // unsigned integers are guaranteed to wrap on overflow.
+ result += result_increment;
+ if(result < result_increment) {
+ // The addition overflowed. Reject.
+ continue;
+ }
+ if(result > range) {
+ // Too big. Reject.
+ continue;
+ }
+ return random::detail::add<range_type, result_type>()(result, min_value);
+ }
+ } else { // brange > range
+#ifdef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
+ typedef typename mpl::if_c<
+ std::numeric_limits<range_type>::is_specialized && std::numeric_limits<base_unsigned>::is_specialized
+ && (std::numeric_limits<range_type>::digits >= std::numeric_limits<base_unsigned>::digits),
+ range_type, base_unsigned>::type mixed_range_type;
+#else
+ typedef base_unsigned mixed_range_type;
+#endif
+
+ mixed_range_type bucket_size;
+ // it's safe to add 1 to range, as long as we cast it first,
+ // because we know that it is less than brange. However,
+ // we do need to be careful not to cause overflow by adding 1
+ // to brange. We use mixed_range_type throughout for mixed
+ // arithmetic between base_unsigned and range_type - in the case
+ // that range_type has more bits than base_unsigned it is always
+ // safe to use range_type for this albeit it may be more effient
+ // to use base_unsigned. The latter is a narrowing conversion though
+ // which may be disallowed if range_type is a multiprecision type
+ // and there are no explicit converison operators.
+
+ if(brange == (std::numeric_limits<base_unsigned>::max)()) {
+ bucket_size = static_cast<mixed_range_type>(brange) / (static_cast<mixed_range_type>(range)+1);
+ if(static_cast<mixed_range_type>(brange) % (static_cast<mixed_range_type>(range)+1) == static_cast<mixed_range_type>(range)) {
+ ++bucket_size;
+ }
+ } else {
+ bucket_size = static_cast<mixed_range_type>(brange + 1) / (static_cast<mixed_range_type>(range)+1);
+ }
+ for(;;) {
+ mixed_range_type result =
+ random::detail::subtract<base_result>()(eng(), bmin);
+ result /= bucket_size;
+ // result and range are non-negative, and result is possibly larger
+ // than range, so the cast is safe
+ if(result <= static_cast<mixed_range_type>(range))
+ return random::detail::add<mixed_range_type, result_type>()(result, min_value);
+ }
+ }
+}
+
+#ifdef BOOST_MSVC
+#pragma warning(pop)
+#endif
+
+template<class Engine, class T>
+inline T generate_uniform_int(
+ Engine& eng, T min_value, T max_value,
+ boost::mpl::false_ /** is_integral<Engine::result_type> */)
+{
+ uniform_int_float<Engine> wrapper(eng);
+ return generate_uniform_int(wrapper, min_value, max_value, boost::mpl::true_());
+}
+
+template<class Engine, class T>
+inline T generate_uniform_int(Engine& eng, T min_value, T max_value)
+{
+ typedef typename Engine::result_type base_result;
+ return generate_uniform_int(eng, min_value, max_value,
+ boost::random::traits::is_integral<base_result>());
+}
+
+}
+
+/**
+ * The class template uniform_int_distribution models a \random_distribution.
+ * On each invocation, it returns a random integer value uniformly
+ * distributed in the set of integers {min, min+1, min+2, ..., max}.
+ *
+ * The template parameter IntType shall denote an integer-like value type.
+ */
+template<class IntType = int>
+class uniform_int_distribution
+{
+public:
+ typedef IntType input_type;
+ typedef IntType result_type;
+
+ class param_type
+ {
+ public:
+
+ typedef uniform_int_distribution distribution_type;
+
+ /**
+ * Constructs the parameters of a uniform_int_distribution.
+ *
+ * Requires min <= max
+ */
+ explicit param_type(
+ IntType min_arg = 0,
+ IntType max_arg = (std::numeric_limits<IntType>::max)())
+ : _min(min_arg), _max(max_arg)
+ {
+ BOOST_ASSERT(_min <= _max);
+ }
+
+ /** Returns the minimum value of the distribution. */
+ IntType a() const { return _min; }
+ /** Returns the maximum value of the distribution. */
+ IntType b() const { return _max; }
+
+ /** Writes the parameters to a @c std::ostream. */
+ BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
+ {
+ os << parm._min << " " << parm._max;
+ return os;
+ }
+
+ /** Reads the parameters from a @c std::istream. */
+ BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
+ {
+ IntType min_in, max_in;
+ if(is >> min_in >> std::ws >> max_in) {
+ if(min_in <= max_in) {
+ parm._min = min_in;
+ parm._max = max_in;
+ } else {
+ is.setstate(std::ios_base::failbit);
+ }
+ }
+ return is;
+ }
+
+ /** Returns true if the two sets of parameters are equal. */
+ BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
+ { return lhs._min == rhs._min && lhs._max == rhs._max; }
+
+ /** Returns true if the two sets of parameters are different. */
+ BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
+
+ private:
+
+ IntType _min;
+ IntType _max;
+ };
+
+ /**
+ * Constructs a uniform_int_distribution. @c min and @c max are
+ * the parameters of the distribution.
+ *
+ * Requires: min <= max
+ */
+ explicit uniform_int_distribution(
+ IntType min_arg = 0,
+ IntType max_arg = (std::numeric_limits<IntType>::max)())
+ : _min(min_arg), _max(max_arg)
+ {
+ BOOST_ASSERT(min_arg <= max_arg);
+ }
+ /** Constructs a uniform_int_distribution from its parameters. */
+ explicit uniform_int_distribution(const param_type& parm)
+ : _min(parm.a()), _max(parm.b()) {}
+
+ /** Returns the minimum value of the distribution */
+ IntType min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
+ /** Returns the maximum value of the distribution */
+ IntType max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
+
+ /** Returns the minimum value of the distribution */
+ IntType a() const { return _min; }
+ /** Returns the maximum value of the distribution */
+ IntType b() const { return _max; }
+
+ /** Returns the parameters of the distribution. */
+ param_type param() const { return param_type(_min, _max); }
+ /** Sets the parameters of the distribution. */
+ void param(const param_type& parm)
+ {
+ _min = parm.a();
+ _max = parm.b();
+ }
+
+ /**
+ * Effects: Subsequent uses of the distribution do not depend
+ * on values produced by any engine prior to invoking reset.
+ */
+ void reset() { }
+
+ /** Returns an integer uniformly distributed in the range [min, max]. */
+ template<class Engine>
+ result_type operator()(Engine& eng) const
+ { return detail::generate_uniform_int(eng, _min, _max); }
+
+ /**
+ * Returns an integer uniformly distributed in the range
+ * [param.a(), param.b()].
+ */
+ template<class Engine>
+ result_type operator()(Engine& eng, const param_type& parm) const
+ { return detail::generate_uniform_int(eng, parm.a(), parm.b()); }
+
+ /** Writes the distribution to a @c std::ostream. */
+ BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, uniform_int_distribution, ud)
+ {
+ os << ud.param();
+ return os;
+ }
+
+ /** Reads the distribution from a @c std::istream. */
+ BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, uniform_int_distribution, ud)
+ {
+ param_type parm;
+ if(is >> parm) {
+ ud.param(parm);
+ }
+ return is;
+ }
+
+ /**
+ * Returns true if the two distributions will produce identical sequences
+ * of values given equal generators.
+ */
+ BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(uniform_int_distribution, lhs, rhs)
+ { return lhs._min == rhs._min && lhs._max == rhs._max; }
+
+ /**
+ * Returns true if the two distributions may produce different sequences
+ * of values given equal generators.
+ */
+ BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(uniform_int_distribution)
+
+private:
+ IntType _min;
+ IntType _max;
+};
+
+} // namespace random
+} // namespace boost
+
+#endif // BOOST_RANDOM_UNIFORM_INT_HPP
diff --git a/contrib/src/boost/random/variate_generator.hpp b/contrib/src/boost/random/variate_generator.hpp
index 6d5aac4..e5ddb03 100644
--- a/contrib/src/boost/random/variate_generator.hpp
+++ b/contrib/src/boost/random/variate_generator.hpp
@@ -1,122 +1,122 @@
-/* boost random/variate_generator.hpp header file
- *
- * Copyright Jens Maurer 2002
- * Copyright Steven Watanabe 2011
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org for most recent version including documentation.
- *
- * $Id$
- *
- */
-
-#ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP
-#define BOOST_RANDOM_RANDOM_GENERATOR_HPP
-
-#include <boost/random/detail/ptr_helper.hpp>
-
-#include <boost/random/detail/disable_warnings.hpp>
-
-namespace boost {
-
-/// \cond hide_private_members
-
-namespace random {
-
-///\endcond
-
-/**
- * A random variate generator is used to join a random number
- * generator together with a random number distribution.
- * Boost.Random provides a vast choice of \generators as well
- * as \distributions.
- *
- * The argument for the template parameter Engine shall be of
- * the form U, U&, or U*, where U models a
- * \uniform_random_number_generator. Then, the member
- * engine_value_type names U (not the pointer or reference to U).
- *
- * Specializations of @c variate_generator satisfy the
- * requirements of CopyConstructible. They also satisfy the
- * requirements of Assignable unless the template parameter
- * Engine is of the form U&.
- *
- * The complexity of all functions specified in this section
- * is constant. No function described in this section except
- * the constructor throws an exception.
- */
-template<class Engine, class Distribution>
-class variate_generator
-{
-private:
- typedef boost::random::detail::ptr_helper<Engine> helper_type;
-public:
- typedef typename helper_type::value_type engine_value_type;
- typedef Engine engine_type;
- typedef Distribution distribution_type;
- typedef typename Distribution::result_type result_type;
-
- /**
- * Constructs a @c variate_generator object with the associated
- * \uniform_random_number_generator eng and the associated
- * \random_distribution d.
- *
- * Throws: If and what the copy constructor of Engine or
- * Distribution throws.
- */
- variate_generator(Engine e, Distribution d)
- : _eng(e), _dist(d) { }
-
- /** Returns: distribution()(engine()) */
- result_type operator()() { return _dist(engine()); }
- /**
- * Returns: distribution()(engine(), value).
- */
- template<class T>
- result_type operator()(const T& value) { return _dist(engine(), value); }
-
- /**
- * Returns: A reference to the associated uniform random number generator.
- */
- engine_value_type& engine() { return helper_type::ref(_eng); }
- /**
- * Returns: A reference to the associated uniform random number generator.
- */
- const engine_value_type& engine() const { return helper_type::ref(_eng); }
-
- /** Returns: A reference to the associated \random_distribution. */
- distribution_type& distribution() { return _dist; }
- /**
- * Returns: A reference to the associated random distribution.
- */
- const distribution_type& distribution() const { return _dist; }
-
- /**
- * Precondition: distribution().min() is well-formed
- *
- * Returns: distribution().min()
- */
- result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); }
- /**
- * Precondition: distribution().max() is well-formed
- *
- * Returns: distribution().max()
- */
- result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); }
-
-private:
- Engine _eng;
- distribution_type _dist;
-};
-
-} // namespace random
-
-using random::variate_generator;
-
-} // namespace boost
-
-#include <boost/random/detail/enable_warnings.hpp>
-
-#endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP
+/* boost random/variate_generator.hpp header file
+ *
+ * Copyright Jens Maurer 2002
+ * Copyright Steven Watanabe 2011
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP
+#define BOOST_RANDOM_RANDOM_GENERATOR_HPP
+
+#include <boost/random/detail/ptr_helper.hpp>
+
+#include <boost/random/detail/disable_warnings.hpp>
+
+namespace boost {
+
+/// \cond hide_private_members
+
+namespace random {
+
+///\endcond
+
+/**
+ * A random variate generator is used to join a random number
+ * generator together with a random number distribution.
+ * Boost.Random provides a vast choice of \generators as well
+ * as \distributions.
+ *
+ * The argument for the template parameter Engine shall be of
+ * the form U, U&, or U*, where U models a
+ * \uniform_random_number_generator. Then, the member
+ * engine_value_type names U (not the pointer or reference to U).
+ *
+ * Specializations of @c variate_generator satisfy the
+ * requirements of CopyConstructible. They also satisfy the
+ * requirements of Assignable unless the template parameter
+ * Engine is of the form U&.
+ *
+ * The complexity of all functions specified in this section
+ * is constant. No function described in this section except
+ * the constructor throws an exception.
+ */
+template<class Engine, class Distribution>
+class variate_generator
+{
+private:
+ typedef boost::random::detail::ptr_helper<Engine> helper_type;
+public:
+ typedef typename helper_type::value_type engine_value_type;
+ typedef Engine engine_type;
+ typedef Distribution distribution_type;
+ typedef typename Distribution::result_type result_type;
+
+ /**
+ * Constructs a @c variate_generator object with the associated
+ * \uniform_random_number_generator eng and the associated
+ * \random_distribution d.
+ *
+ * Throws: If and what the copy constructor of Engine or
+ * Distribution throws.
+ */
+ variate_generator(Engine e, Distribution d)
+ : _eng(e), _dist(d) { }
+
+ /** Returns: distribution()(engine()) */
+ result_type operator()() { return _dist(engine()); }
+ /**
+ * Returns: distribution()(engine(), value).
+ */
+ template<class T>
+ result_type operator()(const T& value) { return _dist(engine(), value); }
+
+ /**
+ * Returns: A reference to the associated uniform random number generator.
+ */
+ engine_value_type& engine() { return helper_type::ref(_eng); }
+ /**
+ * Returns: A reference to the associated uniform random number generator.
+ */
+ const engine_value_type& engine() const { return helper_type::ref(_eng); }
+
+ /** Returns: A reference to the associated \random_distribution. */
+ distribution_type& distribution() { return _dist; }
+ /**
+ * Returns: A reference to the associated random distribution.
+ */
+ const distribution_type& distribution() const { return _dist; }
+
+ /**
+ * Precondition: distribution().min() is well-formed
+ *
+ * Returns: distribution().min()
+ */
+ result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); }
+ /**
+ * Precondition: distribution().max() is well-formed
+ *
+ * Returns: distribution().max()
+ */
+ result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); }
+
+private:
+ Engine _eng;
+ distribution_type _dist;
+};
+
+} // namespace random
+
+using random::variate_generator;
+
+} // namespace boost
+
+#include <boost/random/detail/enable_warnings.hpp>
+
+#endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP