source: sasmodels/sasmodels/models/lib/j1_cephes.c @ 3b12dea

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

Polevl fixed

  • Property mode set to 100644
File size: 2.0 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*/
41double J1(double );
42
43double J1(double x) {
44
45//Cephes double pression function
46#if FLOAT_SIZE>4
47
48    double w, z, p, q, xn;
49
50    const double Z1 = 1.46819706421238932572E1;
51    const double Z2 = 4.92184563216946036703E1;
52    const double THPIO4 =  2.35619449019234492885;
53    const double SQ2OPI = 0.79788456080286535588;
54
55    w = x;
56    if( x < 0 )
57            w = -x;
58
59    if( w <= 5.0 )
60        {
61            z = x * x;
62            w = polevlRP( z, 3 ) / p1evlRQ( z, 8 );
63            w = w * x * (z - Z1) * (z - Z2);
64            return( w );
65        }
66
67    w = 5.0/x;
68    z = w * w;
69
70    p = polevlPP( z, 6)/polevlPQ( z, 6 );
71    q = polevlQP( z, 7)/p1evlQQ( z, 7 );
72
73    xn = x - THPIO4;
74
75    double sn, cn;
76    SINCOS(xn, sn, cn);
77    p = p * cn - w * q * sn;
78
79    return( p * SQ2OPI / sqrt(x) );
80
81
82//Single precission version of cephes
83#else
84    double xx, w, z, p, q, xn;
85
86    const double Z1 = 1.46819706421238932572E1;
87    const double THPIO4F =  2.35619449019234492885;    /* 3*pi/4 */
88
89
90    xx = x;
91    if( xx < 0 )
92            xx = -x;
93
94    if( xx <= 2.0 )
95        {
96            z = xx * xx;
97            p = (z-Z1) * xx * polevlJP( z, 4 );
98            return( p );
99        }
100
101    q = 1.0/x;
102    w = sqrt(q);
103
104    p = w * polevlMO1( q, 7);
105    w = q*q;
106    xn = q * polevlPH1( w, 7) - THPIO4F;
107    p = p * cos(xn + xx);
108
109    return(p);
110#endif
111}
Note: See TracBrowser for help on using the repository browser.