vSMC
vSMC: Scalable Monte Carlo
u01.h
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/rngc/u01.h
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_RNGC_U01_H
33 #define VSMC_RNGC_U01_H
34 
35 #include <vsmc/internal/config.h>
36 
37 #ifdef VSMC_OPENCL
38 #define VSMC_RNGC_U01_31F (1.0f / 2147483648.0f)
39 #define VSMC_RNGC_U01_24F (1.0f / 16777216.0f)
40 #define VSMC_RNGC_U01_23F (1.0f / 8388608.0f)
41 #define VSMC_RNGC_U01_33D (1.0 / 8589934592.0)
42 #define VSMC_RNGC_U01_32D (1.0 / 4294967296.0)
43 #define VSMC_RNGC_U01_63D (1.0 / 9223372036854775808.0)
44 #define VSMC_RNGC_U01_53D (1.0 / 9007199254740992.0)
45 #define VSMC_RNGC_U01_52D (1.0 / 4503599627370496.0)
46 #else // VSMC_OPENCL
47 static const float VSMC_RNGC_U01_31F = 1.0f / 2147483648.0f;
48 static const float VSMC_RNGC_U01_24F = 1.0f / 16777216.0f;
49 static const float VSMC_RNGC_U01_23F = 1.0f / 8388608.0f;
50 static const double VSMC_RNGC_U01_33D = 1.0 / 8589934592.0;
51 static const double VSMC_RNGC_U01_32D = 1.0 / 4294967296.0;
52 static const double VSMC_RNGC_U01_63D = 1.0 / 9223372036854775808.0;
53 static const double VSMC_RNGC_U01_53D = 1.0 / 9007199254740992.0;
54 static const double VSMC_RNGC_U01_52D = 1.0 / 4503599627370496.0;
55 #endif // VSMC_OPENCL
56 
60 {
61  return ((u & UINT32_C(0x7FFFFFC0)) + (u & UINT32_C(0x40))) *
63 }
64 
68 {
69  return (u >> 8) * VSMC_RNGC_U01_24F;
70 }
71 
75 {
76  return VSMC_RNGC_U01_24F + (u >> 8) * VSMC_RNGC_U01_24F;
77 }
78 
82 {
83  return VSMC_RNGC_U01_24F + (u >> 9) * VSMC_RNGC_U01_23F;
84 }
85 
86 #if VSMC_HAS_RNGC_DOUBLE
87 
91 {
92 #ifdef __cplusplus
93  return (static_cast<double>(u & 1) + u) * VSMC_RNGC_U01_32D;
94 #else
95  return (((double) (u & 1)) + u) * VSMC_RNGC_U01_32D;
96 #endif
97 }
98 
102 {
103  return u * VSMC_RNGC_U01_32D;
104 }
105 
109 {
111 }
112 
116 {
118 }
119 
123 {
124 #ifdef __cplusplus
125  return vsmc_u01_closed_closed_u32_f32(static_cast<uint32_t>(u));
126 #else
128 #endif
129 }
130 
134 {
135 #ifdef __cplusplus
136  return vsmc_u01_closed_open_u32_f32(static_cast<uint32_t>(u));
137 #else
139 #endif
140 }
141 
145 {
146 #ifdef __cplusplus
147  return vsmc_u01_open_closed_u32_f32(static_cast<uint32_t>(u));
148 #else
150 #endif
151 }
152 
156 {
157 #ifdef __cplusplus
158  return vsmc_u01_open_open_u32_f32(static_cast<uint32_t>(u));
159 #else
160  return vsmc_u01_open_open_u32_f32(((uint32_t) u));
161 #endif
162 }
163 
167 {
168  return ((u & UINT64_C(0x7FFFFFFFFFFFFE00)) + (u & UINT64_C(0x200))) *
170 }
171 
175 {
176  return (u >> 11) * VSMC_RNGC_U01_53D;
177 }
178 
182 {
183  return VSMC_RNGC_U01_53D + (u >> 11) * VSMC_RNGC_U01_53D;
184 }
185 
189 {
190  return VSMC_RNGC_U01_53D + (u >> 12) * VSMC_RNGC_U01_52D;
191 }
192 
193 #endif // VSMC_HAS_RNGC_DOUBLE
194 
195 #endif // VSMC_RNGC_U01_H
static const float VSMC_RNGC_U01_31F
Definition: u01.h:47
#define UINT64_C(x)
Definition: opencl.h:42
static double vsmc_u01_open_closed_u64_f64(uint64_t u)
Converting 64-bits unsigned to double precision uniform .
Definition: u01.h:181
static double vsmc_u01_closed_open_u64_f64(uint64_t u)
Converting 64-bits unsigned to double precision uniform .
Definition: u01.h:174
uint uint32_t
Definition: opencl.h:39
static float vsmc_u01_closed_closed_u64_f32(uint64_t u)
Converting 64-bits unsigned to single precision uniform .
Definition: u01.h:122
static const double VSMC_RNGC_U01_52D
Definition: u01.h:54
ulong uint64_t
Definition: opencl.h:40
static float vsmc_u01_open_closed_u64_f32(uint64_t u)
Converting 64-bits unsigned to single precision uniform .
Definition: u01.h:144
static const double VSMC_RNGC_U01_53D
Definition: u01.h:53
static float vsmc_u01_open_open_u64_f32(uint64_t u)
Converting 64-bits unsigned to single precision uniform .
Definition: u01.h:155
static const float VSMC_RNGC_U01_23F
Definition: u01.h:49
static const double VSMC_RNGC_U01_32D
Definition: u01.h:51
static const double VSMC_RNGC_U01_33D
Definition: u01.h:50
static const float VSMC_RNGC_U01_24F
Definition: u01.h:48
static double vsmc_u01_open_open_u32_f64(uint32_t u)
Converting 32-bits unsigned to double precision uniform .
Definition: u01.h:115
static const double VSMC_RNGC_U01_63D
Definition: u01.h:52
static double vsmc_u01_open_open_u64_f64(uint64_t u)
Converting 64-bits unsigned to double precision uniform .
Definition: u01.h:188
static float vsmc_u01_closed_open_u32_f32(uint32_t u)
Converting 32-bits unsigned to single precision uniform .
Definition: u01.h:67
static float vsmc_u01_closed_open_u64_f32(uint64_t u)
Converting 64-bits unsigned to single precision uniform .
Definition: u01.h:133
static float vsmc_u01_open_closed_u32_f32(uint32_t u)
Converting 32-bits unsigned to single precision uniform .
Definition: u01.h:74
#define VSMC_STATIC_INLINE
Definition: opencl.h:48
static double vsmc_u01_closed_closed_u32_f64(uint32_t u)
Converting 32-bits unsigned to double precision uniform .
Definition: u01.h:90
static float vsmc_u01_open_open_u32_f32(uint32_t u)
Converting 32-bits unsigned to single precision uniform .
Definition: u01.h:81
static double vsmc_u01_closed_open_u32_f64(uint32_t u)
Converting 32-bits unsigned to double precision uniform .
Definition: u01.h:101
#define UINT32_C(x)
Definition: opencl.h:41
static double vsmc_u01_closed_closed_u64_f64(uint64_t u)
Converting 64-bits unsigned to double precision uniform .
Definition: u01.h:166
static double vsmc_u01_open_closed_u32_f64(uint32_t u)
Converting 32-bits unsigned to double precision uniform .
Definition: u01.h:108
static float vsmc_u01_closed_closed_u32_f32(uint32_t u)
Converting 32-bits unsigned to single precision uniform .
Definition: u01.h:59