vSMC  v3.0.0
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-2016, 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_23F (1.0f / 8388608.0f)
39 #define VSMC_RNGC_U01_24F (1.0f / 16777216.0f)
40 #define VSMC_RNGC_U01_31F (1.0f / 2147483648.0f)
41 #define VSMC_RNGC_U01_32F (1.0f / 4294967296.0f)
42 #define VSMC_RNGC_U01_33F (1.0f / 8589934592.0f)
43 #define VSMC_RNGC_U01_64F (1.0f / 18446744073709551616.0f)
44 #define VSMC_RNGC_U01_65F (1.0f / 36893488147419103232.0f)
45 #if VSMC_HAS_OPENCL_DOUBLE
46 #define VSMC_RNGC_U01_32D (1.0 / 4294967296.0)
47 #define VSMC_RNGC_U01_33D (1.0 / 8589934592.0)
48 #define VSMC_RNGC_U01_52D (1.0 / 4503599627370496.0)
49 #define VSMC_RNGC_U01_53D (1.0 / 9007199254740992.0)
50 #define VSMC_RNGC_U01_63D (1.0 / 9223372036854775808.0)
51 #define VSMC_RNGC_U01_64D (1.0 / 18446744073709551616.0)
52 #define VSMC_RNGC_U01_65D (1.0 / 36893488147419103232.0)
53 #endif // VSMC_HAS_OPENCL_DOUBLE
54 #else // VSMC_OPENCL
55 static const float VSMC_RNGC_U01_23F = 1.0f / 8388608.0f;
56 static const float VSMC_RNGC_U01_24F = 1.0f / 16777216.0f;
57 static const float VSMC_RNGC_U01_31F = 1.0f / 2147483648.0f;
58 static const float VSMC_RNGC_U01_32F = 1.0f / 4294967296.0f;
59 static const float VSMC_RNGC_U01_33F = 1.0f / 8589934592.0f;
60 static const float VSMC_RNGC_U01_64F = 1.0f / 18446744073709551616.0f;
61 static const float VSMC_RNGC_U01_65F = 1.0f / 36893488147419103232.0f;
62 static const double VSMC_RNGC_U01_32D = 1.0 / 4294967296.0;
63 static const double VSMC_RNGC_U01_33D = 1.0 / 8589934592.0;
64 static const double VSMC_RNGC_U01_52D = 1.0 / 4503599627370496.0;
65 static const double VSMC_RNGC_U01_53D = 1.0 / 9007199254740992.0;
66 static const double VSMC_RNGC_U01_63D = 1.0 / 9223372036854775808.0;
67 static const double VSMC_RNGC_U01_64D = 1.0 / 18446744073709551616.0;
68 static const double VSMC_RNGC_U01_65D = 1.0 / 36893488147419103232.0;
69 static const long double VSMC_RNGC_U01_32L = 1.0l / 4294967296.0l;
70 static const long double VSMC_RNGC_U01_33L = 1.0l / 8589934592.0l;
71 static const long double VSMC_RNGC_U01_63L = 1.0l / 9223372036854775808.0l;
72 static const long double VSMC_RNGC_U01_64L = 1.0l / 18446744073709551616.0l;
73 static const long double VSMC_RNGC_U01_65L = 1.0l / 36893488147419103232.0l;
74 #endif // VSMC_OPENCL
75 
78 static inline float vsmc_u01_u32f(uint32_t u)
79 {
81 }
82 
85 static inline float vsmc_u01_u64f(uint64_t u)
86 {
88 }
89 
90 #if !defined(VSMC_OPENCL) || VSMC_HAS_OPENCL_DOUBLE
91 
94 static inline double vsmc_u01_u32d(uint32_t u)
95 {
97 }
98 
101 static inline double vsmc_u01_u64d(uint64_t u)
102 {
104 }
105 
106 #endif // !defined(VSMC_OPENCL) || VSMC_HAS_OPENCL_DOUBLE
107 
108 #ifndef VSMC_OPENCL
109 
112 static inline long double vsmc_u01_u32l(uint32_t u)
113 {
115 }
116 
119 static inline long double vsmc_u01_u64l(uint64_t u)
120 {
122 }
123 
124 #endif // VSMC_OPENCL
125 
128 static inline float vsmc_u01_cc_u32f(uint32_t u)
129 {
130  return ((u & UINT32_C(0x40)) + (u & UINT32_C(0x7FFFFFC0))) *
132 }
133 
136 static inline float vsmc_u01_co_u32f(uint32_t u)
137 {
138  return (u >> 8) * VSMC_RNGC_U01_24F;
139 }
140 
143 static inline float vsmc_u01_oc_u32f(uint32_t u)
144 {
145  return (u >> 8) * VSMC_RNGC_U01_24F + VSMC_RNGC_U01_24F;
146 }
147 
150 static inline float vsmc_u01_oo_u32f(uint32_t u)
151 {
152  return (u >> 9) * VSMC_RNGC_U01_23F + VSMC_RNGC_U01_24F;
153 }
154 
157 static inline float vsmc_u01_cc_u64f(uint64_t u)
158 {
159 #ifdef __cplusplus
160  return vsmc_u01_cc_u32f(static_cast<uint32_t>(u >> 32));
161 #else
162  return vsmc_u01_cc_u32f(((uint32_t)(u >> 32)));
163 #endif
164 }
165 
168 static inline float vsmc_u01_co_u64f(uint64_t u)
169 {
170 #ifdef __cplusplus
171  return vsmc_u01_co_u32f(static_cast<uint32_t>(u >> 32));
172 #else
173  return vsmc_u01_co_u32f(((uint32_t)(u >> 32)));
174 #endif
175 }
176 
179 static inline float vsmc_u01_oc_u64f(uint64_t u)
180 {
181 #ifdef __cplusplus
182  return vsmc_u01_oc_u32f(static_cast<uint32_t>(u >> 32));
183 #else
184  return vsmc_u01_oc_u32f(((uint32_t)(u >> 32)));
185 #endif
186 }
187 
190 static inline float vsmc_u01_oo_u64f(uint64_t u)
191 {
192 #ifdef __cplusplus
193  return vsmc_u01_oo_u32f(static_cast<uint32_t>(u >> 32));
194 #else
195  return vsmc_u01_oo_u32f(((uint32_t)(u >> 32)));
196 #endif
197 }
198 
199 #if !defined(VSMC_OPENCL) || VSMC_HAS_OPENCL_DOUBLE
200 
203 static inline double vsmc_u01_cc_u32d(uint32_t u)
204 {
205 #ifdef __cplusplus
206  return (static_cast<double>(u & 1) + u) * VSMC_RNGC_U01_32D;
207 #else
208  return (((double) (u & 1)) + u) * VSMC_RNGC_U01_32D;
209 #endif
210 }
211 
214 static inline double vsmc_u01_co_u32d(uint32_t u)
215 {
216  return u * VSMC_RNGC_U01_32D;
217 }
218 
221 static inline double vsmc_u01_oc_u32d(uint32_t u)
222 {
224 }
225 
228 static inline double vsmc_u01_oo_u32d(uint32_t u)
229 {
231 }
232 
235 static inline double vsmc_u01_cc_u64d(uint64_t u)
236 {
237  return ((u & UINT64_C(0x7FFFFFFFFFFFFE00)) + (u & UINT64_C(0x200))) *
239 }
240 
243 static inline double vsmc_u01_co_u64d(uint64_t u)
244 {
245  return (u >> 11) * VSMC_RNGC_U01_53D;
246 }
247 
250 static inline double vsmc_u01_oc_u64d(uint64_t u)
251 {
252  return VSMC_RNGC_U01_53D + (u >> 11) * VSMC_RNGC_U01_53D;
253 }
254 
257 static inline double vsmc_u01_oo_u64d(uint64_t u)
258 {
259  return VSMC_RNGC_U01_53D + (u >> 12) * VSMC_RNGC_U01_52D;
260 }
261 
262 #endif // !defined(VSMC_OPENCL) || VSMC_HAS_OPENCL_DOUBLE
263 
264 #ifndef VSMC_OPENCL
265 
269 static inline long double vsmc_u01_cc_u32l(uint32_t u)
270 {
271 #ifdef __cplusplus
272  return (static_cast<long double>(u & 1) + u) * VSMC_RNGC_U01_32L;
273 #else
274  return (((long double) (u & 1)) + u) * VSMC_RNGC_U01_32L;
275 #endif
276 }
277 
281 static inline long double vsmc_u01_co_u32l(uint32_t u)
282 {
283  return u * VSMC_RNGC_U01_32L;
284 }
285 
289 static inline long double vsmc_u01_oc_u32l(uint32_t u)
290 {
292 }
293 
297 static inline long double vsmc_u01_oo_u32l(uint32_t u)
298 {
300 }
301 
305 static inline long double vsmc_u01_cc_u64l(uint64_t u)
306 {
307 #ifdef __cplusplus
308  return (static_cast<long double>(u & 1) + u) * VSMC_RNGC_U01_64L;
309 #else
310  return (((long double) (u & 1)) + u) * VSMC_RNGC_U01_64L;
311 #endif
312 }
313 
317 static inline long double vsmc_u01_co_u64l(uint64_t u)
318 {
319  return u * VSMC_RNGC_U01_64L;
320 }
321 
325 static inline long double vsmc_u01_oc_u64l(uint64_t u)
326 {
328 }
329 
333 static inline long double vsmc_u01_oo_u64l(uint64_t u)
334 {
335  return (u >> 1) * VSMC_RNGC_U01_63L + VSMC_RNGC_U01_64L;
336 }
337 
338 #endif // VSMC_OPENCL
339 
340 #endif // VSMC_RNGC_U01_H
static const float VSMC_RNGC_U01_31F
Definition: u01.h:57
#define UINT64_C(x)
Definition: opencl.h:44
static float vsmc_u01_oc_u64f(uint64_t u)
Converting 64-bit unsigned to single precision uniform .
Definition: u01.h:179
static long double vsmc_u01_oo_u64l(uint64_t u)
Converting 64-bit unsigned to long double precision uniform .
Definition: u01.h:333
static long double vsmc_u01_oc_u64l(uint64_t u)
Converting 64-bit unsigned to long double precision uniform .
Definition: u01.h:325
static long double vsmc_u01_co_u64l(uint64_t u)
Converting 64-bit unsigned to long double precision uniform .
Definition: u01.h:317
static long double vsmc_u01_cc_u32l(uint32_t u)
Converting 32-bit unsigned to long double precision uniform .
Definition: u01.h:269
static const long double VSMC_RNGC_U01_64L
Definition: u01.h:72
static float vsmc_u01_co_u32f(uint32_t u)
Converting 32-bit unsigned to single precision uniform .
Definition: u01.h:136
static float vsmc_u01_oo_u32f(uint32_t u)
Converting 32-bit unsigned to single precision uniform .
Definition: u01.h:150
uint uint32_t
Definition: opencl.h:41
static float vsmc_u01_cc_u32f(uint32_t u)
Converting 32-bit unsigned to single precision uniform .
Definition: u01.h:128
static const double VSMC_RNGC_U01_52D
Definition: u01.h:64
ulong uint64_t
Definition: opencl.h:42
static const double VSMC_RNGC_U01_53D
Definition: u01.h:65
static long double vsmc_u01_cc_u64l(uint64_t u)
Converting 64-bit unsigned to long double precision uniform .
Definition: u01.h:305
static const float VSMC_RNGC_U01_23F
Definition: u01.h:55
static double vsmc_u01_oc_u64d(uint64_t u)
Converting 64-bit unsigned to double precision uniform .
Definition: u01.h:250
static const long double VSMC_RNGC_U01_63L
Definition: u01.h:71
static double vsmc_u01_oo_u64d(uint64_t u)
Converting 64-bit unsigned to double precision uniform .
Definition: u01.h:257
static const double VSMC_RNGC_U01_32D
Definition: u01.h:62
static double vsmc_u01_cc_u64d(uint64_t u)
Converting 64-bit unsigned to double precision uniform .
Definition: u01.h:235
static double vsmc_u01_u32d(uint32_t u)
Converting 32-bit unsigned to double precision uniform .
Definition: u01.h:94
static long double vsmc_u01_u32l(uint32_t u)
Converting 32-bit unsigned to long double precision uniform .
Definition: u01.h:112
static const double VSMC_RNGC_U01_33D
Definition: u01.h:63
static const long double VSMC_RNGC_U01_32L
Definition: u01.h:69
static const float VSMC_RNGC_U01_33F
Definition: u01.h:59
static const float VSMC_RNGC_U01_24F
Definition: u01.h:56
static double vsmc_u01_oc_u32d(uint32_t u)
Converting 32-bit unsigned to double precision uniform .
Definition: u01.h:221
static float vsmc_u01_co_u64f(uint64_t u)
Converting 64-bit unsigned to single precision uniform .
Definition: u01.h:168
static const float VSMC_RNGC_U01_65F
Definition: u01.h:61
static float vsmc_u01_oc_u32f(uint32_t u)
Converting 32-bit unsigned to single precision uniform .
Definition: u01.h:143
static const double VSMC_RNGC_U01_63D
Definition: u01.h:66
static float vsmc_u01_u64f(uint64_t u)
Converting 64-bit unsigned to single precision uniform .
Definition: u01.h:85
static const double VSMC_RNGC_U01_64D
Definition: u01.h:67
static double vsmc_u01_co_u32d(uint32_t u)
Converting 32-bit unsigned to double precision uniform .
Definition: u01.h:214
static long double vsmc_u01_u64l(uint64_t u)
Converting 64-bit unsigned to long double precision uniform .
Definition: u01.h:119
static const double VSMC_RNGC_U01_65D
Definition: u01.h:68
static long double vsmc_u01_oc_u32l(uint32_t u)
Converting 32-bit unsigned to long double precision uniform .
Definition: u01.h:289
static const float VSMC_RNGC_U01_64F
Definition: u01.h:60
static double vsmc_u01_cc_u32d(uint32_t u)
Converting 32-bit unsigned to double precision uniform .
Definition: u01.h:203
static double vsmc_u01_u64d(uint64_t u)
Converting 64-bit unsigned to double precision uniform .
Definition: u01.h:101
static long double vsmc_u01_co_u32l(uint32_t u)
Converting 32-bit unsigned to long double precision uniform .
Definition: u01.h:281
#define UINT32_C(x)
Definition: opencl.h:43
static const long double VSMC_RNGC_U01_65L
Definition: u01.h:73
static float vsmc_u01_u32f(uint32_t u)
Converting 32-bit unsigned to single precision uniform .
Definition: u01.h:78
static double vsmc_u01_oo_u32d(uint32_t u)
Converting 32-bit unsigned to double precision uniform .
Definition: u01.h:228
static const float VSMC_RNGC_U01_32F
Definition: u01.h:58
static float vsmc_u01_oo_u64f(uint64_t u)
Converting 64-bit unsigned to single precision uniform .
Definition: u01.h:190
static const long double VSMC_RNGC_U01_33L
Definition: u01.h:70
static long double vsmc_u01_oo_u32l(uint32_t u)
Converting 32-bit unsigned to long double precision uniform .
Definition: u01.h:297
static double vsmc_u01_co_u64d(uint64_t u)
Converting 64-bit unsigned to double precision uniform .
Definition: u01.h:243
static float vsmc_u01_cc_u64f(uint64_t u)
Converting 64-bit unsigned to single precision uniform .
Definition: u01.h:157