vSMC
vSMC: Scalable Monte Carlo
u01.hpp
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/rng/u01.hpp
3 //----------------------------------------------------------------------------
4 // vSMC: Scalable Monte Carlo
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013-2015, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef VSMC_RNG_U01_HPP
33 #define VSMC_RNG_U01_HPP
34 
36 #include <vsmc/rngc/u01.h>
37 
38 #define VSMC_DEFINE_RNG_U01_IMPL( \
39  UBits, FBits, RealType, Left, Right, left, right) \
40  template <> \
41  class U01Impl<sizeof(std::uint##UBits##_t), sizeof(RealType), Left, \
42  Right> \
43  { \
44  public: \
45  template <typename UIntType> \
46  static RealType eval(UIntType u) \
47  { \
48  return ::vsmc_u01_##left##_##right##_u##UBits##_f##FBits( \
49  static_cast<uint##UBits##_t>(u)); \
50  } \
51  }; // class U01Impl
52 
53 #define VSMC_DEFINE_RNG_U01(UBits, FBits, RealType) \
54  VSMC_DEFINE_RNG_U01_IMPL( \
55  UBits, FBits, RealType, Closed, Closed, closed, closed) \
56  VSMC_DEFINE_RNG_U01_IMPL( \
57  UBits, FBits, RealType, Closed, Open, closed, open) \
58  VSMC_DEFINE_RNG_U01_IMPL( \
59  UBits, FBits, RealType, Open, Closed, open, closed) \
60  VSMC_DEFINE_RNG_U01_IMPL(UBits, FBits, RealType, Open, Open, open, open)
61 
62 namespace vsmc
63 {
64 
65 namespace internal
66 {
67 
68 template <std::size_t, std::size_t, typename, typename>
69 class U01Impl;
70 
71 VSMC_DEFINE_RNG_U01(32, 32, float)
72 VSMC_DEFINE_RNG_U01(32, 64, double)
73 VSMC_DEFINE_RNG_U01(64, 32, float)
74 VSMC_DEFINE_RNG_U01(64, 64, double)
75 
76 } // namespace vsmc::internal
77 
78 template <typename UIntType, typename RealType, typename Left, typename Right>
79 class U01
80  : public internal::U01Impl<sizeof(UIntType), sizeof(RealType), Left, Right>
81 {
82 }; // class U01
83 
84 } // namespace vsmc
85 
86 #endif // VSMC_RNG_U01_HPP
Definition: monitor.hpp:49
#define VSMC_DEFINE_RNG_U01(UBits, FBits, RealType)
Definition: u01.hpp:53