mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
workaround for Clang: uniform_int_ditribution, uniform_real_distribution
This commit is contained in:
parent
0aeaf19c47
commit
3e97ddd286
2 changed files with 622 additions and 67 deletions
|
@ -21,6 +21,399 @@ namespace sprout {
|
||||||
Engine engine;
|
Engine engine;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
|
||||||
|
template<int D = 16, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int(Engine const& eng, T min_value, T max_value, std::true_type);
|
||||||
|
template<int D = 16, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int(Engine const& eng, T min_value, T max_value, std::true_type);
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_3_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, BaseUnsigned bucket_size
|
||||||
|
);
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_3_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, BaseUnsigned bucket_size
|
||||||
|
);
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_3_1_1(
|
||||||
|
Engine const& eng, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, BaseUnsigned bucket_size, BaseUnsigned result
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef T result_type;
|
||||||
|
return result <= static_cast<BaseUnsigned>(range)
|
||||||
|
? sprout::random::detail::generate_uniform_int_result<T, Engine>{
|
||||||
|
sprout::random::detail::add<BaseUnsigned, result_type>()(result, min_value),
|
||||||
|
eng
|
||||||
|
}
|
||||||
|
: sprout::random::detail::generate_uniform_int_true_3_1<D + 1>(
|
||||||
|
eng(), min_value, range,
|
||||||
|
bmin, brange, bucket_size
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_3_1_1(
|
||||||
|
Engine const&, T, RangeType,
|
||||||
|
BaseResult, BaseUnsigned, BaseUnsigned, BaseUnsigned
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE_DECL(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_3_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, BaseUnsigned bucket_size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::random::detail::generate_uniform_int_true_3_1_1<D + 1>(
|
||||||
|
rnd.engine(), min_value, range,
|
||||||
|
bmin, brange, bucket_size,
|
||||||
|
sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin) / bucket_size
|
||||||
|
);
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_3_1(
|
||||||
|
sprout::random::random_result<Engine> const&, T, RangeType,
|
||||||
|
BaseResult, BaseUnsigned, BaseUnsigned
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_3(
|
||||||
|
Engine const& eng, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::random::detail::generate_uniform_int_true_3_1<D + 1>(
|
||||||
|
eng(), min_value, range,
|
||||||
|
bmin, brange,
|
||||||
|
brange == std::numeric_limits<BaseUnsigned>::max()
|
||||||
|
? brange / (static_cast<BaseUnsigned>(range) + 1) + (
|
||||||
|
brange % (static_cast<BaseUnsigned>(range) + 1) == static_cast<BaseUnsigned>(range) ? 1 : 0
|
||||||
|
)
|
||||||
|
: (brange + 1) / (static_cast<BaseUnsigned>(range) + 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_3(
|
||||||
|
Engine const&, T, RangeType,
|
||||||
|
BaseResult, BaseUnsigned
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2(
|
||||||
|
Engine const& eng, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange
|
||||||
|
);
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2(
|
||||||
|
Engine const& eng, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange
|
||||||
|
);
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_4(
|
||||||
|
Engine const& eng, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, RangeType result, RangeType result_increment
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef T result_type;
|
||||||
|
return result < result_increment || result > range
|
||||||
|
? sprout::random::detail::generate_uniform_int_true_2<D + 1>(eng, min_value, range, bmin, brange)
|
||||||
|
: sprout::random::detail::generate_uniform_int_result<T, Engine>{
|
||||||
|
random::detail::add<RangeType, result_type>()(result, min_value),
|
||||||
|
eng
|
||||||
|
}
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_4(
|
||||||
|
Engine const&, T, RangeType,
|
||||||
|
BaseResult, BaseUnsigned, RangeType, RangeType
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_3(
|
||||||
|
Engine const& eng, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, RangeType result, RangeType mult, RangeType result_increment
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return std::numeric_limits<RangeType>::max() / mult < result_increment
|
||||||
|
? sprout::random::detail::generate_uniform_int_true_2<D + 1>(eng, min_value, range, bmin, brange)
|
||||||
|
: sprout::random::detail::generate_uniform_int_true_2_4<D + 1>(
|
||||||
|
eng, min_value, range,
|
||||||
|
bmin, brange, result + (result_increment * mult), result_increment * mult
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_3(
|
||||||
|
Engine const&, T, RangeType,
|
||||||
|
BaseResult, BaseUnsigned, RangeType, RangeType, RangeType
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, typename Result, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_2(
|
||||||
|
Engine const&, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, RangeType result, RangeType mult, Result const& result_increment_base
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::random::detail::generate_uniform_int_true_2_3<D + 1>(
|
||||||
|
result_increment_base.engine, min_value, range,
|
||||||
|
bmin, brange, result, mult, result_increment_base.result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, typename Result, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_2(
|
||||||
|
Engine const&, T, RangeType,
|
||||||
|
BaseResult, BaseUnsigned, RangeType, RangeType, Result const&
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_1(
|
||||||
|
Engine const& eng, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, RangeType limit,
|
||||||
|
RangeType result = RangeType(0), RangeType mult = RangeType(1)
|
||||||
|
);
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_1(
|
||||||
|
Engine const& eng, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, RangeType limit,
|
||||||
|
RangeType result = RangeType(0), RangeType mult = RangeType(1)
|
||||||
|
);
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_1_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, RangeType limit, RangeType result, RangeType mult
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return mult * RangeType(brange) == range - mult + 1
|
||||||
|
? sprout::random::detail::generate_uniform_int_result<T, Engine>{
|
||||||
|
static_cast<T>(
|
||||||
|
result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin) * mult)
|
||||||
|
),
|
||||||
|
rnd.engine()
|
||||||
|
}
|
||||||
|
: sprout::random::detail::generate_uniform_int_true_2_1<D + 1>(
|
||||||
|
rnd.engine(), min_value, range,
|
||||||
|
bmin, brange, limit,
|
||||||
|
result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin) * mult),
|
||||||
|
mult * (RangeType(brange) + RangeType(1))
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_1_1(
|
||||||
|
sprout::random::random_result<Engine> const&, T, RangeType,
|
||||||
|
BaseResult, BaseUnsigned, RangeType, RangeType, RangeType
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE_DECL(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_1(
|
||||||
|
Engine const& eng, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange, RangeType limit,
|
||||||
|
RangeType result, RangeType mult
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return mult <= limit
|
||||||
|
? sprout::random::detail::generate_uniform_int_true_2_1_1<D + 1>(
|
||||||
|
eng(), min_value, range,
|
||||||
|
bmin, brange, limit,
|
||||||
|
result, mult
|
||||||
|
)
|
||||||
|
: sprout::random::detail::generate_uniform_int_true_2_2<D + 1>(
|
||||||
|
eng, min_value, range,
|
||||||
|
bmin, brange,
|
||||||
|
result, mult,
|
||||||
|
sprout::random::detail::generate_uniform_int<D + 1>(
|
||||||
|
eng,
|
||||||
|
static_cast<RangeType>(0),
|
||||||
|
static_cast<RangeType>(range / mult),
|
||||||
|
std::true_type()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2_1(
|
||||||
|
Engine const&, T, RangeType,
|
||||||
|
BaseResult, BaseUnsigned, RangeType,
|
||||||
|
RangeType, RangeType
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE_DECL(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2(
|
||||||
|
Engine const& eng, T min_value, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::random::detail::generate_uniform_int_true_2_1<D + 1>(
|
||||||
|
eng, min_value, range,
|
||||||
|
bmin, brange,
|
||||||
|
range == std::numeric_limits<RangeType>::max()
|
||||||
|
? range / (RangeType(brange) + 1) + (
|
||||||
|
range % (RangeType(brange) + 1) == RangeType(brange) ? 1 : 0
|
||||||
|
)
|
||||||
|
: (range + 1) / (RangeType(brange) + 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_2(
|
||||||
|
Engine const&, T, RangeType,
|
||||||
|
BaseResult, BaseUnsigned
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename BaseResult, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_1_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd, T min_value, BaseResult bmin
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef T result_type;
|
||||||
|
typedef typename std::make_unsigned<BaseResult>::type base_unsigned;
|
||||||
|
return sprout::random::detail::generate_uniform_int_result<T, Engine>{
|
||||||
|
sprout::random::detail::add<base_unsigned, result_type>()(
|
||||||
|
base_unsigned(sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin)),
|
||||||
|
min_value
|
||||||
|
),
|
||||||
|
rnd.engine()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename BaseResult, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_1_1(
|
||||||
|
sprout::random::random_result<Engine> const&, T, BaseResult
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_1(
|
||||||
|
Engine const& eng, T min_value, T, RangeType range,
|
||||||
|
BaseResult bmin, BaseUnsigned brange
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return range == 0 ? sprout::random::detail::generate_uniform_int_result<T, Engine>{min_value, eng}
|
||||||
|
: brange == range ? sprout::random::detail::generate_uniform_int_true_1_1<D + 1>(eng(), min_value, bmin)
|
||||||
|
: brange < range ? sprout::random::detail::generate_uniform_int_true_2<D + 1>(eng, min_value, range, bmin, brange)
|
||||||
|
: sprout::random::detail::generate_uniform_int_true_3<D + 1>(eng, min_value, range, bmin, brange)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_true_1(
|
||||||
|
Engine const&, T, T, RangeType,
|
||||||
|
BaseResult, BaseUnsigned
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE_DECL(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int(
|
||||||
|
Engine const& eng, T min_value, T max_value, std::true_type
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef T result_type;
|
||||||
|
typedef typename std::make_unsigned<T>::type range_type;
|
||||||
|
typedef typename Engine::result_type base_result;
|
||||||
|
typedef typename std::make_unsigned<base_result>::type base_unsigned;
|
||||||
|
return sprout::random::detail::generate_uniform_int_true_1<D + 1>(
|
||||||
|
eng, min_value, max_value,
|
||||||
|
range_type(sprout::random::detail::subtract<result_type>()(max_value, min_value)),
|
||||||
|
base_result(eng.min()),
|
||||||
|
base_unsigned(sprout::random::detail::subtract<base_result>()(eng.max(), eng.min()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int(
|
||||||
|
Engine const&, T, T, std::true_type
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename Result, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_false_1(Result const& rnd) {
|
||||||
|
return sprout::random::detail::generate_uniform_int_result<T, Engine>{
|
||||||
|
rnd.result, rnd.engine.base()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, typename Result, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int_false_1(Result const& rnd) {
|
||||||
|
return sprout::random::detail::generate_uniform_int_result<T, Engine>{
|
||||||
|
rnd.result, rnd.engine.base()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int(
|
||||||
|
Engine const& eng, T min_value, T max_value, std::false_type
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::random::detail::generate_uniform_int_false_1<D + 1, Engine, T>(
|
||||||
|
sprout::random::detail::generate_uniform_int<D + 1>(
|
||||||
|
sprout::random::detail::uniform_int_float<Engine>(eng),
|
||||||
|
min_value, max_value,
|
||||||
|
std::true_type()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
template<int D = 16, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
|
generate_uniform_int(
|
||||||
|
Engine const&, T, T, std::false_type
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
#else
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
generate_uniform_int(Engine const& eng, T min_value, T max_value, std::true_type);
|
generate_uniform_int(Engine const& eng, T min_value, T max_value, std::true_type);
|
||||||
|
@ -43,7 +436,7 @@ namespace sprout {
|
||||||
sprout::random::detail::add<BaseUnsigned, result_type>()(result, min_value),
|
sprout::random::detail::add<BaseUnsigned, result_type>()(result, min_value),
|
||||||
eng
|
eng
|
||||||
}
|
}
|
||||||
: generate_uniform_int_true_3_1(
|
: sprout::random::detail::generate_uniform_int_true_3_1(
|
||||||
eng(), min_value, range,
|
eng(), min_value, range,
|
||||||
bmin, brange, bucket_size
|
bmin, brange, bucket_size
|
||||||
)
|
)
|
||||||
|
@ -110,7 +503,7 @@ namespace sprout {
|
||||||
{
|
{
|
||||||
return std::numeric_limits<RangeType>::max() / mult < result_increment
|
return std::numeric_limits<RangeType>::max() / mult < result_increment
|
||||||
? sprout::random::detail::generate_uniform_int_true_2(eng, min_value, range, bmin, brange)
|
? sprout::random::detail::generate_uniform_int_true_2(eng, min_value, range, bmin, brange)
|
||||||
: generate_uniform_int_true_2_4(
|
: sprout::random::detail::generate_uniform_int_true_2_4(
|
||||||
eng, min_value, range,
|
eng, min_value, range,
|
||||||
bmin, brange, result + (result_increment * mult), result_increment * mult
|
bmin, brange, result + (result_increment * mult), result_increment * mult
|
||||||
)
|
)
|
||||||
|
@ -166,7 +559,7 @@ namespace sprout {
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return mult <= limit
|
return mult <= limit
|
||||||
? generate_uniform_int_true_2_1_1(
|
? sprout::random::detail::generate_uniform_int_true_2_1_1(
|
||||||
eng(), min_value, range,
|
eng(), min_value, range,
|
||||||
bmin, brange, limit,
|
bmin, brange, limit,
|
||||||
result, mult
|
result, mult
|
||||||
|
@ -260,7 +653,7 @@ namespace sprout {
|
||||||
Engine const& eng, T min_value, T max_value, std::false_type
|
Engine const& eng, T min_value, T max_value, std::false_type
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return generate_uniform_int_false_1<Engine, T>(
|
return sprout::random::detail::generate_uniform_int_false_1<Engine, T>(
|
||||||
sprout::random::detail::generate_uniform_int(
|
sprout::random::detail::generate_uniform_int(
|
||||||
sprout::random::detail::uniform_int_float<Engine>(eng),
|
sprout::random::detail::uniform_int_float<Engine>(eng),
|
||||||
min_value, max_value,
|
min_value, max_value,
|
||||||
|
@ -268,6 +661,7 @@ namespace sprout {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result<T, Engine>
|
||||||
generate_uniform_int(
|
generate_uniform_int(
|
||||||
|
|
|
@ -19,17 +19,187 @@ namespace sprout {
|
||||||
Engine engine;
|
Engine engine;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Engine, typename T>
|
#ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real_false_1(
|
template<int D = 16, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_1(
|
||||||
sprout::random::random_result<Engine> const& rnd,
|
sprout::random::random_result<Engine> const& rnd,
|
||||||
T min_value,
|
T min_value, T max_value
|
||||||
T max_value
|
);
|
||||||
|
template<int D = 16, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd,
|
||||||
|
T min_value, T max_value
|
||||||
|
);
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_3(
|
||||||
|
Engine const& eng,
|
||||||
|
T min_value, T max_value,
|
||||||
|
T result
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return result < max_value
|
||||||
|
? sprout::random::detail::generate_uniform_real_result<T, Engine>{result, eng}
|
||||||
|
: sprout::random::detail::generate_uniform_real_false_1<D + 1>(eng(), min_value, max_value)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_3(
|
||||||
|
Engine const&,
|
||||||
|
T, T,
|
||||||
|
T
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_2(
|
||||||
|
Engine const& eng,
|
||||||
|
T min_value, T max_value,
|
||||||
|
T numerator, T divisor
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return SPROUT_ASSERT(divisor > 0), SPROUT_ASSERT(numerator >= 0 && numerator <= divisor),
|
||||||
|
sprout::random::detail::generate_uniform_real_false_3<D + 1>(
|
||||||
|
eng,
|
||||||
|
min_value, max_value,
|
||||||
|
numerator / divisor * (max_value - min_value) + min_value
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_2(
|
||||||
|
Engine const&,
|
||||||
|
T, T,
|
||||||
|
T, T
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE_DECL(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd,
|
||||||
|
T min_value, T max_value
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::random::detail::generate_uniform_real_false_2<D + 1>(
|
||||||
|
rnd.engine(),
|
||||||
|
min_value, max_value,
|
||||||
|
static_cast<T>(rnd.result() - rnd.engine().min()), static_cast<T>(rnd.engine().max() - rnd.engine().min())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_1(
|
||||||
|
sprout::random::random_result<Engine> const&,
|
||||||
|
T, T
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D = 16, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd,
|
||||||
|
T min_value, T max_value
|
||||||
|
);
|
||||||
|
template<int D = 16, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd,
|
||||||
|
T min_value, T max_value
|
||||||
|
);
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_3(
|
||||||
|
Engine const& eng,
|
||||||
|
T min_value, T max_value,
|
||||||
|
T result
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return result < max_value
|
||||||
|
? sprout::random::detail::generate_uniform_real_result<T, Engine>{result, eng}
|
||||||
|
: sprout::random::detail::generate_uniform_real_true_1<D + 1>(eng(), min_value, max_value)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_3(
|
||||||
|
Engine const&,
|
||||||
|
T, T,
|
||||||
|
T
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_2(
|
||||||
|
Engine const& eng,
|
||||||
|
T min_value, T max_value,
|
||||||
|
T numerator, T divisor
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return SPROUT_ASSERT(divisor > 0), SPROUT_ASSERT(numerator >= 0 && numerator <= divisor),
|
||||||
|
sprout::random::detail::generate_uniform_real_true_3<D + 1>(
|
||||||
|
eng,
|
||||||
|
min_value, max_value,
|
||||||
|
numerator / divisor * (max_value - min_value) + min_value
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_2(
|
||||||
|
Engine const&,
|
||||||
|
T, T,
|
||||||
|
T, T
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE_DECL(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd,
|
||||||
|
T min_value, T max_value
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef typename Engine::result_type base_result;
|
||||||
|
return sprout::random::detail::generate_uniform_real_true_2<D + 1>(
|
||||||
|
rnd.engine(),
|
||||||
|
min_value, max_value,
|
||||||
|
static_cast<T>(sprout::random::detail::subtract<base_result>()(rnd.result(), rnd.engine().min())),
|
||||||
|
static_cast<T>(sprout::random::detail::subtract<base_result>()(rnd.engine().max(), rnd.engine().min())) + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
template<int D, typename Engine, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_1(
|
||||||
|
sprout::random::random_result<Engine> const&,
|
||||||
|
T, T
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::throw_recursive_function_template_instantiation_exeeded();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
template<typename Engine, typename T>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_1(
|
||||||
|
sprout::random::random_result<Engine> const& rnd,
|
||||||
|
T min_value, T max_value
|
||||||
);
|
);
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real_false_3(
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_3(
|
||||||
Engine const& eng,
|
Engine const& eng,
|
||||||
T min_value,
|
T min_value, T max_value,
|
||||||
T max_value,
|
|
||||||
T result
|
T result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -39,63 +209,45 @@ namespace sprout {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real_false_2(
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_2(
|
||||||
Engine const& eng,
|
Engine const& eng,
|
||||||
T min_value,
|
T min_value, T max_value,
|
||||||
T max_value,
|
T numerator, T divisor
|
||||||
T numerator,
|
|
||||||
T divisor
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return SPROUT_ASSERT(divisor > 0), SPROUT_ASSERT(numerator >= 0 && numerator <= divisor),
|
return SPROUT_ASSERT(divisor > 0), SPROUT_ASSERT(numerator >= 0 && numerator <= divisor),
|
||||||
sprout::random::detail::generate_uniform_real_false_3(
|
sprout::random::detail::generate_uniform_real_false_3(
|
||||||
eng,
|
eng,
|
||||||
min_value,
|
min_value, max_value,
|
||||||
max_value,
|
|
||||||
numerator / divisor * (max_value - min_value) + min_value
|
numerator / divisor * (max_value - min_value) + min_value
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real_false_1(
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_false_1(
|
||||||
sprout::random::random_result<Engine> const& rnd,
|
sprout::random::random_result<Engine> const& rnd,
|
||||||
T min_value,
|
T min_value, T max_value
|
||||||
T max_value
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return sprout::random::detail::generate_uniform_real_false_2(
|
return sprout::random::detail::generate_uniform_real_false_2(
|
||||||
rnd.engine(),
|
rnd.engine(),
|
||||||
min_value,
|
min_value, max_value,
|
||||||
max_value,
|
static_cast<T>(rnd.result() - rnd.engine().min()), static_cast<T>(rnd.engine().max() - rnd.engine().min())
|
||||||
static_cast<T>(rnd.result() - rnd.engine().min()),
|
|
||||||
static_cast<T>(rnd.engine().max() - rnd.engine().min())
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real(
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
Engine const& eng,
|
generate_uniform_real_true_1(
|
||||||
T min_value,
|
|
||||||
T max_value,
|
|
||||||
std::false_type
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return sprout::random::detail::generate_uniform_real_false_1(
|
|
||||||
eng(),
|
|
||||||
min_value,
|
|
||||||
max_value
|
|
||||||
);
|
|
||||||
}
|
|
||||||
template<typename Engine, typename T>
|
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real_true_1(
|
|
||||||
sprout::random::random_result<Engine> const& rnd,
|
sprout::random::random_result<Engine> const& rnd,
|
||||||
T min_value,
|
T min_value, T max_value
|
||||||
T max_value
|
|
||||||
);
|
);
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real_true_3(
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_3(
|
||||||
Engine const& eng,
|
Engine const& eng,
|
||||||
T min_value,
|
T min_value, T max_value,
|
||||||
T max_value,
|
|
||||||
T result
|
T result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -105,64 +257,73 @@ namespace sprout {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real_true_2(
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_2(
|
||||||
Engine const& eng,
|
Engine const& eng,
|
||||||
T min_value,
|
T min_value, T max_value,
|
||||||
T max_value,
|
T numerator, T divisor
|
||||||
T numerator,
|
|
||||||
T divisor
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return SPROUT_ASSERT(divisor > 0), SPROUT_ASSERT(numerator >= 0 && numerator <= divisor),
|
return SPROUT_ASSERT(divisor > 0), SPROUT_ASSERT(numerator >= 0 && numerator <= divisor),
|
||||||
sprout::random::detail::generate_uniform_real_true_3(
|
sprout::random::detail::generate_uniform_real_true_3(
|
||||||
eng,
|
eng,
|
||||||
min_value,
|
min_value, max_value,
|
||||||
max_value,
|
|
||||||
numerator / divisor * (max_value - min_value) + min_value
|
numerator / divisor * (max_value - min_value) + min_value
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real_true_1(
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real_true_1(
|
||||||
sprout::random::random_result<Engine> const& rnd,
|
sprout::random::random_result<Engine> const& rnd,
|
||||||
T min_value,
|
T min_value, T max_value
|
||||||
T max_value
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
typedef typename Engine::result_type base_result;
|
typedef typename Engine::result_type base_result;
|
||||||
return sprout::random::detail::generate_uniform_real_true_2(
|
return sprout::random::detail::generate_uniform_real_true_2(
|
||||||
rnd.engine(),
|
rnd.engine(),
|
||||||
min_value,
|
min_value, max_value,
|
||||||
max_value,
|
|
||||||
static_cast<T>(sprout::random::detail::subtract<base_result>()(rnd.result(), rnd.engine().min())),
|
static_cast<T>(sprout::random::detail::subtract<base_result>()(rnd.result(), rnd.engine().min())),
|
||||||
static_cast<T>(sprout::random::detail::subtract<base_result>()(rnd.engine().max(), rnd.engine().min())) + 1
|
static_cast<T>(sprout::random::detail::subtract<base_result>()(rnd.engine().max(), rnd.engine().min())) + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real(
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real(
|
||||||
Engine const& eng,
|
Engine const& eng,
|
||||||
T min_value,
|
T min_value, T max_value,
|
||||||
T max_value,
|
std::false_type
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::random::detail::generate_uniform_real_false_1(
|
||||||
|
eng(),
|
||||||
|
min_value, max_value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
template<typename Engine, typename T>
|
||||||
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real(
|
||||||
|
Engine const& eng,
|
||||||
|
T min_value, T max_value,
|
||||||
std::true_type
|
std::true_type
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return sprout::random::detail::generate_uniform_real_true_1(
|
return sprout::random::detail::generate_uniform_real_true_1(
|
||||||
eng(),
|
eng(),
|
||||||
min_value,
|
min_value, max_value
|
||||||
max_value
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
template<typename Engine, typename T>
|
template<typename Engine, typename T>
|
||||||
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine> generate_uniform_real(
|
SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_real_result<T, Engine>
|
||||||
|
generate_uniform_real(
|
||||||
Engine const& eng,
|
Engine const& eng,
|
||||||
T min_value,
|
T min_value, T max_value
|
||||||
T max_value
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return sprout::random::detail::generate_uniform_real(
|
return sprout::random::detail::generate_uniform_real(
|
||||||
eng,
|
eng,
|
||||||
min_value,
|
min_value, max_value,
|
||||||
max_value,
|
|
||||||
std::is_integral<typename Engine::result_type>()
|
std::is_integral<typename Engine::result_type>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue