Debian Codegraph @

external/gsl/gsl_rng__ranlxd.c

raw symbols SCIP
1 /* rng/ranlxd.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 James Theiler, Brian Gough
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
21 #include <stdlib.h>
22 #include "gsl_rng.h"cxx . . $ `<file>/external/gsl/gsl_rng.h`/
23
24 /* This is an implementation of Martin Luescher's second generation
25 double-precision (48-bit) version of the RANLUX generator.
26
27 Thanks to Martin Luescher for providing information on this
28 generator.
29
30 */
31
32 static inline unsigned long int ranlxd_getcxx . . $ ranlxd_get(751e5d26f8574c32). (void *vstate);
33 static double ranlxd_get_doublecxx . . $ ranlxd_get_double(a405b17f82753acc). (void *vstate);
34 static void ranlxd_set_luxcxx . . $ ranlxd_set_lux(42777cb9d99382a2). (void *state, unsigned long int s, unsigned int luxury);
35 static void ranlxd1_setcxx . . $ ranlxd1_set(5500c4293b1bbef0). (void *state, unsigned long int s);
36 static void ranlxd2_setcxx . . $ ranlxd2_set(5500c4293b1bbef0). (void *state, unsigned long int s);
37
38 static const int nextcxx . . $ next.[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0};
39
40 static const double one_bitcxx . . $ one_bit. = 1.0 / 281474976710656.0; /* 1/2^48 */
41
42 #define RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`!(x1,x2,i1,i2,i3) \
43 x1=xdbl[i1] - xdbl[i2]; \
44 if (x2 < 0) \
45 { \
46 x1-=one_bit; \
47 x2+=1; \
48 } \
49 xdbl[i3]=x2
50
51 typedef structcxx . . $ $anonymous_type_69a1af6907219683_0#
52 {
53 double xdblcxx . . $ $anonymous_type_69a1af6907219683_0#xdbl.[12];
54 double carrycxx . . $ $anonymous_type_69a1af6907219683_0#carry.;
55 unsigned int ircxx . . $ $anonymous_type_69a1af6907219683_0#ir.;
56 unsigned int jrcxx . . $ $anonymous_type_69a1af6907219683_0#jr.;
57 unsigned int ir_oldcxx . . $ $anonymous_type_69a1af6907219683_0#ir_old.;
58 unsigned int prcxx . . $ $anonymous_type_69a1af6907219683_0#pr.;
59 }
60 ranlxd_state_tcxx . . $ ranlxd_state_t#;
61
62 static inline void increment_statecxx . . $ increment_state(665e86133bd0ecfa). (ranlxd_state_tcxx . . $ ranlxd_state_t# * state);
63
64 static inline void
65 increment_statecxx . . $ increment_state(665e86133bd0ecfa). (ranlxd_state_tcxx . . $ ranlxd_state_t# * state)
66 {
67 int k, kmax;
68 double y1, y2, y3;
69
70 double *xdbl = state->xdblcxx . . $ $anonymous_type_69a1af6907219683_0#xdbl.;
71 double carry = state->carrycxx . . $ $anonymous_type_69a1af6907219683_0#carry.;
72 unsigned int ir = state->ircxx . . $ $anonymous_type_69a1af6907219683_0#ir.;
73 unsigned int jr = state->jrcxx . . $ $anonymous_type_69a1af6907219683_0#jr.;
74
75 for (k = 0; ir > 0; ++k)
76 {
77 y1 = xdbl[jr] - xdbl[ir];
78 y2 = y1 - carry;
79 if (y2 < 0)
80 {
81 carry = one_bitcxx . . $ one_bit.;
82 y2 += 1;
83 }
84 else
85 {
86 carry = 0;
87 }
88 xdbl[ir] = y2;
89 ir = nextcxx . . $ next.[ir];
90 jr = nextcxx . . $ next.[jr];
91 }
92
93 kmax = state->prcxx . . $ $anonymous_type_69a1af6907219683_0#pr. - 12;
94
95 for (; k <= kmax; k += 12)
96 {
97 y1 = xdbl[7] - xdbl[0];
98 y1 -= carry;
99
100 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y2, y1, 8, 1, 0);
101 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y3, y2, 9, 2, 1);
102 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y1, y3, 10, 3, 2);
103 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y2, y1, 11, 4, 3);
104 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y3, y2, 0, 5, 4);
105 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y1, y3, 1, 6, 5);
106 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y2, y1, 2, 7, 6);
107 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y3, y2, 3, 8, 7);
108 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y1, y3, 4, 9, 8);
109 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y2, y1, 5, 10, 9);
110 RANLUX_STEPcxx . . $ `external/gsl/gsl_rng__ranlxd.c:42:9`! (y3, y2, 6, 11, 10);
111
112 if (y3 < 0)
113 {
114 carry = one_bitcxx . . $ one_bit.;
115 y3 += 1;
116 }
117 else
118 {
119 carry = 0;
120 }
121 xdbl[11] = y3;
122 }
123
124 kmax = state->prcxx . . $ $anonymous_type_69a1af6907219683_0#pr.;
125
126 for (; k < kmax; ++k)
127 {
128 y1 = xdbl[jr] - xdbl[ir];
129 y2 = y1 - carry;
130 if (y2 < 0)
131 {
132 carry = one_bitcxx . . $ one_bit.;
133 y2 += 1;
134 }
135 else
136 {
137 carry = 0;
138 }
139 xdbl[ir] = y2;
140 ir = nextcxx . . $ next.[ir];
141 jr = nextcxx . . $ next.[jr];
142 }
143 state->ircxx . . $ $anonymous_type_69a1af6907219683_0#ir. = ir;
144 state->ir_oldcxx . . $ $anonymous_type_69a1af6907219683_0#ir_old. = ir;
145 state->jrcxx . . $ $anonymous_type_69a1af6907219683_0#jr. = jr;
146 state->carrycxx . . $ $anonymous_type_69a1af6907219683_0#carry. = carry;
147 }
148
149 static inline unsigned long int
150 ranlxd_getcxx . . $ ranlxd_get(751e5d26f8574c32). (void *vstate)
151 {
152 return ranlxd_get_doublecxx . . $ ranlxd_get_double(a405b17f82753acc). (vstate) * 4294967296.0; /* 2^32 */
153 }
154
155 static double
156 ranlxd_get_doublecxx . . $ ranlxd_get_double(a405b17f82753acc). (void *vstate)
157 {
158 ranlxd_state_tcxx . . $ ranlxd_state_t# *state = (ranlxd_state_tcxx . . $ ranlxd_state_t# *) vstate;
159
160 int ir = state->ircxx . . $ $anonymous_type_69a1af6907219683_0#ir.;
161
162 state->ircxx . . $ $anonymous_type_69a1af6907219683_0#ir. = nextcxx . . $ next.[ir];
163
164 if (state->ircxx . . $ $anonymous_type_69a1af6907219683_0#ir. == state->ir_oldcxx . . $ $anonymous_type_69a1af6907219683_0#ir_old.)
165 increment_statecxx . . $ increment_state(665e86133bd0ecfa). (state);
166
167 return state->xdblcxx . . $ $anonymous_type_69a1af6907219683_0#xdbl.[state->ircxx . . $ $anonymous_type_69a1af6907219683_0#ir.];
168 }
169
170 static void
171 ranlxd_set_luxcxx . . $ ranlxd_set_lux(42777cb9d99382a2). (void *vstate, unsigned long int s, unsigned int luxury)
172 {
173 ranlxd_state_tcxx . . $ ranlxd_state_t# *state = (ranlxd_state_tcxx . . $ ranlxd_state_t# *) vstate;
174
175 int ibit, jbit, i, k, l, xbit[31];
176 double x, y;
177
178 long int seed;
179
180 if (s == 0)
181 s = 1; /* default seed is 1 */
182
183 seed = s;
184
185 i = seed & 0xFFFFFFFFUL;
186
187 for (k = 0; k < 31; ++k)
188 {
189 xbit[k] = i % 2;
190 i /= 2;
191 }
192
193 ibit = 0;
194 jbit = 18;
195
196 for (k = 0; k < 12; ++k)
197 {
198 x = 0;
199
200 for (l = 1; l <= 48; ++l)
201 {
202 y = (double) ((xbit[ibit] + 1) % 2);
203 x += x + y;
204 xbit[ibit] = (xbit[ibit] + xbit[jbit]) % 2;
205 ibit = (ibit + 1) % 31;
206 jbit = (jbit + 1) % 31;
207 }
208 state->xdblcxx . . $ $anonymous_type_69a1af6907219683_0#xdbl.[k] = one_bitcxx . . $ one_bit. * x;
209 }
210
211 state->carrycxx . . $ $anonymous_type_69a1af6907219683_0#carry. = 0;
212 state->ircxx . . $ $anonymous_type_69a1af6907219683_0#ir. = 11;
213 state->jrcxx . . $ $anonymous_type_69a1af6907219683_0#jr. = 7;
214 state->ir_oldcxx . . $ $anonymous_type_69a1af6907219683_0#ir_old. = 0;
215 state->prcxx . . $ $anonymous_type_69a1af6907219683_0#pr. = luxury;
216 }
217
218 static void
219 ranlxd1_setcxx . . $ ranlxd1_set(5500c4293b1bbef0). (void *vstate, unsigned long int s)
220 {
221 ranlxd_set_luxcxx . . $ ranlxd_set_lux(42777cb9d99382a2). (vstate, s, 202);
222 }
223
224 static void
225 ranlxd2_setcxx . . $ ranlxd2_set(5500c4293b1bbef0). (void *vstate, unsigned long int s)
226 {
227 ranlxd_set_luxcxx . . $ ranlxd_set_lux(42777cb9d99382a2). (vstate, s, 397);
228 }
229
230 static const gsl_rng_typecxx . . $ gsl_rng_type# ranlxd1_typecxx . . $ ranlxd1_type. =
231 {"ranlxd1", /* name */
232 0xffffffffUL, /* RAND_MAX */
233 0, /* RAND_MIN */
234 sizeof (ranlxd_state_tcxx . . $ ranlxd_state_t#),
235 &ranlxd1_setcxx . . $ ranlxd1_set(5500c4293b1bbef0).,
236 &ranlxd_getcxx . . $ ranlxd_get(751e5d26f8574c32).,
237 &ranlxd_get_doublecxx . . $ ranlxd_get_double(a405b17f82753acc).};
238
239 static const gsl_rng_typecxx . . $ gsl_rng_type# ranlxd2_typecxx . . $ ranlxd2_type. =
240 {"ranlxd2", /* name */
241 0xffffffffUL, /* RAND_MAX */
242 0, /* RAND_MIN */
243 sizeof (ranlxd_state_tcxx . . $ ranlxd_state_t#),
244 &ranlxd2_setcxx . . $ ranlxd2_set(5500c4293b1bbef0).,
245 &ranlxd_getcxx . . $ ranlxd_get(751e5d26f8574c32).,
246 &ranlxd_get_doublecxx . . $ ranlxd_get_double(a405b17f82753acc).};
247
248 const gsl_rng_typecxx . . $ gsl_rng_type# *gsl_rng_ranlxd1cxx . . $ gsl_rng_ranlxd1. = &ranlxd1_typecxx . . $ ranlxd1_type.;
249 const gsl_rng_typecxx . . $ gsl_rng_type# *gsl_rng_ranlxd2cxx . . $ gsl_rng_ranlxd2. = &ranlxd2_typecxx . . $ ranlxd2_type.;