22static double clenshaw(std::size_t
n,
const double* coeffs,
double x,
double left,
double right) {
26 double t = (2.*
x -
left -
right) / (right - left);
29 for(std::size_t k =
n-1; k >= 1; k--) {
30 double b0 = coeffs[k] +
t2 *
b1 -
b2;
34 return 0.5 * coeffs[0] + t *
b1 -
b2 ;
38static const double fd_half_coeffs_1_1[] = {
39 1.7177138871306189157,
40 0.6192579515822668460,
41 0.0932802275119206269,
42 0.0047094853246636182,
43 -0.0004243667967864481,
44 -0.0000452569787686193,
65static const double fd_half_coeffs_1_4[] = {
69 -0.007730591500584980,
70 -0.000217443383867318,
72 -0.000021586361321527,
89static const double fd_half_coeffs_4_10[] = {
90 29.584339348839816528,
93 -0.021540694914550443,
95 -0.000257365680646579,
116static const double fd_half_coeffs_10_30[] = {
117 1.5116909434145508537,
118 -0.0036043405371630468,
119 0.0014207743256393359,
120 -0.0005045399052400260,
121 0.0001690758006957347,
122 -0.0000546305872688307,
123 0.0000172223228484571,
149#define WITH_SIZE(arr) sizeof(arr)/sizeof(double), arr
151static const double eta_table[] = {
152 0.50000000000000000000000000000,
154 0.82246703342411321823620758332,
155 0.90154267736969571404980362113,
156 0.94703282949724591757650323447,
157 0.97211977044690930593565514355,
158 0.98555109129743510409843924448,
159 0.99259381992283028267042571313,
160 0.99623300185264789922728926008,
161 0.99809429754160533076778303185,
162 0.99903950759827156563922184570,
163 0.99951714349806075414409417483,
164 0.99975768514385819085317967871,
165 0.99987854276326511549217499282,
166 0.99993917034597971817095419226,
167 0.99996955121309923808263293263,
168 0.99998476421490610644168277496,
169 0.99999237829204101197693787224,
170 0.99999618786961011347968922641,
171 0.99999809350817167510685649297,
172 0.99999904661158152211505084256,
173 0.99999952325821554281631666433,
174 0.99999976161323082254789720494,
175 0.99999988080131843950322382485,
176 0.99999994039889239462836140314,
177 0.99999997019885696283441513311,
178 0.99999998509923199656878766181,
179 0.99999999254955048496351585274,
180 0.99999999627475340010872752767,
181 0.99999999813736941811218674656,
182 0.99999999906868228145397862728,
183 0.99999999953434033145421751469,
184 0.99999999976716989595149082282,
185 0.99999999988358485804603047265,
186 0.99999999994179239904531592388,
187 0.99999999997089618952980952258,
188 0.99999999998544809143388476396,
189 0.99999999999272404460658475006,
190 0.99999999999636202193316875550,
191 0.99999999999818101084320873555,
192 0.99999999999909050538047887809,
193 0.99999999999954525267653087357,
194 0.99999999999977262633369589773,
195 0.99999999999988631316532476488,
196 0.99999999999994315658215465336,
197 0.99999999999997157829090808339,
198 0.99999999999998578914539762720,
199 0.99999999999999289457268000875,
200 0.99999999999999644728633373609,
201 0.99999999999999822364316477861,
202 0.99999999999999911182158169283,
203 0.99999999999999955591079061426,
204 0.99999999999999977795539522974,
205 0.99999999999999988897769758908,
206 0.99999999999999994448884878594,
207 0.99999999999999997224442439010,
208 0.99999999999999998612221219410,
209 0.99999999999999999306110609673,
210 0.99999999999999999653055304826,
211 0.99999999999999999826527652409,
212 0.99999999999999999913263826204,
213 0.99999999999999999956631913101,
214 0.99999999999999999978315956551,
215 0.99999999999999999989157978275,
216 0.99999999999999999994578989138,
217 0.99999999999999999997289494569,
218 0.99999999999999999998644747284,
219 0.99999999999999999999322373642,
220 0.99999999999999999999661186821,
221 0.99999999999999999999830593411,
222 0.99999999999999999999915296705,
223 0.99999999999999999999957648353,
224 0.99999999999999999999978824176,
225 0.99999999999999999999989412088,
226 0.99999999999999999999994706044,
227 0.99999999999999999999997353022,
228 0.99999999999999999999998676511,
229 0.99999999999999999999999338256,
230 0.99999999999999999999999669128,
231 0.99999999999999999999999834564,
232 0.99999999999999999999999917282,
233 0.99999999999999999999999958641,
234 0.99999999999999999999999979320,
235 0.99999999999999999999999989660,
236 0.99999999999999999999999994830,
237 0.99999999999999999999999997415,
238 0.99999999999999999999999998708,
239 0.99999999999999999999999999354,
240 0.99999999999999999999999999677,
241 0.99999999999999999999999999838,
242 0.99999999999999999999999999919,
243 0.99999999999999999999999999960,
244 0.99999999999999999999999999980,
245 0.99999999999999999999999999990,
246 0.99999999999999999999999999995,
247 0.99999999999999999999999999997,
248 0.99999999999999999999999999999,
249 0.99999999999999999999999999999,
250 1.00000000000000000000000000000,
251 1.00000000000000000000000000000,
252 1.00000000000000000000000000000,
262 for(
int n = 2;
n < 100 ;
n++) {
263 double rat = (
n - 1.) /
n;
266 if(
fabs(
term/
sum) < std::numeric_limits<double>::epsilon())
break;
271 return clenshaw(
WITH_SIZE(fd_half_coeffs_1_1), x, -1., 1.);
274 return clenshaw(
WITH_SIZE(fd_half_coeffs_1_4), x, 1., 4.);
277 return clenshaw(
WITH_SIZE(fd_half_coeffs_4_10), x, 4., 10.);
280 double val = clenshaw(
WITH_SIZE(fd_half_coeffs_10_30), x, 10., 30.);
281 return x * sqrt(x) * val;
285 const int itmax = 200;
286 const double lg = 0.28468287047291918;
288 double xm2 = 1. / x / x;
290 double add = std::numeric_limits<double>::max();
294 const double eta = (
n <= 50)? eta_table[2*
n]: 1.;
298 if(
fabs(add/
seqn) < std::numeric_limits<double>::epsilon())
break;