75 #define SMALL_J0_BOUND 1e6
78 #define SMALL_JN_BOUND 5.0
81 #define BIG_JN_BOUND 25.0
84 #define MAX_SMALL_ITERATION 2048
114 ak =
pow (0.5 * z, n);
118 return n > 0 ? 0.0 : 1;
130 ak = -(z * z) / (4.0 * k * (n + k));
132 if (fabs (
real (Rk)) < fabs (
real (R) * NR_EPSI) &&
133 fabs (
imag (Rk)) < fabs (
imag (R) * NR_EPSI))
139 assert (k < MAX_SMALL_ITERATION);
158 m1pna2 = (n / 2) % 2 == 0 ? 1.0 : -1.0;
159 first = (1.0 + m1pna2 *
cos (z)) / (2.0 * m);
162 for (k = 1; k <= m - 1; k++)
164 t = (k *
M_PI) / (2 * m);
168 return first + second / (nr_double_t) m;
185 m1pn1a2 = ((n - 1) / 2) % 2 == 0 ? 1.0 : -1.0;
186 first = (m1pn1a2 *
sin (z)) / (2.0 * m);
189 for (k = 1; k <= m - 1; k++)
191 t = (k *
M_PI) / (2 * m);
195 return first + second / (nr_double_t) m;
211 #define MAX_LARGE_ITERATION 430
222 unsigned long num, denum;
232 Q0 = (4.0 * n * n - 1) / (8.0 * z);
236 m1a8z2 = (-1.0) / (8.0 *
sqr (z));
244 num = (4 *
sqr (n) -
sqr (4 * k - 3)) * (4 *
sqr (n) - (4 * k - 1));
245 denum = 2 * k * (2 * k - 1);
246 Pk = Pk * ((nr_double_t) num * m1a8z2) / ((nr_double_t) denum);
248 if (
real (Pk) <
real (P0) * NR_EPSI &&
261 num = (4 *
sqr (n) -
sqr (4 * k - 1)) * (4 *
sqr (n) - (4 * k - 1));
262 denum = 2 * k * (2 * k - 1);
263 Qk = Qk * ((nr_double_t) num * m1a8z2) / ((nr_double_t) denum);
265 if (
real (Qk) <
real (Q0) * NR_EPSI ||
273 l = (n % 4 == 0) || (n % 4 == 3) ? 1.0 : -1.0;
274 m = (n % 4 == 0) || (n % 4 == 1) ? 1.0 : -1.0;
277 tmp = (l * P + m * Q_) *
cos (z);
278 tmp += (m * P - l * Q_) *
sin (z);
288 nr_double_t mul = 1.0;
static nr_complex_t cbesselj_largearg(unsigned int n, nr_complex_t z)
besselj for large argument
std::complex< nr_double_t > nr_complex_t
matrix real(matrix a)
Real part matrix.
matrix abs(matrix a)
Computes magnitude of each matrix element.
static nr_complex_t cbesselj_smallarg(unsigned int n, nr_complex_t z)
static nr_complex_t cbesselj_mediumarg_odd(unsigned int n, nr_complex_t z)
nr_complex_t pow(const nr_complex_t z, const nr_double_t d)
Compute power function with real exponent.
nr_complex_t cos(const nr_complex_t z)
Compute complex cosine.
#define MAX_LARGE_ITERATION
num of P(k) (n = 8) will overlow above this value
#define SMALL_JN_BOUND
use ascending serie below this magnitude
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
matrix imag(matrix a)
Imaginary part matrix.
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
#define BIG_JN_BOUND
use assymptotic expression above this magnitude
nr_complex_t sin(const nr_complex_t z)
Compute complex sine.
nr_complex_t cbesselj(unsigned int n, nr_complex_t z)
Main entry point for besselj function.
static nr_complex_t cbesselj_mediumarg(unsigned int n, nr_complex_t z)
#define M_PI
Archimedes' constant ( )
#define MAX_SMALL_ITERATION
Arbitrary value for iteration.
unsigned int factorial(unsigned int n)
Compute factorial n ie $n!$.
static nr_complex_t cbesselj_mediumarg_even(unsigned int n, nr_complex_t z)