2
0
mirror of https://github.com/boostorg/random.git synced 2026-01-19 04:22:17 +00:00

Warning patrol

[SVN r70017]
This commit is contained in:
Steven Watanabe
2011-03-16 03:24:42 +00:00
parent 45255face5
commit cb6b4f1ffb
40 changed files with 203 additions and 127 deletions

View File

@@ -13,13 +13,15 @@
#ifndef BOOST_RANDOM_BINOMIAL_DISTRIBUTION_HPP_INCLUDED
#define BOOST_RANDOM_BINOMIAL_DISTRIBUTION_HPP_INCLUDED
#include <cmath>
#include <boost/config/no_tr1/cmath.hpp>
#include <cstdlib>
#include <iosfwd>
#include <boost/random/detail/config.hpp>
#include <boost/random/uniform_01.hpp>
#include <boost/random/detail/disable_warnings.hpp>
namespace boost {
namespace random {
@@ -415,4 +417,6 @@ using random::binomial_distribution;
}
#include <boost/random/detail/enable_warnings.hpp>
#endif

View File

@@ -43,8 +43,11 @@ public:
{
if(((unsigned_m() - 1) & unsigned_m()) == 0)
return (unsigned_type(x)) & (unsigned_m() - 1);
else
return x % m;
else {
IntType supress_warnings = (m == 0);
BOOST_ASSERT(supress_warnings == 0);
return x % (m + supress_warnings);
}
}
static IntType add(IntType x, IntType c)
@@ -83,9 +86,11 @@ public:
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
return (a*x+c) % m;
else
else if(m <= (traits::const_max-c)/a) { // i.e. a*m+c <= max
IntType supress_warnings = (m == 0);
BOOST_ASSERT(supress_warnings == 0);
return (a*x+c) % (m + supress_warnings);
} else
return add(mult(a, x), c);
}
@@ -113,7 +118,9 @@ private:
static IntType mult_small(IntType a, IntType x)
{
return a*x % m;
IntType supress_warnings = (m == 0);
BOOST_ASSERT(supress_warnings == 0);
return a*x % (m + supress_warnings);
}
static IntType mult_schrage(IntType a, IntType value)
@@ -130,9 +137,12 @@ private:
IntType q, r;
IntType value = 0;
IntType supress_warnings = (m == 0);
BOOST_ASSERT(supress_warnings == 0);
while(true) {
if(a == 0 || b <= traits::const_max/a)
return add(value, IntType(a * b % m));
return add(value, IntType(a * b % (m + supress_warnings)));
if(b < a) std::swap(a, b);
q = m / a;
@@ -143,7 +153,7 @@ private:
a = r;
b = IntType(b/q);
if(a == 0 || b <= traits::const_max/a)
return sub(value, IntType(a * b % m));
return sub(value, IntType(a * b % (m + supress_warnings)));
if(b < a) std::swap(a, b);
q = m / a;

View File

@@ -28,6 +28,8 @@
#include <boost/random/detail/integer_log2.hpp>
#include <boost/random/detail/signed_unsigned_tools.hpp>
#include <boost/random/detail/disable_warnings.hpp>
namespace boost {
namespace random {
namespace detail {
@@ -60,7 +62,7 @@ template<>
struct const_pow_impl<0>
{
template<class T>
static T call(T arg, int n, T result)
static T call(T, int, T result)
{
return result;
}
@@ -165,7 +167,9 @@ void generate_from_int(Engine& eng, Iter begin, Iter end)
} 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;
val >>= 32;
int supress_warning = (bits >= 32);
BOOST_ASSERT(supress_warning == 1);
val >>= (32 * supress_warning);
*begin++ = word;
if(begin == end) return;
}
@@ -184,7 +188,9 @@ void generate_from_int(Engine& eng, Iter begin, Iter end)
if(bits >= 32) {
for(; available_bits >= 32; available_bits -= 32) {
boost::uint_least32_t word = boost::uint_least32_t(val) & 0xFFFFFFFFu;
val >>= 32;
int supress_warning = (bits >= 32);
BOOST_ASSERT(supress_warning == 1);
val >>= (32 * supress_warning);
*begin++ = word;
if(begin == end) return;
}
@@ -386,4 +392,6 @@ void fill_array_real(Iter& first, Iter last, RealType (&x)[n])
}
}
#include <boost/random/detail/enable_warnings.hpp>
#endif

View File

@@ -20,6 +20,8 @@
#include <boost/integer.hpp>
#include <boost/random/detail/config.hpp>
#include <boost/random/detail/disable_warnings.hpp>
namespace boost {
namespace random {
namespace detail {
@@ -66,4 +68,6 @@ private:
} // namespace random
} // namespace boost
#include <boost/random/detail/enable_warnings.hpp>
#endif // BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP

View File

@@ -32,6 +32,8 @@
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/random/detail/disable_warnings.hpp>
namespace boost {
namespace random {
@@ -446,4 +448,6 @@ private:
}
}
#include <boost/random/detail/enable_warnings.hpp>
#endif

View File

@@ -56,11 +56,10 @@ RealType generate_canonical_impl(URNG& g, boost::mpl::false_ /*is_integral*/)
std::size_t digits = std::numeric_limits<RealType>::digits;
std::size_t engine_bits = g.precision();
std::size_t b = (std::min)(bits, digits);
std::size_t k = (b + engine_bits - 1) / engine_bits;
RealType R = pow(RealType(2), RealType(engine_bits));
RealType mult = R;
RealType limit = pow(RealType(2), RealType(b));
RealType S = g() - (g.min)();
RealType S = RealType(g() - (g.min)());
while(mult < limit) {
RealType inc(floor((RealType(g()) - RealType((g.min)())) * R));
S += inc * mult;

View File

@@ -28,6 +28,8 @@
#include <boost/random/detail/operators.hpp>
#include <boost/random/detail/seed_impl.hpp>
#include <boost/random/detail/disable_warnings.hpp>
namespace boost {
namespace random {
@@ -260,4 +262,6 @@ using random::hellekalek1995;
} // namespace boost
#include <boost/random/detail/enable_warnings.hpp>
#endif // BOOST_RANDOM_INVERSIVE_CONGRUENTIAL_HPP

View File

@@ -23,6 +23,8 @@
#include <boost/random/uniform_01.hpp>
#include <boost/random/detail/config.hpp>
#include <boost/random/detail/disable_warnings.hpp>
namespace boost {
namespace random {
@@ -353,4 +355,6 @@ using random::poisson_distribution;
} // namespace boost
#include <boost/random/detail/enable_warnings.hpp>
#endif // BOOST_RANDOM_POISSON_DISTRIBUTION_HPP

View File

@@ -19,6 +19,8 @@
#include <boost/assert.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/random/detail/disable_warnings.hpp>
namespace boost {
namespace random {
@@ -66,4 +68,6 @@ using random::random_number_generator;
} // namespace boost
#include <boost/random/detail/enable_warnings.hpp>
#endif // BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP

View File

@@ -45,7 +45,7 @@ namespace detail {
class ranlux_documentation {};
}
typedef subtract_with_carry_engine<int, 24, 10, 24> ranlux_base;
typedef subtract_with_carry_engine<uint32_t, 24, 10, 24> ranlux_base;
typedef subtract_with_carry_01_engine<float, 24, 10, 24> ranlux_base_01;
typedef subtract_with_carry_01_engine<double, 48, 10, 24> ranlux64_base_01;
@@ -66,7 +66,7 @@ typedef discard_block_engine<ranlux64_base_01, 223, 24> ranlux64_3_01;
typedef discard_block_engine<ranlux64_base_01, 389, 24> ranlux64_4_01;
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T)
typedef subtract_with_carry_engine<int64_t, 48, 10, 24> ranlux64_base;
typedef subtract_with_carry_engine<uint64_t, 48, 10, 24> ranlux64_base;
/** @copydoc boost::random::detail::ranlux_documentation */
typedef discard_block_engine<ranlux64_base, 223, 24> ranlux64_3;
/** @copydoc boost::random::detail::ranlux_documentation */

View File

@@ -111,16 +111,17 @@ public:
*
* Complexity: Exactly k+1 invocations of the base generator.
*/
template<class T>
void seed(T& s) { _rng.seed(s); init(); }
BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(shuffle_order_engine,
result_type, seed_arg)
{ _rng.seed(seed_arg); init(); }
/**
* Invokes the one-argument seed method of the base generator
* with the parameter seed and re-initializes the internal buffer array.
* with the parameter seq and re-initializes the internal buffer array.
*
* Complexity: Exactly k+1 invocations of the base generator.
*/
template<class T>
void seed(const T& s) { _rng.seed(s); init(); }
BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(shuffle_order_engine, SeedSeq, seq)
{ _rng.seed(seq); init(); }
template<class It> void seed(It& first, It last)
{ _rng.seed(first, last); init(); }
@@ -203,7 +204,7 @@ public:
BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, shuffle_order_engine, s)
{
os << s._rng;
for(int i = 0; i < k; ++i)
for(std::size_t i = 0; i < k; ++i)
os << ' ' << s.v[i];
os << ' ' << s.y;
return os;
@@ -213,7 +214,7 @@ public:
BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, shuffle_order_engine, s)
{
is >> s._rng;
for(int i = 0; i < k; ++i)
for(std::size_t i = 0; i < k; ++i)
is >> std::ws >> s.v[i];
is >> std::ws >> s.y;
return is;

View File

@@ -66,7 +66,7 @@ void subtract_with_carry_discard(Engine& eng, boost::uintmax_t z) {
if(k < z) {
// main loop: update full blocks from k = 0 to long_lag
for(int i = 0; i < (z - k) / long_lag; ++i) {
for(std::size_t i = 0; i < (z - k) / long_lag; ++i) {
for(std::size_t j = 0; j < short_lag; ++j) {
carry = eng.do_update(j, j + long_lag - short_lag, carry);
}

View File

@@ -8,7 +8,7 @@
# bring in rules for testing
import testing ;
project /boost/random/test ;
project /boost/random/test : requirements <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS ;
run test_const_mod.cpp /boost//unit_test_framework ;
run test_generate_canonical.cpp /boost//unit_test_framework ;

View File

@@ -9,8 +9,22 @@
*
*/
#ifndef BOOST_RANDOM_TEST_CONCEPTS_HPP
#define BOOST_RANDOM_TEST_CONCEPTS_HPP
#include <boost/config.hpp>
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4100)
#endif
#include <boost/concept_check.hpp>
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#include <boost/concept_archetype.hpp>
#include <boost/concept/requires.hpp>
#include <boost/mpl/assert.hpp>
@@ -22,8 +36,11 @@
#include <istream>
#include <ostream>
#ifndef BOOST_RANDOM_TEST_CONCEPTS_HPP
#define BOOST_RANDOM_TEST_CONCEPTS_HPP
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4510)
#pragma warning(disable:4610)
#endif
namespace boost {
namespace random {
@@ -135,7 +152,7 @@ private:
E v;
const E x;
seed_seq_archetype<> q;
result_type s;
typename detail::seed_type<result_type>::type s;
unsigned long long z;
void check_extra(boost::mpl::true_ /*is_integral*/) {}
@@ -197,4 +214,8 @@ private:
}
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif

View File

@@ -94,7 +94,7 @@ public:
for(int i = 0; i < n; ++i)
count(f());
}
double probability(int i) const { return 1.0/classes(); }
double probability(int /*i*/) const { return 1.0/classes(); }
};
// two-dimensional equidistribution experiment

View File

@@ -25,7 +25,7 @@
bool do_test(double p, long long max) {
std::cout << "running bernoulli(" << p << ")" << " " << max << " times: " << std::flush;
boost::math::binomial expected(max, p);
boost::math::binomial expected(static_cast<double>(max), p);
boost::random::bernoulli_distribution<> dist(p);
boost::mt19937 gen;

View File

@@ -98,37 +98,37 @@ typedef boost::mpl::vector<
> int32_types;
BOOST_AUTO_TEST_CASE_TEMPLATE(test_mult32, IntType, int32_types) {
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(0, 0)), 0);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(0, 2147483562)), 0);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(2147483562, 0)), 0);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(2147483562, 2147483562)), 1);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(1234567890, 1234657890)), 813106682);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(0, 0)), IntType(0));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(0, 2147483562)), IntType(0));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(2147483562, 0)), IntType(0));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(2147483562, 2147483562)), IntType(1));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(1234567890, 1234657890)), IntType(813106682));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(test_add32, IntType, int32_types) {
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::add(0, 0)), 0);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::add(0, 2147483562)), 2147483562);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::add(2147483562, 0)), 2147483562);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::add(2147483562, 2147483562)), 2147483561);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::add(1234567890, 1234657890)), 321742217);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::add(0, 0)), IntType(0));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::add(0, 2147483562)), IntType(2147483562));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::add(2147483562, 0)), IntType(2147483562));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::add(2147483562, 2147483562)), IntType(2147483561));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::add(1234567890, 1234657890)), IntType(321742217));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(test_mult_add32, IntType, int32_types) {
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(0, 0, 0)), 0);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(0, 2147483562, 827364)), 827364);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(2147483562, 0, 827364)), 827364);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(2147483562, 2147483562, 2147483562)), 0);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(1234567890, 1234657890, 1726384759)), 392007878);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(0, 0, 0)), IntType(0));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(0, 2147483562, 827364)), IntType(827364));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(2147483562, 0, 827364)), IntType(827364));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(2147483562, 2147483562, 2147483562)), IntType(0));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(1234567890, 1234657890, 1726384759)), IntType(392007878));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(test_invert32, IntType, int32_types) {
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::invert(0)), 0);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(0, 0, 0)), 0);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::invert(0)), IntType(0));
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult_add(0, 0, 0)), IntType(0));
IntType inverse;
inverse = boost::random::const_mod<IntType, 2147483563>::invert(2147483562);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(2147483562, inverse)), 1);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(2147483562, inverse)), IntType(1));
inverse = boost::random::const_mod<IntType, 2147483563>::invert(1234567890);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(1234567890, inverse)), 1);
BOOST_CHECK_EQUAL((boost::random::const_mod<IntType, 2147483563>::mult(1234567890, inverse)), IntType(1));
}
#if !defined(BOOST_NO_INT64_T)
@@ -140,44 +140,44 @@ typedef boost::mpl::vector<
BOOST_AUTO_TEST_CASE_TEMPLATE(test_mult64, IntType, int64_types) {
typedef boost::random::const_mod<IntType, INT64_C(2147483563652738498)> const_mod_type;
BOOST_CHECK_EQUAL((const_mod_type::mult(0, 0)), 0);
BOOST_CHECK_EQUAL((const_mod_type::mult(0, 2147483562)), 0);
BOOST_CHECK_EQUAL((const_mod_type::mult(2147483562, 0)), 0);
BOOST_CHECK_EQUAL((const_mod_type::mult(2147483562, 2147483562)), INT64_C(316718521754730848));
BOOST_CHECK_EQUAL((const_mod_type::mult(1234567890, 1234657890)), INT64_C(1524268986129152100));
BOOST_CHECK_EQUAL((const_mod_type::mult(INT64_C(1234567890726352938), INT64_C(1234657890736453927))), INT64_C(88656187017794672));
BOOST_CHECK_EQUAL((const_mod_type::mult(0, 0)), IntType(0));
BOOST_CHECK_EQUAL((const_mod_type::mult(0, 2147483562)), IntType(0));
BOOST_CHECK_EQUAL((const_mod_type::mult(2147483562, 0)), IntType(0));
BOOST_CHECK_EQUAL((const_mod_type::mult(2147483562, 2147483562)), IntType(INT64_C(316718521754730848)));
BOOST_CHECK_EQUAL((const_mod_type::mult(1234567890, 1234657890)), IntType(INT64_C(1524268986129152100)));
BOOST_CHECK_EQUAL((const_mod_type::mult(INT64_C(1234567890726352938), INT64_C(1234657890736453927))), IntType(INT64_C(88656187017794672)));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(test_add64, IntType, int64_types) {
typedef boost::random::const_mod<IntType, INT64_C(2147483563652738498)> const_mod_type;
BOOST_CHECK_EQUAL((const_mod_type::add(0, 0)), 0);
BOOST_CHECK_EQUAL((const_mod_type::add(0, 2147483562)), 2147483562);
BOOST_CHECK_EQUAL((const_mod_type::add(2147483562, 0)), 2147483562);
BOOST_CHECK_EQUAL((const_mod_type::add(2147483562, 2147483562)), 4294967124);
BOOST_CHECK_EQUAL((const_mod_type::add(1234567890, 1234657890)), 2469225780);
BOOST_CHECK_EQUAL((const_mod_type::add(INT64_C(1234567890726352938), INT64_C(1234657890736453927))), INT64_C(321742217810068367));
BOOST_CHECK_EQUAL((const_mod_type::add(INT64_C(2147483563652738490), 8)), 0);
BOOST_CHECK_EQUAL((const_mod_type::add(0, 0)), IntType(0));
BOOST_CHECK_EQUAL((const_mod_type::add(0, 2147483562)), IntType(2147483562));
BOOST_CHECK_EQUAL((const_mod_type::add(2147483562, 0)), IntType(2147483562));
BOOST_CHECK_EQUAL((const_mod_type::add(2147483562, 2147483562)), IntType(4294967124U));
BOOST_CHECK_EQUAL((const_mod_type::add(1234567890, 1234657890)), IntType(2469225780U));
BOOST_CHECK_EQUAL((const_mod_type::add(INT64_C(1234567890726352938), INT64_C(1234657890736453927))), IntType(INT64_C(321742217810068367)));
BOOST_CHECK_EQUAL((const_mod_type::add(INT64_C(2147483563652738490), 8)), IntType(0));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(test_mult_add64, IntType, int64_types) {
typedef boost::random::const_mod<IntType, INT64_C(2147483563652738498)> const_mod_type;
BOOST_CHECK_EQUAL((const_mod_type::mult_add(0, 0, 0)), 0);
BOOST_CHECK_EQUAL((const_mod_type::mult_add(0, 2147483562, 827364)), 827364);
BOOST_CHECK_EQUAL((const_mod_type::mult_add(2147483562, 0, 827364)), 827364);
BOOST_CHECK_EQUAL((const_mod_type::mult_add(2147483562, 2147483562, 2147483562)), INT64_C(316718523902214410));
BOOST_CHECK_EQUAL((const_mod_type::mult_add(1234567890, 1234657890, 1726384759)), INT64_C(1524268987855536859));
BOOST_CHECK_EQUAL((const_mod_type::mult_add(INT64_C(1234567890726352938), INT64_C(1234657890736453927), INT64_C(1726384759726488649))), INT64_C(1815040946744283321));
BOOST_CHECK_EQUAL((const_mod_type::mult_add(0, 0, 0)), IntType(0));
BOOST_CHECK_EQUAL((const_mod_type::mult_add(0, 2147483562, 827364)), IntType(827364));
BOOST_CHECK_EQUAL((const_mod_type::mult_add(2147483562, 0, 827364)), IntType(827364));
BOOST_CHECK_EQUAL((const_mod_type::mult_add(2147483562, 2147483562, 2147483562)), IntType(INT64_C(316718523902214410)));
BOOST_CHECK_EQUAL((const_mod_type::mult_add(1234567890, 1234657890, 1726384759)), IntType(INT64_C(1524268987855536859)));
BOOST_CHECK_EQUAL((const_mod_type::mult_add(INT64_C(1234567890726352938), INT64_C(1234657890736453927), INT64_C(1726384759726488649))), IntType(INT64_C(1815040946744283321)));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(test_invert64, IntType, int64_types) {
typedef boost::random::const_mod<IntType, INT64_C(2147483563652738498)> const_mod_type;
BOOST_CHECK_EQUAL((const_mod_type::invert(0)), 0);
BOOST_CHECK_EQUAL((const_mod_type::mult_add(0, 0, 0)), 0);
BOOST_CHECK_EQUAL((const_mod_type::invert(0)), IntType(0));
BOOST_CHECK_EQUAL((const_mod_type::mult_add(0, 0, 0)), IntType(0));
IntType inverse;
inverse = const_mod_type::invert(INT64_C(7362947769));
BOOST_CHECK_EQUAL((const_mod_type::mult(INT64_C(7362947769), inverse)), 1);
BOOST_CHECK_EQUAL((const_mod_type::mult(INT64_C(7362947769), inverse)), IntType(1));
inverse = const_mod_type::invert(INT64_C(1263142436887493875));
BOOST_CHECK_EQUAL((const_mod_type::mult(INT64_C(1263142436887493875), inverse)), 1);
BOOST_CHECK_EQUAL((const_mod_type::mult(INT64_C(1263142436887493875), inverse)), IntType(1));
}
#endif

View File

@@ -204,6 +204,8 @@ BOOST_AUTO_TEST_CASE(test_streaming) {
BOOST_CHECK_EQUAL(dist, restored_dist);
}
void use(BOOST_RANDOM_DISTRIBUTION::result_type) {}
BOOST_AUTO_TEST_CASE(test_generation) {
boost::minstd_rand0 gen;
BOOST_RANDOM_DISTRIBUTION dist BOOST_RANDOM_TEST1_PARAMS;
@@ -211,6 +213,7 @@ BOOST_AUTO_TEST_CASE(test_generation) {
typedef BOOST_RANDOM_DISTRIBUTION::result_type result_type;
for(int i = 0; i < 10; ++i) {
result_type value = dist(gen);
use(value);
#ifdef BOOST_RANDOM_TEST1_MIN
BOOST_CHECK_GE(value, BOOST_RANDOM_TEST1_MIN);
#endif
@@ -218,6 +221,7 @@ BOOST_AUTO_TEST_CASE(test_generation) {
BOOST_CHECK_LE(value, BOOST_RANDOM_TEST1_MAX);
#endif
result_type value_two = dist_two(gen);
use(value_two);
#ifdef BOOST_RANDOM_TEST2_MIN
BOOST_CHECK_GE(value_two, BOOST_RANDOM_TEST2_MIN);
#endif
@@ -225,6 +229,7 @@ BOOST_AUTO_TEST_CASE(test_generation) {
BOOST_CHECK_LE(value_two, BOOST_RANDOM_TEST2_MAX);
#endif
result_type value_param = dist_two(gen, dist.param());
use(value_param);
#ifdef BOOST_RANDOM_TEST1_MIN
BOOST_CHECK_GE(value_param, BOOST_RANDOM_TEST1_MIN);
#endif
@@ -232,6 +237,7 @@ BOOST_AUTO_TEST_CASE(test_generation) {
BOOST_CHECK_LE(value_param, BOOST_RANDOM_TEST1_MAX);
#endif
result_type value_two_param = dist(gen, dist_two.param());
use(value_two_param);
#ifdef BOOST_RANDOM_TEST2_MIN
BOOST_CHECK_GE(value_two_param, BOOST_RANDOM_TEST2_MIN);
#endif
@@ -248,6 +254,7 @@ BOOST_AUTO_TEST_CASE(test_generation_float) {
typedef BOOST_RANDOM_DISTRIBUTION::result_type result_type;
for(int i = 0; i < 10; ++i) {
result_type value = dist(gen);
use(value);
#ifdef BOOST_RANDOM_TEST1_MIN
BOOST_CHECK_GE(value, BOOST_RANDOM_TEST1_MIN);
#endif
@@ -255,6 +262,7 @@ BOOST_AUTO_TEST_CASE(test_generation_float) {
BOOST_CHECK_LE(value, BOOST_RANDOM_TEST1_MAX);
#endif
result_type value_two = dist_two(gen);
use(value_two);
#ifdef BOOST_RANDOM_TEST2_MIN
BOOST_CHECK_GE(value_two, BOOST_RANDOM_TEST2_MIN);
#endif
@@ -262,6 +270,7 @@ BOOST_AUTO_TEST_CASE(test_generation_float) {
BOOST_CHECK_LE(value_two, BOOST_RANDOM_TEST2_MAX);
#endif
result_type value_param = dist_two(gen, dist.param());
use(value_param);
#ifdef BOOST_RANDOM_TEST1_MIN
BOOST_CHECK_GE(value_param, BOOST_RANDOM_TEST1_MIN);
#endif
@@ -269,6 +278,7 @@ BOOST_AUTO_TEST_CASE(test_generation_float) {
BOOST_CHECK_LE(value_param, BOOST_RANDOM_TEST1_MAX);
#endif
result_type value_two_param = dist(gen, dist_two.param());
use(value_two_param);
#ifdef BOOST_RANDOM_TEST2_MIN
BOOST_CHECK_GE(value_two_param, BOOST_RANDOM_TEST2_MIN);
#endif

View File

@@ -15,9 +15,9 @@
#define BOOST_RANDOM_SEED_WORDS 2
#define BOOST_RANDOM_VALIDATION_VALUE 2060321752
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 1416886025
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 776923198
#define BOOST_RANDOM_VALIDATION_VALUE 2060321752U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 1416886025U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 776923198U
#define BOOST_RANDOM_GENERATE_VALUES { 0x7AE0C087U, 0x948A8A31U, 0xBE5CCBA9U, 0x1316692CU }

View File

@@ -19,6 +19,7 @@ using boost::random::test::RandomNumberEngine;
BOOST_CONCEPT_ASSERT((RandomNumberEngine< BOOST_RANDOM_URNG >));
typedef BOOST_RANDOM_URNG::result_type result_type;
typedef boost::random::detail::seed_type<result_type>::type seed_type;
#ifdef BOOST_MSVC
#pragma warning(push)
@@ -43,7 +44,7 @@ void test_seed_conversion(URNG & urng, const T & t)
#pragma warning(pop)
#endif
void test_seed(result_type value)
void test_seed(seed_type value)
{
BOOST_RANDOM_URNG urng(value);
@@ -80,10 +81,10 @@ BOOST_AUTO_TEST_CASE(test_default_seed)
BOOST_AUTO_TEST_CASE(test_arithmetic_seed)
{
test_seed(static_cast<result_type>(0));
test_seed(static_cast<result_type>(127));
test_seed(static_cast<result_type>(539157235));
test_seed(static_cast<result_type>(~0u));
test_seed(static_cast<seed_type>(0));
test_seed(static_cast<seed_type>(127));
test_seed(static_cast<seed_type>(539157235));
test_seed(static_cast<seed_type>(~0u));
}
BOOST_AUTO_TEST_CASE(test_iterator_seed)

View File

@@ -12,6 +12,7 @@
#include <boost/random/geometric_distribution.hpp>
#include <boost/random/uniform_real.hpp>
#include <boost/math/distributions/geometric.hpp>
#include <boost/numeric/conversion/cast.hpp>
#define BOOST_RANDOM_DISTRIBUTION boost::random::geometric_distribution<>
#define BOOST_RANDOM_DISTRIBUTION_NAME geometric
@@ -20,6 +21,6 @@
#define BOOST_RANDOM_ARG1_NAME p
#define BOOST_RANDOM_ARG1_DEFAULT 0.5
#define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_real<>(0.0001, 0.9999)
#define BOOST_RANDOM_DISTRIBUTION_MAX (-5 / std::log(1-p))
#define BOOST_RANDOM_DISTRIBUTION_MAX boost::numeric_cast<int>(-5 / std::log(1-p))
#include "test_real_distribution.ipp"

View File

@@ -15,9 +15,9 @@
#define BOOST_RANDOM_SEED_WORDS 1
#define BOOST_RANDOM_VALIDATION_VALUE 1187812169
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 1081665111
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 618743552
#define BOOST_RANDOM_VALIDATION_VALUE 1187812169U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 1081665111U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 618743552U
#define BOOST_RANDOM_GENERATE_VALUES { 0x5642A47BU, 0x1F6987E8U, 0xD35860E7U, 0xC8C661ABU }

View File

@@ -17,9 +17,9 @@ typedef boost::random::independent_bits_engine<boost::random::minstd_rand0, 31,
#define BOOST_RANDOM_SEED_WORDS 1
#define BOOST_RANDOM_VALIDATION_VALUE 26292962
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 1147343739
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 1399154219
#define BOOST_RANDOM_VALIDATION_VALUE 26292962U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 1147343739U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 1399154219U
#define BOOST_RANDOM_GENERATE_VALUES { 0xC1A63AF0U, 0xD66C0614U, 0xADE076B1U, 0xC1DAE13FU }

View File

@@ -18,8 +18,8 @@ typedef boost::random::independent_bits_engine<boost::random::mt19937, 32, boost
#define BOOST_RANDOM_SEED_WORDS 624
#define BOOST_RANDOM_VALIDATION_VALUE 4123659995U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 3107690757
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 3408548740
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 3107690757U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 3408548740U
#define BOOST_RANDOM_GENERATE_VALUES { 0xD091BB5CU, 0x22AE9EF6U, 0xE7E1FAEEU, 0xD5C31F79U }

View File

@@ -17,9 +17,9 @@
#define BOOST_RANDOM_SEED_WORDS 1
// validation from the C++0x draft (n3090)
#define BOOST_RANDOM_VALIDATION_VALUE 1112339016
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 160100893
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 1692601883
#define BOOST_RANDOM_VALIDATION_VALUE 1112339016U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 160100893U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 1692601883U
#define BOOST_RANDOM_GENERATE_VALUES { 0x5D189C63U, 0xD0544F0EU, 0x15B0E78FU, 0xD814D654U }

View File

@@ -17,9 +17,9 @@
#define BOOST_RANDOM_SEED_WORDS 1
// validation by experiment from Harry Erwin's generator.h (private e-mail)
#define BOOST_RANDOM_VALIDATION_VALUE 139726
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 227233
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 163138
#define BOOST_RANDOM_VALIDATION_VALUE 139726U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 227233U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 163138U
#define BOOST_RANDOM_GENERATE_VALUES { 0x3EADAB08U, 0x85E481CEU, 0xCF84AEA5U, 0x39D4395BU }

View File

@@ -16,9 +16,9 @@ typedef boost::random::lagged_fibonacci_engine<boost::uint32_t, 24, 607, 273> la
#define BOOST_RANDOM_SEED_WORDS 607
#define BOOST_RANDOM_VALIDATION_VALUE 3543833
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 7852929
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 4372778
#define BOOST_RANDOM_VALIDATION_VALUE 3543833U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 7852929U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 4372778U
#define BOOST_RANDOM_GENERATE_VALUES { 0xF61A5094U, 0xFC4BA046U, 0xF1C41E92U, 0x3D82FE61U }

View File

@@ -17,9 +17,9 @@
#define BOOST_RANDOM_SEED_WORDS 1
// validation values from the publications
#define BOOST_RANDOM_VALIDATION_VALUE 399268537
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 2096435890
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 182651141
#define BOOST_RANDOM_VALIDATION_VALUE 399268537U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 2096435890U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 182651141U
#define BOOST_RANDOM_GENERATE_VALUES { 0x8400BC8EU, 0xF45B895FU, 0x145F0F91U, 0xE5F8F088U }

View File

@@ -17,9 +17,9 @@
#define BOOST_RANDOM_SEED_WORDS 1
// validation values from the publications
#define BOOST_RANDOM_VALIDATION_VALUE 1043618065
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 849515105
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 1263181168
#define BOOST_RANDOM_VALIDATION_VALUE 1043618065U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 849515105U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 1263181168U
#define BOOST_RANDOM_GENERATE_VALUES { 0xC00041A6U, 0xCD8358EBU, 0x430A4B7AU, 0x31B781ADU }

View File

@@ -60,7 +60,7 @@ double cdf(const piecewise_constant& dist, double x)
return dist.cdf(x);
}
bool do_test(int n, long long max) {
bool do_test(int n, int max) {
std::cout << "running piecewise_constant(p0, p1, ..., p" << n-1 << ")" << " " << max << " times: " << std::flush;
std::vector<double> weights;
@@ -93,7 +93,7 @@ bool do_test(int n, long long max) {
return result;
}
bool do_tests(int repeat, int max_n, long long trials) {
bool do_tests(int repeat, int max_n, int trials) {
boost::mt19937 gen;
boost::uniform_int<> idist(1, max_n);
int errors = 0;
@@ -128,7 +128,7 @@ bool handle_option(int& argc, char**& argv, char opt, T& value) {
int main(int argc, char** argv) {
int repeat = 10;
int max_n = 10;
long long trials = 1000000ll;
int trials = 1000000;
if(argc > 0) {
--argc;

View File

@@ -77,7 +77,7 @@ double cdf(const piecewise_linear& dist, double x)
return dist.cdf(x);
}
bool do_test(int n, long long max) {
bool do_test(int n, int max) {
std::cout << "running piecewise_linear(p0, p1, ..., p" << n-1 << ")" << " " << max << " times: " << std::flush;
std::vector<double> weights;
@@ -110,7 +110,7 @@ bool do_test(int n, long long max) {
return result;
}
bool do_tests(int repeat, int max_n, long long trials) {
bool do_tests(int repeat, int max_n, int trials) {
boost::mt19937 gen;
boost::uniform_int<> idist(2, max_n);
int errors = 0;
@@ -145,7 +145,7 @@ bool handle_option(int& argc, char**& argv, char opt, T& value) {
int main(int argc, char** argv) {
int repeat = 10;
int max_n = 10;
long long trials = 1000000ll;
int trials = 1000000;
if(argc > 0) {
--argc;

View File

@@ -17,7 +17,7 @@
#define BOOST_RANDOM_SEED_WORDS 2
// by experiment from lrand48()
#define BOOST_RANDOM_VALIDATION_VALUE 1993516219
#define BOOST_RANDOM_VALIDATION_VALUE 1993516219U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 1127873718U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 839037874U

View File

@@ -13,7 +13,7 @@
#include <boost/test/test_tools.hpp>
#include <boost/test/included/test_exec_monitor.hpp>
int test_main(int argc, char** argv) {
int test_main(int, char**) {
boost::random_device rng;
double entropy = rng.entropy();
BOOST_CHECK_GE(entropy, 0);

View File

@@ -17,9 +17,9 @@
#define BOOST_RANDOM_SEED_WORDS 24
// validation from the C++0x draft (n3090)
#define BOOST_RANDOM_VALIDATION_VALUE 9901578
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 4870344
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 3888733
#define BOOST_RANDOM_VALIDATION_VALUE 9901578U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 4870344U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 3888733U
#define BOOST_RANDOM_GENERATE_VALUES { 0x55E57B2CU, 0xF2DEF915U, 0x6D1A0CD9U, 0xCA0109F9U }

View File

@@ -16,9 +16,9 @@
#define BOOST_RANDOM_SEED_WORDS 24
// validation from the C++0x draft (n3126).
#define BOOST_RANDOM_VALIDATION_VALUE 7937952
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 836370
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 7739608
#define BOOST_RANDOM_VALIDATION_VALUE 7937952U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 836370U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 7739608U
#define BOOST_RANDOM_GENERATE_VALUES { 0x55E57B2CU, 0xF2DEF915U, 0x6D1A0CD9U, 0xCA0109F9U }

View File

@@ -16,9 +16,9 @@
#define BOOST_RANDOM_SEED_WORDS 24
// principal operation validated with CLHEP, values by experiment
#define BOOST_RANDOM_VALIDATION_VALUE 5957620
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 1848500
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 11620328
#define BOOST_RANDOM_VALIDATION_VALUE 5957620U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 1848500U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 11620328U
#define BOOST_RANDOM_GENERATE_VALUES { 0x55E57B2CU, 0xF2DEF915U, 0x6D1A0CD9U, 0xCA0109F9U }

View File

@@ -16,9 +16,9 @@
#define BOOST_RANDOM_SEED_WORDS 24
// principal operation validated with CLHEP, values by experiment
#define BOOST_RANDOM_VALIDATION_VALUE 8587295
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 6375782
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 4515722
#define BOOST_RANDOM_VALIDATION_VALUE 8587295U
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE 6375782U
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE 4515722U
#define BOOST_RANDOM_GENERATE_VALUES { 0x55E57B2CU, 0xF2DEF915U, 0x6D1A0CD9U, 0xCA0109F9U }

View File

@@ -18,7 +18,7 @@
#define BOOST_RANDOM_SEED_WORDS 48
// principal operation validated with CLHEP, values by experiment
#define BOOST_RANDOM_VALIDATION_VALUE INT64_C(141789170949364)
#define BOOST_RANDOM_VALIDATION_VALUE UINT64_C(141789170949364)
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE UINT64_C(97179253367494)
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE UINT64_C(101724473226966)

View File

@@ -18,7 +18,7 @@
#define BOOST_RANDOM_SEED_WORDS 48
// principal operation validated with CLHEP, values by experiment
#define BOOST_RANDOM_VALIDATION_VALUE INT64_C(199461971133682)
#define BOOST_RANDOM_VALIDATION_VALUE UINT64_C(199461971133682)
#define BOOST_RANDOM_SEED_SEQ_VALIDATION_VALUE UINT64_C(63570328604787)
#define BOOST_RANDOM_ITERATOR_VALIDATION_VALUE UINT64_C(40074210927900)

View File

@@ -34,6 +34,7 @@
#include <boost/exception/diagnostic_information.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/range/numeric.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <iostream>
#include <vector>
@@ -82,7 +83,7 @@ bool do_test(BOOST_RANDOM_ARG1_TYPE BOOST_RANDOM_ARG1_NAME,
#else
kolmogorov_experiment test(max);
kolmogorov_experiment test(boost::numeric_cast<int>(max));
boost::variate_generator<boost::mt19937&, BOOST_RANDOM_DISTRIBUTION > vgen(gen, dist);
double prob = test.probability(test.run(vgen, expected));