source: sasmodels/sasmodels/models/lib/sas_J0.c @ ba32cdd

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

fix opencl compile; still doesn't run

  • Property mode set to 100644
File size: 5.8 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
51double sas_J0(double x);
52
53/* Note: all coefficients satisfy the relative error criterion
54 * except YP, YQ which are designed for absolute error. */
55
56
57 constant double PPJ0[8] = {
58        7.96936729297347051624E-4,
59        8.28352392107440799803E-2,
60        1.23953371646414299388E0,
61        5.44725003058768775090E0,
62        8.74716500199817011941E0,
63        5.30324038235394892183E0,
64        9.99999999999999997821E-1,
65        0.0
66    };
67
68 constant double PQJ0[8] = {
69        9.24408810558863637013E-4,
70        8.56288474354474431428E-2,
71        1.25352743901058953537E0,
72        5.47097740330417105182E0,
73        8.76190883237069594232E0,
74        5.30605288235394617618E0,
75        1.00000000000000000218E0,
76        0.0
77    };
78
79 constant double QPJ0[8] = {
80        -1.13663838898469149931E-2,
81        -1.28252718670509318512E0,
82        -1.95539544257735972385E1,
83        -9.32060152123768231369E1,
84        -1.77681167980488050595E2,
85        -1.47077505154951170175E2,
86        -5.14105326766599330220E1,
87        -6.05014350600728481186E0,
88    };
89
90 constant double QQJ0[8] = {
91        /*  1.00000000000000000000E0,*/
92        6.43178256118178023184E1,
93        8.56430025976980587198E2,
94        3.88240183605401609683E3,
95        7.24046774195652478189E3,
96        5.93072701187316984827E3,
97        2.06209331660327847417E3,
98        2.42005740240291393179E2,
99    };
100
101 constant double YPJ0[8] = {
102        1.55924367855235737965E4,
103        -1.46639295903971606143E7,
104        5.43526477051876500413E9,
105        -9.82136065717911466409E11,
106        8.75906394395366999549E13,
107        -3.46628303384729719441E15,
108        4.42733268572569800351E16,
109        -1.84950800436986690637E16,
110 };
111
112
113 constant double YQJ0[7] = {
114        /* 1.00000000000000000000E0,*/
115        1.04128353664259848412E3,
116        6.26107330137134956842E5,
117        2.68919633393814121987E8,
118        8.64002487103935000337E10,
119        2.02979612750105546709E13,
120        3.17157752842975028269E15,
121        2.50596256172653059228E17,
122  };
123
124 constant double RPJ0[8] = {
125        -4.79443220978201773821E9,
126        1.95617491946556577543E12,
127        -2.49248344360967716204E14,
128        9.70862251047306323952E15,
129        0.0,
130        0.0,
131        0.0,
132        0.0
133  };
134
135 constant double RQJ0[8] = {
136        /* 1.00000000000000000000E0,*/
137        4.99563147152651017219E2,
138        1.73785401676374683123E5,
139        4.84409658339962045305E7,
140        1.11855537045356834862E10,
141        2.11277520115489217587E12,
142        3.10518229857422583814E14,
143        3.18121955943204943306E16,
144        1.71086294081043136091E18,
145  };
146
147 constant double MOJ0[8] = {
148        -6.838999669318810E-002,
149        1.864949361379502E-001,
150        -2.145007480346739E-001,
151        1.197549369473540E-001,
152        -3.560281861530129E-003,
153        -4.969382655296620E-002,
154        -3.355424622293709E-006,
155        7.978845717621440E-001
156  };
157
158 constant double PHJ0[8] = {
159        3.242077816988247E+001,
160        -3.630592630518434E+001,
161        1.756221482109099E+001,
162        -4.974978466280903E+000,
163        1.001973420681837E+000,
164        -1.939906941791308E-001,
165        6.490598792654666E-002,
166        -1.249992184872738E-001
167  };
168
169 constant double JPJ0[8] = {
170        -6.068350350393235E-008,
171        6.388945720783375E-006,
172        -3.969646342510940E-004,
173        1.332913422519003E-002,
174        -1.729150680240724E-001,
175        0.0,
176        0.0,
177        0.0
178 };
179
180double sas_J0(double x)
181{
182
183//Cephes single precission
184#if FLOAT_SIZE>4
185    double w, z, p, q, xn;
186
187    //const double TWOOPI = 6.36619772367581343075535E-1;
188    const double SQ2OPI = 7.9788456080286535587989E-1;
189    const double PIO4 = 7.85398163397448309616E-1;
190
191    const double DR1 = 5.78318596294678452118E0;
192    const double DR2 = 3.04712623436620863991E1;
193
194
195    if( x < 0 )
196            x = -x;
197
198    if( x <= 5.0 ) {
199            z = x * x;
200            if( x < 1.0e-5 )
201                    return( 1.0 - z/4.0 );
202
203            p = (z - DR1) * (z - DR2);
204            p = p * polevl( z, RPJ0, 3)/p1evl( z, RQJ0, 8 );
205            return( p );
206        }
207
208    w = 5.0/x;
209    q = 25.0/(x*x);
210    p = polevl( q, PPJ0, 6)/polevl( q, PQJ0, 6 );
211    q = polevl( q, QPJ0, 7)/p1evl( q, QQJ0, 7 );
212    xn = x - PIO4;
213
214    double sn, cn;
215    SINCOS(xn, sn, cn);
216    p = p * cn - w * q * sn;
217
218    return( p * SQ2OPI / sqrt(x) );
219//Cephes single precission
220#else
221    double xx, w, z, p, q, xn;
222
223    //const double YZ1 =  0.43221455686510834878;
224    //const double YZ2 = 22.401876406482861405;
225    //const double YZ3 = 64.130620282338755553;
226    const double DR1 =  5.78318596294678452118;
227    const double PIO4F = 0.7853981633974483096;
228
229    if( x < 0 )
230            xx = -x;
231    else
232            xx = x;
233
234    if( x <= 2.0 ) {
235            z = xx * xx;
236            if( x < 1.0e-3 )
237                    return( 1.0 - 0.25*z );
238
239            p = (z-DR1) * polevl( z, JPJ0, 4);
240            return( p );
241        }
242
243    q = 1.0/x;
244    w = sqrt(q);
245
246    p = w * polevl( q, MOJ0, 7);
247    w = q*q;
248    xn = q * polevl( w, PHJ0, 7) - PIO4F;
249    p = p * cos(xn + xx);
250    return(p);
251#endif
252
253}
254
Note: See TracBrowser for help on using the repository browser.