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