var besseli/*:BesselF*/ = (function() { var b0_a = [1.0, 3.5156229, 3.0899424, 1.2067492, 0.2659732, 0.360768e-1, 0.45813e-2].reverse(); var b0_b = [0.39894228, 0.1328592e-1, 0.225319e-2, -0.157565e-2, 0.916281e-2, -0.2057706e-1, 0.2635537e-1, -0.1647633e-1, 0.392377e-2].reverse(); function bessel0(x/*:number*/)/*:number*/ { if(x <= 3.75) return _horner(b0_a, x*x/(3.75*3.75)); return M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b0_b, 3.75/M.abs(x)); } var b1_a = [0.5, 0.87890594, 0.51498869, 0.15084934, 0.2658733e-1, 0.301532e-2, 0.32411e-3].reverse(); var b1_b = [0.39894228, -0.3988024e-1, -0.362018e-2, 0.163801e-2, -0.1031555e-1, 0.2282967e-1, -0.2895312e-1, 0.1787654e-1, -0.420059e-2].reverse(); function bessel1(x/*:number*/)/*:number*/ { if(x < 3.75) return x * _horner(b1_a, x*x/(3.75*3.75)); return (x < 0 ? -1 : 1) * M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b1_b, 3.75/M.abs(x)); } return function besseli(x/*:number*/, n/*:number*/)/*:number*/ { n = Math.round(n); if(n === 0) return bessel0(x); if(n === 1) return bessel1(x); if(n < 0) return NaN; if(M.abs(x) === 0) return 0; if(x == Infinity) return Infinity; var ret = 0.0, j, tox = 2 / M.abs(x), bip = 0.0, bi=1.0, bim=0.0; var m=2*M.round((n+M.round(M.sqrt(40*n)))/2); for (j=m;j>0;j--) { bim=j*tox*bi + bip; bip=bi; bi=bim; if (M.abs(bi) > 1E10) { bi *= 1E-10; bip *= 1E-10; ret *= 1E-10; } if(j == n) ret = bip; } ret *= besseli(x, 0) / bi; return x < 0 && (n%2) ? -ret : ret; }; })();