32 #ifndef VSMC_RNG_UNIFORM_REAL_DISTRIBUTION_HPP
33 #define VSMC_RNG_UNIFORM_REAL_DISTRIBUTION_HPP
38 #define VSMC_RUNTIME_ASSERT_RNG_UNIFORM_REAL_DISTRIBUTION_PARAM_CHECK(a, b) \
39 VSMC_RUNTIME_ASSERT((a <= b), \
40 ("**UniformRealDistribution** CONSTRUCTED WITH INVALID " \
41 "MINIMUM AND MAXIMUM PARAMTER VALUES"))
43 #define VSMC_RUNTIME_ASSERT_RNG_UNIFORM_REAL_DISTRIBUTION_ENG_MIN(eng_min) \
44 VSMC_RUNTIME_ASSERT((eng_min == 0), \
45 ("**UniformRealDistribution::operator()** " \
46 "ENGINE MEMBER FUNCTION min() RETURN A VALUE OTHER THAN ZERO"))
48 #define VSMC_RUNTIME_ASSERT_RNG_UNIFORM_REAL_DISTRIBUTION_ENG_MAX(eng_max) \
49 VSMC_RUNTIME_ASSERT((eng_max == uint32_t_max_ || eng_max == uint64_t_max_),\
50 ("**UniformRealDistribution::operator()** " \
51 "ENGINE MEMBER FUNCTION max() RETURN A VALUE OTHER THAN " \
52 "THE MAXIMUM OF uint32_t OR uint64_t"))
58 template <u
int64_t, u
int64_t>
63 static_cast<uint64_t>(static_cast<uint32_t>(~(static_cast<uint32_t>(0))))>
68 static_cast<uint64_t>(~(static_cast<uint64_t>(0)))>
71 template <
typename FPType,
typename Left,
typename Right,
typename Eng,
bool>
74 static VSMC_CONSTEXPR const uint64_t uint32_t_max_ =
static_cast<uint64_t
>(
75 static_cast<uint32_t
>(~(
static_cast<uint32_t
>(0))));
77 static VSMC_CONSTEXPR const uint64_t uint64_t_max_ =
static_cast<uint64_t
>(
78 ~(
static_cast<uint64_t
>(0)));
84 static const uint64_t eng_max =
static_cast<uint64_t
>(
91 if (eng_max == uint32_t_max_)
93 static_cast<uint32_t>(eng()));
95 if (eng_max == uint64_t_max_)
97 static_cast<uint64_t>(eng()));
103 #if VSMC_HAS_CXX11_CONSTEXPR
104 template <
typename FPType,
typename Left,
typename Right,
typename Eng>
115 static_cast<eng_uint_t>(eng()));
170 template <
typename FPType = double,
171 typename Left = Closed,
typename Right = Open,
172 bool MinMaxIsConstexpr =
false>
189 result_type
a ()
const {
return a_;}
190 result_type
b ()
const {
return b_;}
195 if (param1.a_ < param2.a_ || param1.a_ > param2.a_)
197 if (param1.b_ < param2.b_ || param1.b_ > param2.b_)
204 {
return !(param1 == param2);}
206 template <
typename CharT,
typename Traits>
207 friend inline std::basic_ostream<CharT, Traits> &
operator<< (
213 os << param.a_ <<
' ' << param.b_;
218 template <
typename CharT,
typename Traits>
219 friend inline std::basic_istream<CharT, Traits> &
operator>> (
235 is.setstate(std::ios_base::failbit);
253 a_(param.
a()), b_(param.
b())
266 result_type
a ()
const {
return a_;}
267 result_type
b ()
const {
return b_;}
280 template <
typename Eng>
284 FPType, Left, Right, Eng, MinMaxIsConstexpr
285 >::uint2fp(eng) * (b_ - a_) + a_;
290 FPType, Left, Right, MinMaxIsConstexpr> &runif1,
292 FPType, Left, Right, MinMaxIsConstexpr> &runif2)
294 if (runif1.a_ < runif2.a_ || runif1.a_ > runif1.a_)
296 if (runif1.b_ < runif2.b_ || runif1.b_ > runif1.b_)
303 FPType, Left, Right, MinMaxIsConstexpr> &runif1,
305 FPType, Left, Right, MinMaxIsConstexpr> &runif2)
306 {
return !(runif1 == runif2);}
308 template <
typename CharT,
typename Traits>
309 friend inline std::basic_ostream<CharT, Traits> &
operator<< (
310 std::basic_ostream<CharT, Traits> &os,
312 FPType, Left, Right, MinMaxIsConstexpr> &runif)
317 os << runif.a_ <<
' ' << runif.b_;
322 template <
typename CharT,
typename Traits>
323 friend inline std::basic_istream<CharT, Traits> &
operator>> (
324 std::basic_istream<CharT, Traits> &is,
326 FPType, Left, Right, MinMaxIsConstexpr> &runif)
340 is.setstate(std::ios_base::failbit);
355 #endif // VSMC_RNG_UNIFORM_REAL_DISTRIBUTION_HPP
#define VSMC_CONSTEXPR
constexpr
#define VSMC_MNE
Avoid MSVC stupid behavior: MNE = Macro No Expansion.