source: sasmodels/sasmodels/models/lib/sas_J1.c @ 0278e3f

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 0278e3f was 0278e3f, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

remove opencl compiler warnings; maybe fix build server breakage

  • Property mode set to 100644
File size: 4.4 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
42constant double RPJ1[8] = {
43    -8.99971225705559398224E8,
44    4.52228297998194034323E11,
45    -7.27494245221818276015E13,
46    3.68295732863852883286E15,
47    0.0,
48    0.0,
49    0.0,
50    0.0 };
51
52constant double RQJ1[8] = {
53    6.20836478118054335476E2,
54    2.56987256757748830383E5,
55    8.35146791431949253037E7,
56    2.21511595479792499675E10,
57    4.74914122079991414898E12,
58    7.84369607876235854894E14,
59    8.95222336184627338078E16,
60    5.32278620332680085395E18
61    };
62
63constant double PPJ1[8] = {
64    7.62125616208173112003E-4,
65    7.31397056940917570436E-2,
66    1.12719608129684925192E0,
67    5.11207951146807644818E0,
68    8.42404590141772420927E0,
69    5.21451598682361504063E0,
70    1.00000000000000000254E0,
71    0.0} ;
72
73
74constant double PQJ1[8] = {
75    5.71323128072548699714E-4,
76    6.88455908754495404082E-2,
77    1.10514232634061696926E0,
78    5.07386386128601488557E0,
79    8.39985554327604159757E0,
80    5.20982848682361821619E0,
81    9.99999999999999997461E-1,
82    0.0 };
83
84constant double QPJ1[8] = {
85    5.10862594750176621635E-2,
86    4.98213872951233449420E0,
87    7.58238284132545283818E1,
88    3.66779609360150777800E2,
89    7.10856304998926107277E2,
90    5.97489612400613639965E2,
91    2.11688757100572135698E2,
92    2.52070205858023719784E1 };
93
94constant double QQJ1[8] = {
95    7.42373277035675149943E1,
96    1.05644886038262816351E3,
97    4.98641058337653607651E3,
98    9.56231892404756170795E3,
99    7.99704160447350683650E3,
100    2.82619278517639096600E3,
101    3.36093607810698293419E2,
102    0.0 };
103
104constant double JPJ1[8] = {
105    -4.878788132172128E-009,
106    6.009061827883699E-007,
107    -4.541343896997497E-005,
108    1.937383947804541E-003,
109    -3.405537384615824E-002,
110    0.0,
111    0.0,
112    0.0
113    };
114
115constant double MO1J1[8] = {
116    6.913942741265801E-002,
117    -2.284801500053359E-001,
118    3.138238455499697E-001,
119    -2.102302420403875E-001,
120    5.435364690523026E-003,
121    1.493389585089498E-001,
122    4.976029650847191E-006,
123    7.978845453073848E-001
124    };
125
126constant double PH1J1[8] = {
127    -4.497014141919556E+001,
128    5.073465654089319E+001,
129    -2.485774108720340E+001,
130    7.222973196770240E+000,
131    -1.544842782180211E+000,
132    3.503787691653334E-001,
133    -1.637986776941202E-001,
134    3.749989509080821E-001
135    };
136
137double sas_J1(double x);
138double sas_J1(double x)
139{
140
141//Cephes double pression function
142#if FLOAT_SIZE>4
143
144    double w, z, p, q, xn;
145
146    const double Z1 = 1.46819706421238932572E1;
147    const double Z2 = 4.92184563216946036703E1;
148    const double THPIO4 =  2.35619449019234492885;
149    const double SQ2OPI = 0.79788456080286535588;
150
151    w = x;
152    if( x < 0 )
153            w = -x;
154
155    if( w <= 5.0 )
156        {
157            z = x * x;
158            w = polevl( z, RPJ1, 3 ) / p1evl( z, RQJ1, 8 );
159            w = w * x * (z - Z1) * (z - Z2);
160            return( w );
161        }
162
163    w = 5.0/x;
164    z = w * w;
165
166    p = polevl( z, PPJ1, 6)/polevl( z, PQJ1, 6 );
167    q = polevl( z, QPJ1, 7)/p1evl( z, QQJ1, 7 );
168
169    xn = x - THPIO4;
170
171    double sn, cn;
172    SINCOS(xn, sn, cn);
173    p = p * cn - w * q * sn;
174
175    return( p * SQ2OPI / sqrt(x) );
176
177
178//Single precission version of cephes
179#else
180    double xx, w, z, p, q, xn;
181
182    const double Z1 = 1.46819706421238932572E1;
183    const double THPIO4F =  2.35619449019234492885;    /* 3*pi/4 */
184
185
186    xx = x;
187    if( xx < 0 )
188            xx = -x;
189
190    if( xx <= 2.0 )
191        {
192            z = xx * xx;
193            p = (z-Z1) * xx * polevl( z, JPJ1, 4 );
194            return( p );
195        }
196
197    q = 1.0/x;
198    w = sqrt(q);
199
200    p = w * polevl( q, MO1J1, 7);
201    w = q*q;
202    xn = q * polevl( w, PH1J1, 7) - THPIO4F;
203    p = p * cos(xn + xx);
204
205    return(p);
206#endif
207}
208
209//Finally J1c function that equals 2*J1(x)/x
210double sas_J1c(double x);
211double sas_J1c(double x)
212{
213    return (x != 0.0 ) ? 2.0*sas_J1(x)/x : 1.0;
214}
Note: See TracBrowser for help on using the repository browser.