14 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
23 #include <boost/bind.hpp>
26 void sincosint(
double x,
double& sint,
double& cint);
32 int dzero(
double a,
double b,
double& x0,
double& rv,
double eps,
int mxf,
F func);
44 const double xp[9] = {9.29, 2.47, .89, .36, .15, .07, .03, .02, 0.0};
45 const double xq[7] = {.012, .03, .08, .26, .87, 3.83, 11.0};
47 double q, u,
x,
c1, c2, c3, c4,
d1, h4, h5, h6,
q2,
x1,
d, ll, ul, xf1, xf2, rv;
61 h_[4] = 1. - beta2 * 0.42278433999999998 + 7.6 /
kappa;
64 h4 = -7.6 /
kappa - (beta2 * .57721566 + 1);
71 for (lp = 0; lp < 9; ++lp) {
76 for (lq = 0; lq < 7; ++lq) {
81 auto f2 = [h_](
double x) {
89 h_[0] =
kappa * (beta2 * .57721566 + 2.) + 9.9166128600000008;
93 h_[1] = beta2 *
kappa;
95 h_[3] =
omega_ * 1.5707963250000001;
96 auto f1 = [h_](
double x) {
return h_[0] + h_[1] *
std::log(h_[2] *
x) - h_[3] *
x; };
99 d =
exp(
kappa * (beta2 * (.57721566 - h5) + 1.)) * .31830988654751274;
106 for (
k = 1;
k <
n; ++
k) {
114 xf1 =
kappa * (beta2 *
c1 - c4) -
x * c2;
141 double f, u,
y,
a0, a1;
149 }
else if (
x <=
t1_) {
151 u =
omega_ *
y - 3.141592653589793;
156 for (
k = 2;
k <= n1; ++
k) {
159 a0 =
a_[
k - 1] + cof * a1 -
a2;
163 for (
k = 2;
k <=
n; ++
k) {
197 const double zero = 0.;
198 const double one = 1.;
199 const double two = 2.;
200 const double eight = 8.;
201 const double ce = .57721566490153;
202 const double c__[14] = {1.9405491464836,
216 const double p[23] = {
217 .96074783975204, -.0371138962124, .00194143988899, -1.7165988425e-4, 2.112637753e-5, -3.27163257e-6,
218 6.0069212e-7, -1.2586794e-7, 2.932563e-8, -7.45696e-9, 2.04105e-9, -5.9502e-10,
219 1.8323e-10, -5.921e-11, 1.997e-11, -7
e-12, 2.54e-12, -9.5e-13,
220 3.7e-13, -1.4e-13, 6
e-14, -2
e-14, 1
e-14};
221 const double q[20] = {.98604065696238, -.0134717382083, 4.5329284117e-4, -3.067288652e-5, 3.13199198e-6,
222 -4.2110196e-7, 6.907245e-8, -1.318321e-8, 2.83697e-9, -6.7329e-10,
223 1.734e-10, -4.787e-11, 1.403e-11, -4.33e-12, 1.4e-12,
224 -4.7e-13, 1.7e-13, -6
e-14, 2
e-14, -1
e-14};
232 double r__, y,
b0,
b1,
b2,
pp, qq, alfa;
239 if (fabs(x) <= eight) {
243 h__ = two * (d__1 * d__1) - one;
247 for (i__ = 13; i__ >= 0; --i__) {
248 b0 = c__[i__] - alfa *
b1 -
b2;
252 b1 = ce +
log((fabs(x))) -
b0 + h__ *
b2;
258 h__ = two * (d__1 * d__1) - one;
262 for (i__ = 22; i__ >= 0; --i__) {
270 for (i__ = 19; i__ >= 0; --i__) {
284 const double zero = 0.;
285 const double one = 1.;
286 const double two = 2.;
287 const double eight = 8.;
288 const double pih = 1.5707963267949;
289 const double s[14] = {1.9522209759531,
303 const double p[23] = {
304 .96074783975204, -.0371138962124, .00194143988899, -1.7165988425e-4, 2.112637753e-5, -3.27163257e-6,
305 6.0069212e-7, -1.2586794e-7, 2.932563e-8, -7.45696e-9, 2.04105e-9, -5.9502e-10,
306 1.8323e-10, -5.921e-11, 1.997e-11, -7
e-12, 2.54e-12, -9.5e-13,
307 3.7e-13, -1.4e-13, 6
e-14, -2
e-14, 1
e-14};
308 const double q[20] = {.98604065696238, -.0134717382083, 4.5329284117e-4, -3.067288652e-5, 3.13199198e-6,
309 -4.2110196e-7, 6.907245e-8, -1.318321e-8, 2.83697e-9, -6.7329e-10,
310 1.734e-10, -4.787e-11, 1.403e-11, -4.33e-12, 1.4e-12,
311 -4.7e-13, 1.7e-13, -6
e-14, 2
e-14, -1
e-14};
319 double r__, y,
b0,
b1,
b2,
pp, qq, alfa;
321 if (fabs(x) <= eight) {
324 h__ = two * (d__1 * d__1) - one;
328 for (i__ = 13; i__ >= 0; --i__) {
338 h__ = two * (d__1 * d__1) - one;
342 for (i__ = 22; i__ >= 0; --i__) {
350 for (i__ = 19; i__ >= 0; --i__) {
359 b1 = d__1 - r__ * (r__ *
pp *
sin(x) + qq *
cos(x));
368 const double zero = 0.;
369 const double one = 1.;
370 const double two = 2.;
371 const double eight = 8.;
372 const double ce = .57721566490153;
373 const double pih = 1.5707963267949;
374 const double s__[14] = {1.9522209759531,
389 const double c__[14] = {1.9405491464836,
404 const double p[23] = {
405 .96074783975204, -.0371138962124, .00194143988899, -1.7165988425e-4, 2.112637753e-5, -3.27163257e-6,
406 6.0069212e-7, -1.2586794e-7, 2.932563e-8, -7.45696e-9, 2.04105e-9, -5.9502e-10,
407 1.8323e-10, -5.921e-11, 1.997e-11, -7
e-12, 2.54e-12, -9.5e-13,
408 3.7e-13, -1.4e-13, 6
e-14, -2
e-14, 1
e-14};
409 const double q[20] = {.98604065696238, -.0134717382083, 4.5329284117e-4, -3.067288652e-5, 3.13199198e-6,
410 -4.2110196e-7, 6.907245e-8, -1.318321e-8, 2.83697e-9, -6.7329e-10,
411 1.734e-10, -4.787e-11, 1.403e-11, -4.33e-12, 1.4e-12,
412 -4.7e-13, 1.7e-13, -6
e-14, 2
e-14, -1
e-14};
420 double r__, y,
b0,
b1,
b2,
pp, qq, alfa;
425 if (fabs(x) <= eight) {
429 h__ = two * (d__1 * d__1) - one;
436 for (i__ = 13; i__ >= 0; --i__) {
437 b0 = c__[i__] - alfa *
b1 -
b2;
441 cint = ce +
log((fabs(x))) -
b0 + h__ *
b2;
446 for (i__ = 13; i__ >= 0; --i__) {
447 b0 = s__[i__] - alfa *
b1 -
b2;
451 sint = y * (
b0 -
b2);
458 h__ = two * (d__1 * d__1) - one;
462 for (i__ = 22; i__ >= 0; --i__) {
470 for (i__ = 19; i__ >= 0; --i__) {
477 cint = r__ * (qq *
sin(x) - r__ *
pp *
cos(x));
482 sint = d__1 - r__ * (r__ *
pp *
sin(x) + qq *
cos(x));
489 const double zero = 0.;
490 const double q2[7] = {
491 .10340013040487, 3.319092135933, 20.449478501379, 41.280784189142, 32.426421069514, 10.041164382905, 1.};
492 const double p3[6] = {
493 -2.3909964453136, -147.98219500504, -254.3763397689, -119.55761038372, -19.630408535939, -.9999999999036};
494 const double q3[6] = {177.60070940351, 530.68509610812, 462.23027156148, 156.81843364539, 21.630408494238, 1.};
495 const double p4[8] = {-8.6693733995107,
503 const double q4[8] = {34.171875,
511 const double a1[8] = {-2.1808638152072,
519 const double b1[8] = {0.,
527 const double a2[8] = {-3.4833465360285,
535 const double b2[8] = {0.,
543 const double a3[6] = {
544 -27.780928934438, -10.10479081576, -9.1483008216736, -5.0223317461851, -3.0000077799358, 1.0000000000704};
545 const double one = 1.;
546 const double b3[6] = {0., 122.39993926823, 2.7276100778779, -7.1897518395045, -2.9990118065262, 1.999999942826};
547 const double two = 2.;
548 const double three = 3.;
549 const double x0 = .37250741078137;
550 const double xl[6] = {-24., -12., -6., 0., 1., 4.};
551 const double p1[5] = {4.293125234321, 39.894153870321, 292.52518866921, 425.69682638592, -434.98143832952};
552 const double q1[5] = {1., 18.899288395003, 150.95038744251, 568.05252718987, 753.58564359843};
553 const double p2[7] = {.43096783946939,
562 double v, y, ap, bp, aq,
dp, bq, dq;
566 for (
int i__ = 2; i__ <= 5; ++i__) {
568 ap = a3[i__ - 1] - x +
b3[i__ - 1] / ap;
570 y =
exp(-x) / x * (one - (a3[5] +
b3[5] / ap) / x);
571 }
else if (x <= xl[1]) {
573 for (
int i__ = 2; i__ <= 7; ++i__) {
574 ap =
a2[i__ - 1] - x +
b2[i__ - 1] / ap;
576 y =
exp(-x) / x * (
a2[7] +
b2[7] / ap);
577 }
else if (x <= xl[2]) {
579 for (
int i__ = 2; i__ <= 7; ++i__) {
580 ap = a1[i__ - 1] - x +
b1[i__ - 1] / ap;
582 y =
exp(-x) / x * (a1[7] +
b1[7] / ap);
583 }
else if (x < xl[3]) {
584 v = -two * (x / three + one);
587 for (
int i__ = 2; i__ <= 8; ++i__) {
590 dp =
p4[i__ - 1] - ap +
v * bp;
594 for (
int i__ = 2; i__ <= 8; ++i__) {
597 dq = q4[i__ - 1] - aq +
v * bq;
599 y = -
log(-x / x0) + (x + x0) * (
dp - ap) / (dq - aq);
600 }
else if (x == xl[3]) {
602 }
else if (x < xl[4]) {
605 for (
int i__ = 2; i__ <= 5; ++i__) {
606 ap =
p1[i__ - 1] + x * ap;
607 aq =
q1[i__ - 1] + x * aq;
609 y = -
log(x) + ap / aq;
610 }
else if (x <= xl[5]) {
614 for (
int i__ = 2; i__ <= 7; ++i__) {
615 ap =
p2[i__ - 1] + y * ap;
616 aq =
q2[i__ - 1] + y * aq;
618 y =
exp(-x) * ap / aq;
623 for (
int i__ = 2; i__ <= 6; ++i__) {
624 ap =
p3[i__ - 1] + y * ap;
625 aq = q3[i__ - 1] + y * aq;
627 y =
exp(-x) * y * (one + y * ap / aq);
632 template <
typename F>
633 int dzero(
double a,
double b,
double& x0,
double& rv,
double eps,
int mxf,
F func) {
635 double d__1, d__2, d__3, d__4;
638 double f1,
f2, f3,
u1,
u2,
x1,
x2,
u3, u4, x3, ca, cb,
cc,
fa,
fb, ee,
ff;
640 double xa, xb,
fx,
xx, su4;
655 ee = eps * (fabs(x0) + 1);
669 rv = (d__1 = xb - xa, fabs(d__1)) * -.5;
685 if (
u2 == 0. || u4 == 0.) {
712 if (x0 < xa || x0 > xb) {
716 d__3 = (d__1 = x0 - x3, fabs(d__1)), d__4 = (d__2 = x0 -
x2, fabs(d__2));
718 ee = eps * (fabs(x0) + 1);
756 rv = (d__1 = xb - xa, fabs(d__1)) * -.5;