30 const double p1 = 1.0, p2 = 3.5156229, p3 = 3.0899424,
31 p4 = 1.2067492, p5 = 0.2659732, p6 = 3.60768e-2, p7 = 4.5813e-3;
33 const double q1 = 0.39894228, q2 = 1.328592e-2, q3 = 2.25319e-3,
34 q4 = -1.57565e-3, q5 = 9.16281e-3, q6 = -2.057706e-2,
35 q7 = 2.635537e-2, q8 = -1.647633e-2, q9 = 3.92377e-3;
37 const double k1 = 3.75;
40 double y = 0, result = 0;
45 result = p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * (p6 + y * p7)))));
49 result = (exp(ax) / sqrt(ax))*(q1 + y * (q2 + y * (q3 + y * (q4 + y * (q5 + y * (q6 + y * (q7 + y * (q8 + y * q9))))))));
65 const double p1 = -0.57721566, p2 = 0.42278420, p3 = 0.23069756,
66 p4 = 3.488590e-2, p5 = 2.62698e-3, p6 = 1.0750e-4, p7 = 7.4e-6;
68 const double q1 = 1.25331414, q2 = -7.832358e-2, q3 = 2.189568e-2,
69 q4 = -1.062446e-2, q5 = 5.87872e-3, q6 = -2.51540e-3, q7 = 5.3208e-4;
76 double y = 0, result = 0;
80 result = (-log(x / 2.)*
xMath::BesselI0(x)) + (p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * (p6 + y * p7))))));
84 result = (exp(-x) / sqrt(x))*(q1 + y * (q2 + y * (q3 + y * (q4 + y * (q5 + y * (q6 + y * q7))))));
100 const double p1 = 0.5, p2 = 0.87890594, p3 = 0.51498869,
101 p4 = 0.15084934, p5 = 2.658733e-2, p6 = 3.01532e-3, p7 = 3.2411e-4;
103 const double q1 = 0.39894228, q2 = -3.988024e-2, q3 = -3.62018e-3,
104 q4 = 1.63801e-3, q5 = -1.031555e-2, q6 = 2.282967e-2,
105 q7 = -2.895312e-2, q8 = 1.787654e-2, q9 = -4.20059e-3;
107 const double k1 = 3.75;
110 double y = 0, result = 0;
115 result = x * (p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * (p6 + y * p7))))));
119 result = (exp(ax) / sqrt(ax))*(q1 + y * (q2 + y * (q3 + y * (q4 + y * (q5 + y * (q6 + y * (q7 + y * (q8 + y * q9))))))));
120 if (x < 0) result = -result;
136 const double p1 = 1., p2 = 0.15443144, p3 = -0.67278579,
137 p4 = -0.18156897, p5 = -1.919402e-2, p6 = -1.10404e-3, p7 = -4.686e-5;
139 const double q1 = 1.25331414, q2 = 0.23498619, q3 = -3.655620e-2,
140 q4 = 1.504268e-2, q5 = -7.80353e-3, q6 = 3.25614e-3, q7 = -6.8245e-4;
147 double y = 0, result = 0;
151 result = (log(x / 2.)*
xMath::BesselI1(x)) + (1. / x)*(p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * (p6 + y * p7))))));
155 result = (exp(-x) / sqrt(x))*(q1 + y * (q2 + y * (q3 + y * (q4 + y * (q5 + y * (q6 + y * q7))))));
169 if (x <= 0 || n < 0) {
182 for (
int j = 1; j < n; j++) {
183 bkp = bkm + double(j)*tox*bk;
200 const double kBigPositive = 1.e10;
201 const double kBigNegative = 1.e-10;
211 if (x == 0)
return 0;
212 if (fabs(x) > kBigPositive)
return 0;
214 double tox = 2 / fabs(x);
215 double bip = 0, bim = 0;
218 int m = 2 * ((n + int(sqrt(
float(iacc*n)))));
219 for (
int j = m; j >= 1; j--) {
220 bim = bip + double(j)*tox*bi;
224 if (fabs(bi) > kBigPositive) {
225 result *= kBigNegative;
229 if (j == n) result = bip;
233 if ((x < 0) && (n % 2 == 1)) result = -result;
244 double xx, y, result, result1, result2;
245 const double p1 = 57568490574.0, p2 = -13362590354.0, p3 = 651619640.7;
246 const double p4 = -11214424.18, p5 = 77392.33017, p6 = -184.9052456;
247 const double p7 = 57568490411.0, p8 = 1029532985.0, p9 = 9494680.718;
248 const double p10 = 59272.64853, p11 = 267.8532712;
250 const double q1 = 0.785398164;
251 const double q2 = -0.1098628627e-2, q3 = 0.2734510407e-4;
252 const double q4 = -0.2073370639e-5, q5 = 0.2093887211e-6;
253 const double q6 = -0.1562499995e-1, q7 = 0.1430488765e-3;
254 const double q8 = -0.6911147651e-5, q9 = 0.7621095161e-6;
255 const double q10 = 0.934935152e-7, q11 = 0.636619772;
257 if ((ax = fabs(x)) < 8) {
259 result1 = p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * p6))));
260 result2 = p7 + y * (p8 + y * (p9 + y * (p10 + y * (p11 + y))));
261 result = result1 / result2;
267 result1 = 1 + y * (q2 + y * (q3 + y * (q4 + y * q5)));
268 result2 = q6 + y * (q7 + y * (q8 + y * (q9 - y * q10)));
269 result = sqrt(q11 / ax)*(cos(xx)*result1 - z * sin(xx)*result2);
280 double xx, y, result, result1, result2;
281 const double p1 = 72362614232.0, p2 = -7895059235.0, p3 = 242396853.1;
282 const double p4 = -2972611.439, p5 = 15704.48260, p6 = -30.16036606;
283 const double p7 = 144725228442.0, p8 = 2300535178.0, p9 = 18583304.74;
284 const double p10 = 99447.43394, p11 = 376.9991397;
286 const double q1 = 2.356194491;
287 const double q2 = 0.183105e-2, q3 = -0.3516396496e-4;
288 const double q4 = 0.2457520174e-5, q5 = -0.240337019e-6;
289 const double q6 = 0.04687499995, q7 = -0.2002690873e-3;
290 const double q8 = 0.8449199096e-5, q9 = -0.88228987e-6;
291 const double q10 = 0.105787412e-6, q11 = 0.636619772;
293 if ((ax = fabs(x)) < 8) {
295 result1 = x * (p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * p6)))));
296 result2 = p7 + y * (p8 + y * (p9 + y * (p10 + y * (p11 + y))));
297 result = result1 / result2;
303 result1 = 1 + y * (q2 + y * (q3 + y * (q4 + y * q5)));
304 result2 = q6 + y * (q7 + y * (q8 + y * (q9 + y * q10)));
305 result = sqrt(q11 / ax)*(cos(xx)*result1 - z * sin(xx)*result2);
306 if (x < 0) result = -result;
316 double z, xx, y, result, result1, result2;
317 const double p1 = -2957821389., p2 = 7062834065.0, p3 = -512359803.6;
318 const double p4 = 10879881.29, p5 = -86327.92757, p6 = 228.4622733;
319 const double p7 = 40076544269., p8 = 745249964.8, p9 = 7189466.438;
320 const double p10 = 47447.26470, p11 = 226.1030244, p12 = 0.636619772;
322 const double q1 = 0.785398164;
323 const double q2 = -0.1098628627e-2, q3 = 0.2734510407e-4;
324 const double q4 = -0.2073370639e-5, q5 = 0.2093887211e-6;
325 const double q6 = -0.1562499995e-1, q7 = 0.1430488765e-3;
326 const double q8 = -0.6911147651e-5, q9 = 0.7621095161e-6;
327 const double q10 = -0.934945152e-7, q11 = 0.636619772;
331 result1 = p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * p6))));
332 result2 = p7 + y * (p8 + y * (p9 + y * (p10 + y * (p11 + y))));
339 result1 = 1 + y * (q2 + y * (q3 + y * (q4 + y * q5)));
340 result2 = q6 + y * (q7 + y * (q8 + y * (q9 + y * q10)));
341 result = sqrt(q11 / x)*(sin(xx)*result1 + z * cos(xx)*result2);
351 double z, xx, y, result, result1, result2;
352 const double p1 = -0.4900604943e13, p2 = 0.1275274390e13;
353 const double p3 = -0.5153438139e11, p4 = 0.7349264551e9;
354 const double p5 = -0.4237922726e7, p6 = 0.8511937935e4;
355 const double p7 = 0.2499580570e14, p8 = 0.4244419664e12;
356 const double p9 = 0.3733650367e10, p10 = 0.2245904002e8;
357 const double p11 = 0.1020426050e6, p12 = 0.3549632885e3;
358 const double p13 = 0.636619772;
359 const double q1 = 2.356194491;
360 const double q2 = 0.183105e-2, q3 = -0.3516396496e-4;
361 const double q4 = 0.2457520174e-5, q5 = -0.240337019e-6;
362 const double q6 = 0.04687499995, q7 = -0.2002690873e-3;
363 const double q8 = 0.8449199096e-5, q9 = -0.88228987e-6;
364 const double q10 = 0.105787412e-6, q11 = 0.636619772;
368 result1 = x * (p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * p6)))));
369 result2 = p7 + y * (p8 + y * (p9 + y * (p10 + y * (p11 + y * (p12 + y)))));
370 result = (result1 / result2) + p13 * (
xMath::BesselJ1(x)*log(x) - 1 / x);
376 result1 = 1 + y * (q2 + y * (q3 + y * (q4 + y * q5)));
377 result2 = q6 + y * (q7 + y * (q8 + y * (q9 + y * q10)));
378 result = sqrt(q11 / x)*(sin(xx)*result1 + z * cos(xx)*result2);
392 const double c1[16] = { 1.00215845609911981, -1.63969292681309147,
393 1.50236939618292819, -.72485115302121872,
394 .18955327371093136, -.03067052022988,
395 .00337561447375194, -2.6965014312602e-4,
396 1.637461692612e-5, -7.8244408508e-7,
397 3.021593188e-8, -9.6326645e-10,
398 2.579337e-11, -5.8854e-13,
400 const double c2[26] = { .99283727576423943, -.00696891281138625,
401 1.8205103787037e-4, -1.063258252844e-5,
402 9.8198294287e-7, -1.2250645445e-7,
403 1.894083312e-8, -3.44358226e-9,
404 7.1119102e-10, -1.6288744e-10,
405 4.065681e-11, -1.091505e-11,
406 3.12005e-12, -9.4202e-13,
407 2.9848e-13, -9.872e-14,
408 3.394e-14, -1.208e-14,
417 double alfa, h, r, y, b0, b1, b2;
428 for (i = n1; i >= 0; --i) {
429 b0 = c1[i] + alfa * b1 - b2;
433 h = y * (b0 - h * b2);
442 for (i = n2; i >= 0; --i) {
443 b0 = c2[i] + alfa * b1 - b2;
462 const double c3[17] = { .5578891446481605, -.11188325726569816,
463 -.16337958125200939, .32256932072405902,
464 -.14581632367244242, .03292677399374035,
465 -.00460372142093573, 4.434706163314e-4,
466 -3.142099529341e-5, 1.7123719938e-6,
467 -7.416987005e-8, 2.61837671e-9,
468 -7.685839e-11, 1.9067e-12,
471 const double c4[23] = { 1.00757647293865641, .00750316051248257,
472 -7.043933264519e-5, 2.66205393382e-6,
473 -1.8841157753e-7, 1.949014958e-8,
474 -2.6126199e-9, 4.236269e-10,
475 -7.955156e-11, 1.679973e-11,
476 -3.9072e-12, 9.8543e-13,
477 -2.6636e-13, 7.645e-14,
478 -2.313e-14, 7.33e-15,
481 -4e-17, 2e-17,-1e-17 };
487 double alfa, h, r, y, b0, b1, b2;
497 i1 = (int)(-8. / log10(v));
498 for (i = 1; i <= i1; ++i) {
499 h = -h * y / ((2 * i + 1)*(2 * i + 3));
510 for (i = n3; i >= 0; --i) {
511 b0 = c3[i] + alfa * b1 - b2;
523 for (i = n4; i >= 0; --i) {
524 b0 = c4[i] + alfa * b1 - b2;
545 double a0, sl0, a1, bi0;
551 for (i = 1; i <= 60; i++) {
552 r *= (x / (2 * i + 1))*(x / (2 * i + 1));
554 if (fabs(r / s) < 1.e-12)
break;
559 km = int(5 * (x + 1.0));
560 if (x >= 50.0)km = 25;
561 for (i = 1; i <= km; i++) {
562 r *= (2 * i - 1)*(2 * i - 1) / x / x;
564 if (fabs(r / s) < 1.0e-12)
break;
566 a1 = exp(x) / sqrt(2 * pi*x);
569 for (i = 1; i <= 16; i++) {
570 r = 0.125*r*(2.0*i - 1.0)*(2.0*i - 1.0) / (i*x);
572 if (fabs(r / bi0) < 1.0e-12)
break;
576 sl0 = -2.0 / (pi*x)*s + bi0;
588 double a1, sl1, bi1, s;
594 for (i = 1; i <= 60; i++) {
595 r *= x * x / (4.0*i*i - 1.0);
597 if (fabs(r) < fabs(s)*1.e-12)
break;
604 if (x > 50.0)km = 25;
605 for (i = 1; i <= km; i++) {
606 r *= (2 * i + 3)*(2 * i + 1) / x / x;
608 if (fabs(r / s) < 1.0e-12)
break;
610 sl1 = 2.0 / pi * (-1.0 + 1.0 / (x*x) + 3.0*s / (x*x*x*x));
611 a1 = exp(x) / sqrt(2 * pi*x);
614 for (i = 1; i <= 16; i++) {
615 r = -0.125*r*(4.0 - (2.0*i - 1.0)*(2.0*i - 1.0)) / (i*x);
617 if (fabs(r / bi1) < 1.0e-12)
break;
637 const double p1 = -0.57721566, p2 = 0.42278420, p3 = 0.23069756,
638 p4 = 3.488590e-2, p5 = 2.62698e-3, p6 = 1.0750e-4, p7 = 7.4e-6;
640 const double q1 = 1.25331414, q2 = -7.832358e-2, q3 = 2.189568e-2,
641 q4 = -1.062446e-2, q5 = 5.87872e-3, q6 = -2.51540e-3, q7 = 5.3208e-4;
648 double y = 0, result = 0;
652 result = exp(x)*((-log(x / 2.)*
xMath::BesselI0(x)) + (p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * (p6 + y * p7)))))));
656 result = (1. / sqrt(x))*(q1 + y * (q2 + y * (q3 + y * (q4 + y * (q5 + y * (q6 + y * q7))))));
672 const double p1 = 1., p2 = 0.15443144, p3 = -0.67278579,
673 p4 = -0.18156897, p5 = -1.919402e-2, p6 = -1.10404e-3, p7 = -4.686e-5;
675 const double q1 = 1.25331414, q2 = 0.23498619, q3 = -3.655620e-2,
676 q4 = 1.504268e-2, q5 = -7.80353e-3, q6 = 3.25614e-3, q7 = -6.8245e-4;
683 double y = 0, result = 0;
687 result = exp(x) * ((log(x / 2.)*
xMath::BesselI1(x)) + (1. / x)*(p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * (p6 + y * p7)))))));
691 result = (1. / sqrt(x))*(q1 + y * (q2 + y * (q3 + y * (q4 + y * (q5 + y * (q6 + y * q7))))));
705 if (x <= 0 || n < 0) {
718 for (
int j = 1; j < n; j++) {
719 bkp = bkm + double(j)*tox*bk;
734 const double p1 = 1.0, p2 = 3.5156229, p3 = 3.0899424,
735 p4 = 1.2067492, p5 = 0.2659732, p6 = 3.60768e-2, p7 = 4.5813e-3;
737 const double q1 = 0.39894228, q2 = 1.328592e-2, q3 = 2.25319e-3,
738 q4 = -1.57565e-3, q5 = 9.16281e-3, q6 = -2.057706e-2,
739 q7 = 2.635537e-2, q8 = -1.647633e-2, q9 = 3.92377e-3;
741 const double k1 = 3.75;
744 double y = 0, result = 0;
749 result = exp(-ax) * ( p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * (p6 + y * p7))))) );
753 result = (1. / sqrt(ax))*(q1 + y * (q2 + y * (q3 + y * (q4 + y * (q5 + y * (q6 + y * (q7 + y * (q8 + y * q9))))))));
769 const double p1 = 0.5, p2 = 0.87890594, p3 = 0.51498869,
770 p4 = 0.15084934, p5 = 2.658733e-2, p6 = 3.01532e-3, p7 = 3.2411e-4;
772 const double q1 = 0.39894228, q2 = -3.988024e-2, q3 = -3.62018e-3,
773 q4 = 1.63801e-3, q5 = -1.031555e-2, q6 = 2.282967e-2,
774 q7 = -2.895312e-2, q8 = 1.787654e-2, q9 = -4.20059e-3;
776 const double k1 = 3.75;
779 double y = 0, result = 0;
784 result = exp(-ax) * (x * (p1 + y * (p2 + y * (p3 + y * (p4 + y * (p5 + y * (p6 + y * p7)))))));
788 result = (1. / sqrt(ax))*(q1 + y * (q2 + y * (q3 + y * (q4 + y * (q5 + y * (q6 + y * (q7 + y * (q8 + y * q9))))))));
789 if (x < 0) result = -result;
804 const double kBigPositive = 1.e10;
805 const double kBigNegative = 1.e-10;
815 if (x == 0)
return 0;
816 if (fabs(x) > kBigPositive)
return 0;
818 double tox = 2 / fabs(x);
819 double bip = 0, bim = 0;
822 int m = 2 * ((n + int(sqrt(
float(iacc*n)))));
823 for (
int j = m; j >= 1; j--) {
824 bim = bip + double(j)*tox*bi;
828 if (fabs(bi) > kBigPositive) {
829 result *= kBigNegative;
833 if (j == n) result = bip;
837 if ((x < 0) && (n % 2 == 1)) result = -result;
850 std::stringstream os;
851 os <<
"Invalid input argument " << x <<
". Argument must be positive.";
852 throw std::invalid_argument(os.str());
865 const double gamma = 0.577215664901532860606512090;
868 return 1.0 / (x*(1.0 + gamma * x));
880 bool arg_was_less_than_one = (y < 1.0);
884 if (arg_was_less_than_one)
890 n =
static_cast<int> (floor(y)) - 1;
895 static const double p[] =
897 -1.71618513886549492533811E+0,
898 2.47656508055759199108314E+1,
899 -3.79804256470945635097577E+2,
900 6.29331155312818442661052E+2,
901 8.66966202790413211295064E+2,
902 -3.14512729688483675254357E+4,
903 -3.61444134186911729807069E+4,
904 6.64561438202405440627855E+4
908 static const double q[] =
910 -3.08402300119738975254353E+1,
911 3.15350626979604161529144E+2,
912 -1.01515636749021914166146E+3,
913 -3.10777167157231109440444E+3,
914 2.25381184209801510330112E+4,
915 4.75584627752788110767815E+3,
916 -1.34659959864969306392456E+5,
917 -1.15132259675553483497211E+5
925 for (i = 0; i < 8; i++)
927 num = (num + p[i])*z;
928 den = den * z + q[i];
930 double result = num / den + 1.0;
933 if (arg_was_less_than_one)
943 for (i = 0; i < n; i++)
956 double temp = DBL_MAX;
970 std::stringstream os;
971 os <<
"Invalid input argument " << x <<
". Argument must be positive.";
972 throw std::invalid_argument(os.str());
977 return log(fabs(
Gamma(x)));
985 static const double c[8] =
996 double z = 1.0 / (x*x);
998 for (
int i = 6; i >= 0; i--)
1003 double series = sum / x;
1005 static const double halfLogTwoPi = 0.91893853320467274178032973640562;
1006 double logGamma = (x - 0.5)*log(x) - x + halfLogTwoPi + series;
double StruveH0(double x)
Struve functions of order 0.
double BesselKexp(int n, double x)
double BesselI1exp(double x)
double BesselI0exp(double x)
double BesselJ0(double x)
Bessel function J0(x) for any real x.
double StruveL0(double x)
Modified Struve functions of order 0.
double BesselJ1(double x)
Bessel function J1(x) for any real x.
double BesselI1(double x)
modified Bessel function I_1(x)
double BesselIexp(int n, double x)
Contains some extra mathematical functions used in the code.
double BesselI(int n, double x)
integer order modified Bessel function I_n(x)
double BesselK(int n, double x)
integer order modified Bessel function K_n(x)
double StruveL1(double x)
Modified Struve functions of order 1.
double BesselK1(double x)
modified Bessel function K_1(x)
double StruveH1(double x)
Struve functions of order 1.
double BesselK0(double x)
modified Bessel function K_0(x)
double BesselY0(double x)
Bessel function Y0(x) for positive x.
double BesselI0(double x)
modified Bessel function I_0(x)
double BesselY1(double x)
Bessel function Y1(x) for positive x.
double BesselK0exp(double x)
double BesselK1exp(double x)
The main namespace where all classes and functions of the Thermal-FIST library reside.