88 {
89
91
92
93#ifdef Trace1
94std::cout << "r = " << r << "\n";
95#endif
96
97 if ( r > .5 ) {
98 r = 1-r;
100#ifdef Trace1
101std::cout << "r = " << r << "sign negative \n";
102#endif
103 } else if ( r == .5 ) {
104 return 0.0;
105 }
106
107
108
109
110
111
112
113
114
115
116
117
118 const double* tptr = 0;
119 double dx = 0;
120 double h = 0;
121
122
123
124
125 int index;
126
128
130 if (index <= 0) index = 1;
134#ifdef Trace2
135std::cout << "index = " << index << " dx = " << dx << " h = " << h << "\n";
136#endif
138
139
140
141#ifdef Trace2
142std::cout << "offset index = " << index << "\n";
143#endif
144
145 tptr = &gaussTables [index];
146
147 } else if (r < Tsteps[0]) {
148
149
151
152 } else {
153
154 for ( int tableN = 3; tableN >= 0; tableN-- ) {
155 if ( r < Tsteps[tableN] ) {continue;}
156#ifdef Trace2
157std::cout << "Using table " << tableN << "\n";
158#endif
159 double step = Tsteps[tableN];
160 index = int(r/step);
161
162
163
164
165 if (index == 0) index = 1;
166 if (index >= Tsizes[tableN]) index = Tsizes[tableN] - 1;
167 dx = r/step - index;
168 h = step;
169#ifdef Trace2
170std::cout << "index = " << index << " dx = " << dx << " h = " << h << "\n";
171#endif
172 index = (index<<1) + Toffsets[tableN] - 2;
173 tptr = &gaussTables [index];
174 break;
175 }
176
177
178
179
180
181 }
182
183
184
185
186 double y0 = *tptr++;
187 double d0 = *tptr++;
188 double y1 = *tptr++;
189 double d1 = *tptr;
190
191#ifdef Trace3
192std::cout << "y0: " << y0 << " y1: " << y1 << " d0: " << d0 << " d1: " << d1 << "\n";
193#endif
194
195 double x2 = dx * dx;
196 double oneMinusX = 1 - dx;
197 double oneMinusX2 = oneMinusX * oneMinusX;
198
199 double f0 = (2. * dx + 1.) * oneMinusX2;
200 double f1 = (3. - 2. * dx) * x2;
201 double g0 = h * dx * oneMinusX2;
202 double g1 = - h * oneMinusX * x2;
203
204#ifdef Trace3
205std::cout << "f0: " << f0 << " f1: " << f1 << " g0: " << g0 << " g1: " << g1 << "\n";
206#endif
207
208 double answer = f0 * y0 + f1 * y1 + g0 * d0 + g1 * d1;
209
210#ifdef Trace1
211std::cout <<
"variate is: " <<
sign*answer <<
"\n";
212#endif
213
214 return sign * answer;
215
216}
double transformSmall(double r)