source: sasmodels/sasmodels/models/lib/j0_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 094e320, checked in by wojciech, 8 years ago

Fixed cosf and sqrtf

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*                                                      j0.c
2 *
3 *      Bessel function of order zero
4 *
5 *
6 *
7 * SYNOPSIS:
8 *
9 * double x, y, j0();
10 *
11 * y = j0( x );
12 *
13 *
14 *
15 * DESCRIPTION:
16 *
17 * Returns Bessel function of order zero of the argument.
18 *
19 * The domain is divided into the intervals [0, 5] and
20 * (5, infinity). In the first interval the following rational
21 * approximation is used:
22 *
23 *
24 *        2         2
25 * (w - r  ) (w - r  ) P (w) / Q (w)
26 *       1         2    3       8
27 *
28 *            2
29 * where w = x  and the two r's are zeros of the function.
30 *
31 * In the second interval, the Hankel asymptotic expansion
32 * is employed with two rational functions of degree 6/6
33 * and 7/7.
34 *
35 *
36 *
37 * ACCURACY:
38 *
39 *                      Absolute error:
40 * arithmetic   domain     # trials      peak         rms
41 *    DEC       0, 30       10000       4.4e-17     6.3e-18
42 *    IEEE      0, 30       60000       4.2e-16     1.1e-16
43 *
44 */
45
46/*
47Cephes Math Library Release 2.8:  June, 2000
48Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
49*/
50
51/* Note: all coefficients satisfy the relative error criterion
52 * except YP, YQ which are designed for absolute error. */
53
54double j0( double );
55double j0(double x) {
56
57//Cephes single precission
58#if FLOAT_SIZE>4
59    double w, z, p, q, xn;
60
61    const double TWOOPI = 6.36619772367581343075535E-1;
62    const double SQ2OPI = 7.9788456080286535587989E-1;
63    const double PIO4 = 7.85398163397448309616E-1;
64
65    const double DR1 = 5.78318596294678452118E0;
66    const double DR2 = 3.04712623436620863991E1;
67
68    const double PP[8] = {
69        7.96936729297347051624E-4,
70        8.28352392107440799803E-2,
71        1.23953371646414299388E0,
72        5.44725003058768775090E0,
73        8.74716500199817011941E0,
74        5.30324038235394892183E0,
75        9.99999999999999997821E-1,
76        0.0
77    };
78
79    const double PQ[8] = {
80        9.24408810558863637013E-4,
81        8.56288474354474431428E-2,
82        1.25352743901058953537E0,
83        5.47097740330417105182E0,
84        8.76190883237069594232E0,
85        5.30605288235394617618E0,
86        1.00000000000000000218E0,
87        0.0
88    };
89
90    const double QP[8] = {
91        -1.13663838898469149931E-2,
92        -1.28252718670509318512E0,
93        -1.95539544257735972385E1,
94        -9.32060152123768231369E1,
95        -1.77681167980488050595E2,
96        -1.47077505154951170175E2,
97        -5.14105326766599330220E1,
98        -6.05014350600728481186E0,
99    };
100
101    const double QQ[8] = {
102        /*  1.00000000000000000000E0,*/
103        6.43178256118178023184E1,
104        8.56430025976980587198E2,
105        3.88240183605401609683E3,
106        7.24046774195652478189E3,
107        5.93072701187316984827E3,
108        2.06209331660327847417E3,
109        2.42005740240291393179E2,
110    };
111
112    const double YP[8] = {
113        1.55924367855235737965E4,
114        -1.46639295903971606143E7,
115        5.43526477051876500413E9,
116        -9.82136065717911466409E11,
117        8.75906394395366999549E13,
118        -3.46628303384729719441E15,
119        4.42733268572569800351E16,
120        -1.84950800436986690637E16,
121    };
122
123    const double YQ[7] = {
124        /* 1.00000000000000000000E0,*/
125        1.04128353664259848412E3,
126        6.26107330137134956842E5,
127        2.68919633393814121987E8,
128        8.64002487103935000337E10,
129        2.02979612750105546709E13,
130        3.17157752842975028269E15,
131        2.50596256172653059228E17,
132    };
133
134    const double RP[8] = {
135        -4.79443220978201773821E9,
136        1.95617491946556577543E12,
137        -2.49248344360967716204E14,
138        9.70862251047306323952E15,
139        0.0,
140        0.0,
141        0.0,
142        0.0
143    };
144
145    const double RQ[8] = {
146        /* 1.00000000000000000000E0,*/
147        4.99563147152651017219E2,
148        1.73785401676374683123E5,
149        4.84409658339962045305E7,
150        1.11855537045356834862E10,
151        2.11277520115489217587E12,
152        3.10518229857422583814E14,
153        3.18121955943204943306E16,
154        1.71086294081043136091E18,
155    };
156
157    if( x < 0 )
158            x = -x;
159
160    if( x <= 5.0 ) {
161            z = x * x;
162            if( x < 1.0e-5 )
163                    return( 1.0 - z/4.0 );
164
165            p = (z - DR1) * (z - DR2);
166            p = p * polevl( z, RP, 3)/p1evl( z, RQ, 8 );
167            return( p );
168        }
169
170    w = 5.0/x;
171    q = 25.0/(x*x);
172    p = polevl( q, PP, 6)/polevl( q, PQ, 6 );
173    q = polevl( q, QP, 7)/p1evl( q, QQ, 7 );
174    xn = x - PIO4;
175
176    double sn, cn;
177    SINCOS(xn, sn, cn);
178    p = p * cn - w * q * sn;
179
180    return( p * SQ2OPI / sqrt(x) );
181//Cephes single precission
182#else
183    double xx, w, z, p, q, xn;
184
185    const double YZ1 =  0.43221455686510834878;
186    const double YZ2 = 22.401876406482861405;
187    const double YZ3 = 64.130620282338755553;
188    const double DR1 =  5.78318596294678452118;
189    const double PIO4F = 0.7853981633974483096;
190
191    double MO[8] = {
192        -6.838999669318810E-002,
193        1.864949361379502E-001,
194        -2.145007480346739E-001,
195        1.197549369473540E-001,
196        -3.560281861530129E-003,
197        -4.969382655296620E-002,
198        -3.355424622293709E-006,
199        7.978845717621440E-001
200    };
201
202    double PH[8] = {
203        3.242077816988247E+001,
204        -3.630592630518434E+001,
205        1.756221482109099E+001,
206        -4.974978466280903E+000,
207        1.001973420681837E+000,
208        -1.939906941791308E-001,
209        6.490598792654666E-002,
210        -1.249992184872738E-001
211    };
212
213    double YP[8] = {
214        9.454583683980369E-008,
215        -9.413212653797057E-006,
216        5.344486707214273E-004,
217        -1.584289289821316E-002,
218        1.707584643733568E-001,
219        0.0,
220        0.0,
221        0.0
222    };
223
224    double JP[8] = {
225        -6.068350350393235E-008,
226        6.388945720783375E-006,
227        -3.969646342510940E-004,
228        1.332913422519003E-002,
229        -1.729150680240724E-001,
230        0.0,
231        0.0,
232        0.0
233    };
234
235    if( x < 0 )
236            xx = -x;
237    else
238            xx = x;
239
240    if( x <= 2.0 ) {
241            z = xx * xx;
242            if( x < 1.0e-3 )
243                    return( 1.0 - 0.25*z );
244
245            p = (z-DR1) * polevl( z, JP, 4);
246            return( p );
247        }
248
249    q = 1.0/x;
250    w = sqrt(q);
251
252    p = w * polevl( q, MO, 7);
253    w = q*q;
254    xn = q * polevl( w, PH, 7) - PIO4F;
255    p = p * cos(xn + xx);
256    return(p);
257#endif
258
259}
260
Note: See TracBrowser for help on using the repository browser.