mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
workaround for no c++11 numeric_limits
This commit is contained in:
parent
ce16e24637
commit
7a1974742a
110 changed files with 727 additions and 436 deletions
|
@ -1,9 +1,9 @@
|
|||
#ifndef SPROUT_RANDOM_DETAIL_CONST_MOD_HPP
|
||||
#define SPROUT_RANDOM_DETAIL_CONST_MOD_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/limits.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
#ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
|
||||
# include <sprout/workaround/recursive_function_template.hpp>
|
||||
|
@ -41,7 +41,7 @@ namespace sprout {
|
|||
return mult_schrage_1(a, value, m / a, m % a);
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType mult_general(IntType a, IntType b) {
|
||||
return std::uintmax_t(modulus) <= std::numeric_limits<std::uintmax_t>::max() / modulus
|
||||
return std::uintmax_t(modulus) <= sprout::numeric_limits<std::uintmax_t>::max() / modulus
|
||||
? static_cast<IntType>(std::uintmax_t(a) * b % modulus)
|
||||
//: static_cast<IntType>(sprout::random::detail::mulmod(a, b, modulus)) // ???
|
||||
: (SPROUT_ASSERT_MSG(0, "Sorry, not implemented."), IntType())
|
||||
|
@ -51,7 +51,7 @@ namespace sprout {
|
|||
return a < b ? m - (b - a) : a - b;
|
||||
}
|
||||
static SPROUT_CONSTEXPR unsigned_type unsigned_m() {
|
||||
return m == 0 ? unsigned_type((std::numeric_limits<IntType>::max)()) + 1 : unsigned_type(m);
|
||||
return m == 0 ? unsigned_type((sprout::numeric_limits<IntType>::max)()) + 1 : unsigned_type(m);
|
||||
}
|
||||
#ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
|
||||
template<int D, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||
|
@ -106,10 +106,10 @@ namespace sprout {
|
|||
}
|
||||
template<int D, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||
static SPROUT_CONSTEXPR IntType invert_euclidian0_1(IntType c, IntType l1, IntType l2, IntType n) {
|
||||
return SPROUT_ASSERT_MSG(std::numeric_limits<IntType>::max() % n != n - 1, "c must be relatively prime to m."),
|
||||
return SPROUT_ASSERT_MSG(sprout::numeric_limits<IntType>::max() % n != n - 1, "c must be relatively prime to m."),
|
||||
invert_euclidian0_2<D + 1>(
|
||||
c, l1 + (std::numeric_limits<IntType>::max() / n) * l2, l2, n,
|
||||
std::numeric_limits<IntType>::max() - (std::numeric_limits<IntType>::max() / n) * n + 1
|
||||
c, l1 + (sprout::numeric_limits<IntType>::max() / n) * l2, l2, n,
|
||||
sprout::numeric_limits<IntType>::max() - (sprout::numeric_limits<IntType>::max() / n) * n + 1
|
||||
)
|
||||
;
|
||||
}
|
||||
|
@ -149,10 +149,10 @@ namespace sprout {
|
|||
return p == 0 ? l2 : invert_euclidian0_3(c, l1, l2 + (n / p) * l1, n - (n / p) * p, p);
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType invert_euclidian0_1(IntType c, IntType l1, IntType l2, IntType n) {
|
||||
return SPROUT_ASSERT_MSG(std::numeric_limits<IntType>::max() % n != n - 1, "c must be relatively prime to m."),
|
||||
return SPROUT_ASSERT_MSG(sprout::numeric_limits<IntType>::max() % n != n - 1, "c must be relatively prime to m."),
|
||||
invert_euclidian0_2(
|
||||
c, l1 + (std::numeric_limits<IntType>::max() / n) * l2, l2, n,
|
||||
std::numeric_limits<IntType>::max() - (std::numeric_limits<IntType>::max() / n) * n + 1
|
||||
c, l1 + (sprout::numeric_limits<IntType>::max() / n) * l2, l2, n,
|
||||
sprout::numeric_limits<IntType>::max() - (sprout::numeric_limits<IntType>::max() / n) * n + 1
|
||||
)
|
||||
;
|
||||
}
|
||||
|
@ -180,15 +180,15 @@ namespace sprout {
|
|||
return ((unsigned_m() - 1) & unsigned_m()) == 0 ? unsigned_type(a) * unsigned_type(x) & (unsigned_m() - 1)
|
||||
: a == 0 ? 0
|
||||
: a == 1 ? x
|
||||
: m <= std::numeric_limits<IntType>::max() / a ? mult_small(a, x)
|
||||
: std::numeric_limits<IntType>::is_signed && (m % a < m / a) ? mult_schrage(a, x)
|
||||
: m <= sprout::numeric_limits<IntType>::max() / a ? mult_small(a, x)
|
||||
: sprout::numeric_limits<IntType>::is_signed && (m % a < m / a) ? mult_schrage(a, x)
|
||||
: mult_general(a, x)
|
||||
;
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType mult_add(IntType a, IntType x, IntType c) {
|
||||
return ((unsigned_m() - 1) & unsigned_m()) == 0 ? (unsigned_type(a) * unsigned_type(x) + unsigned_type(c)) & (unsigned_m() - 1)
|
||||
: a == 0 ? c
|
||||
: m <= (std::numeric_limits<IntType>::max() - c) / a ? (a * x + c) % (m + supress_warnings)
|
||||
: m <= (sprout::numeric_limits<IntType>::max() - c) / a ? (a * x + c) % (m + supress_warnings)
|
||||
: add(mult(a, x), c)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#define SPROUT_RANDOM_DETAIL_GENERATOR_BITS_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/limits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
|
@ -12,7 +12,7 @@ namespace sprout {
|
|||
struct generator_bits {
|
||||
public:
|
||||
static SPROUT_CONSTEXPR std::size_t value() {
|
||||
return std::numeric_limits<typename URNG::result_type>::digits;
|
||||
return sprout::numeric_limits<typename URNG::result_type>::digits;
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#ifndef SPROUT_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS_HPP
|
||||
#define SPROUT_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/limits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
namespace detail {
|
||||
template<typename T, bool B = std::numeric_limits<T>::is_signed>
|
||||
template<typename T, bool B = sprout::numeric_limits<T>::is_signed>
|
||||
struct subtract {};
|
||||
template<typename T>
|
||||
struct subtract<T, false> {
|
||||
|
@ -32,7 +32,7 @@ namespace sprout {
|
|||
}
|
||||
};
|
||||
|
||||
template<typename T1, typename T2, bool B = std::numeric_limits<T2>::is_signed>
|
||||
template<typename T1, typename T2, bool B = sprout::numeric_limits<T2>::is_signed>
|
||||
struct add {};
|
||||
template<typename T1, typename T2>
|
||||
struct add<T1, T2, false> {
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/limits.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/random/detail/generator_bits.hpp>
|
||||
#include <sprout/detail/integer.hpp>
|
||||
|
@ -19,9 +19,9 @@ namespace sprout {
|
|||
typedef URNG base_type;
|
||||
typedef typename base_type::result_type base_result;
|
||||
typedef typename sprout::detail::uint_t<
|
||||
(std::numeric_limits<std::uintmax_t>::digits < std::numeric_limits<base_result>::digits)
|
||||
? std::numeric_limits<std::uintmax_t>::digits
|
||||
: std::numeric_limits<base_result>::digits
|
||||
(sprout::numeric_limits<std::uintmax_t>::digits < sprout::numeric_limits<base_result>::digits)
|
||||
? sprout::numeric_limits<std::uintmax_t>::digits
|
||||
: sprout::numeric_limits<base_result>::digits
|
||||
>::fast result_type;
|
||||
private:
|
||||
base_type rng_;
|
||||
|
@ -39,7 +39,7 @@ namespace sprout {
|
|||
return (
|
||||
result_type(2) << (
|
||||
NS_SSCRISK_CEL_OR_SPROUT::min(
|
||||
std::numeric_limits<result_type>::digits,
|
||||
sprout::numeric_limits<result_type>::digits,
|
||||
sprout::random::detail::generator_bits<base_type>::value()
|
||||
) - 1
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue