source: sasmodels/sasmodels/models/lib/j1_cephes.c @ 95ce773

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 95ce773 was 95ce773, checked in by wojciech, 8 years ago

Bessel functions clean-up

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*                                                      j1.c
2 *
3 *      Bessel function of order one
4 *
5 *
6 *
7 * SYNOPSIS:
8 *
9 * double x, y, j1();
10 *
11 * y = j1( x );
12 *
13 *
14 *
15 * DESCRIPTION:
16 *
17 * Returns Bessel function of order one of the argument.
18 *
19 * The domain is divided into the intervals [0, 8] and
20 * (8, infinity). In the first interval a 24 term Chebyshev
21 * expansion is used. In the second, the asymptotic
22 * trigonometric representation is employed using two
23 * rational functions of degree 5/5.
24 *
25 *
26 *
27 * ACCURACY:
28 *
29 *                      Absolute error:
30 * arithmetic   domain      # trials      peak         rms
31 *    DEC       0, 30       10000       4.0e-17     1.1e-17
32 *    IEEE      0, 30       30000       2.6e-16     1.1e-16
33 *
34 *
35 */
36
37/*
38Cephes Math Library Release 2.8:  June, 2000
39Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
40*/
41
42double J1(double x) {
43
44//Cephes double pression function
45#if FLOAT_SIZE>4
46
47    double w, z, p, q, xn;
48
49    const double Z1 = 1.46819706421238932572E1;
50    const double Z2 = 4.92184563216946036703E1;
51    const double THPIO4 =  2.35619449019234492885;
52    const double SQ2OPI = 0.79788456080286535588;
53
54    w = x;
55    if( x < 0 )
56            w = -x;
57
58    if( w <= 5.0 )
59        {
60            z = x * x;
61            w = polevl( z, RPJ1, 3 ) / p1evl( z, RQJ1, 8 );
62            w = w * x * (z - Z1) * (z - Z2);
63            return( w );
64        }
65
66    w = 5.0/x;
67    z = w * w;
68
69    p = polevl( z, PPJ1, 6)/polevl( z, PQJ1, 6 );
70    q = polevl( z, QPJ1, 7)/p1evl( z, QQJ1, 7 );
71
72    xn = x - THPIO4;
73
74    double sn, cn;
75    SINCOS(xn, sn, cn);
76    p = p * cn - w * q * sn;
77
78    return( p * SQ2OPI / sqrt(x) );
79
80
81//Single precission version of cephes
82#else
83    double xx, w, z, p, q, xn;
84
85    const double Z1 = 1.46819706421238932572E1;
86    const double THPIO4F =  2.35619449019234492885;    /* 3*pi/4 */
87
88
89    xx = x;
90    if( xx < 0 )
91            xx = -x;
92
93    if( xx <= 2.0 )
94        {
95            z = xx * xx;
96            p = (z-Z1) * xx * polevl( z, JPJ1, 4 );
97            return( p );
98        }
99
100    q = 1.0/x;
101    w = sqrt(q);
102
103    p = w * polevl( q, MO1J1, 7);
104    w = q*q;
105    xn = q * polevl( w, PH1J1, 7) - THPIO4F;
106    p = p * cos(xn + xx);
107
108    return(p);
109#endif
110}
111
112//Finally J1c function that equals 2*J1(x)/x
113double J1c(double x) {
114    return (x != 0.0 ) ? 2.0*J1(x)/x : 1.0;
115}
Note: See TracBrowser for help on using the repository browser.