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