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,2014, 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/rng/u01.h>
37 
38 #define VSMC_DEFINE_RNG_U01(FPType, Left, Right, left, right, UBits, FBits) \
39 template <> struct U01<Left, Right, uint##UBits##_t, FPType> \
40 { \
41  FPType operator() (uint##UBits##_t u) const \
42  {return ::u01_##left##_##right##_##UBits##_##FBits(u);} \
43  \
44  static FPType uint2fp (uint##UBits##_t u) \
45  {return ::u01_##left##_##right##_##UBits##_##FBits(u);} \
46 };
47 
48 namespace vsmc {
49 
52 struct Open {};
53 
56 struct Closed {};
57 
58 template <typename, typename, typename, typename> struct U01;
59 
62 VSMC_DEFINE_RNG_U01(float, Closed, Closed, closed, closed, 32, 24)
63 
64 VSMC_DEFINE_RNG_U01(float, Closed, Open, closed, open, 32, 24)
67 
70 VSMC_DEFINE_RNG_U01(float, Open, Closed, open, closed, 32, 24)
71 
74 VSMC_DEFINE_RNG_U01(float, Open, Open, open, open, 32, 24)
75 
78 VSMC_DEFINE_RNG_U01(double, Closed, Closed, closed, closed, 32, 53)
79 
82 VSMC_DEFINE_RNG_U01(double, Closed, Open, closed, open, 32, 53)
83 
86 VSMC_DEFINE_RNG_U01(double, Open, Closed, open, closed, 32, 53)
87 
90 VSMC_DEFINE_RNG_U01(double, Open, Open, open, open, 32, 53)
91 
94 VSMC_DEFINE_RNG_U01(float, Closed, Closed, closed, closed, 64, 24)
95 
98 VSMC_DEFINE_RNG_U01(float, Closed, Open, closed, open, 64, 24)
99 
102 VSMC_DEFINE_RNG_U01(float, Open, Closed, open, closed, 64, 24)
103 
106 VSMC_DEFINE_RNG_U01(float, Open, Open, open, open, 64, 24)
107 
110 VSMC_DEFINE_RNG_U01(double, Closed, Closed, closed, closed, 64, 53)
111 
114 VSMC_DEFINE_RNG_U01(double, Closed, Open, closed, open, 64, 53)
115 
118 VSMC_DEFINE_RNG_U01(double, Open, Closed, open, closed, 64, 53)
119 
122 VSMC_DEFINE_RNG_U01(double, Open, Open, open, open, 64, 53)
123 
124 } // namespace vsmc
125 
126 #endif // VSMC_RNG_U01_HPP
Definition: adapter.hpp:37
#define VSMC_DEFINE_RNG_U01(FPType, Left, Right, left, right, UBits, FBits)
Definition: u01.hpp:38
Parameter type for closed interval.
Definition: u01.hpp:56
Parameter type for open interval.
Definition: u01.hpp:52