Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __r123_compat_gslrng_dot_h__
00033 #define __r123_compat_gslrng_dot_h__
00034
00035 #include <gsl/gsl_rng.h>
00036 #include <string.h>
00037
00067 #define GSL_CBRNG(NAME, CBRNGNAME) \
00068 const gsl_rng_type *gsl_rng_##NAME; \
00069 \
00070 typedef struct{ \
00071 CBRNGNAME##_ctr_t ctr; \
00072 CBRNGNAME##_ctr_t r; \
00073 CBRNGNAME##_key_t key; \
00074 int elem; \
00075 } NAME##_state; \
00076 \
00077 static unsigned long int NAME##_get(void *vstate){ \
00078 NAME##_state *st = (NAME##_state *)vstate; \
00079 const int N=sizeof(st->ctr.v)/sizeof(st->ctr.v[0]); \
00080 if( st->elem == 0 ){ \
00081 ++st->ctr.v[0]; \
00082 if( N>1 && st->ctr.v[0] == 0 ) ++st->ctr.v[1]; \
00083 if( N>2 && st->ctr.v[1] == 0 ) ++st->ctr.v[2]; \
00084 if( N>3 && st->ctr.v[2] == 0 ) ++st->ctr.v[3]; \
00085 st->r = CBRNGNAME(st->ctr, st->key); \
00086 st->elem = N; \
00087 } \
00088 return st->r.v[--st->elem]; \
00089 } \
00090 \
00091 static double NAME##_get_double (void * vstate); \
00092 \
00093 static void NAME##_set(void *vstate, unsigned long int s){ \
00094 NAME##_state *st = (NAME##_state *)vstate; \
00095 st->elem = 0; \
00096
00097
00098
00099 \
00100 memset(&st->ctr.v[0], 0, sizeof(st->ctr.v)); \
00101 memset(&st->key.v[0], 0, sizeof(st->key.v)); \
00102
00103
00104
00105
00106
00107 \
00108 st->key.v[0] = s; \
00109 } \
00110 \
00111 static const gsl_rng_type NAME##_type = { \
00112 #NAME, \
00113 ~0UL>>((R123_W(CBRNGNAME##_ctr_t)>=8*sizeof(unsigned long))? 0 : (8*sizeof(unsigned long) - R123_W(CBRNGNAME##_ctr_t))), \
00114 0, \
00115 sizeof(NAME##_state), \
00116 &NAME##_set, \
00117 &NAME##_get, \
00118 &NAME##_get_double \
00119 }; \
00120 \
00121 static double \
00122 NAME##_get_double (void * vstate) \
00123 { \
00124 return NAME##_get (vstate)/(double)NAME##_type.max; \
00125 } \
00126 \
00127 const gsl_rng_type *gsl_rng_##NAME = &NAME##_type
00128
00129 #endif
00130