source: sasview/src/sas/models/c_extension/cephes/i1.c @ 0aa3a1b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 0aa3a1b was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 9.0 KB
Line 
1/*                                                      i1.c
2 *
3 *      Modified Bessel function of order one
4 *
5 *
6 *
7 * SYNOPSIS:
8 *
9 * double x, y, i1();
10 *
11 * y = i1( x );
12 *
13 *
14 *
15 * DESCRIPTION:
16 *
17 * Returns modified Bessel function of order one of the
18 * argument.
19 *
20 * The function is defined as i1(x) = -i j1( ix ).
21 *
22 * The range is partitioned into the two intervals [0,8] and
23 * (8, infinity).  Chebyshev polynomial expansions are employed
24 * in each interval.
25 *
26 *
27 *
28 * ACCURACY:
29 *
30 *                      Relative error:
31 * arithmetic   domain     # trials      peak         rms
32 *    DEC       0, 30        3400       1.2e-16     2.3e-17
33 *    IEEE      0, 30       30000       1.9e-15     2.1e-16
34 *
35 *
36 */
37/*                                                     i1e.c
38 *
39 *      Modified Bessel function of order one,
40 *      exponentially scaled
41 *
42 *
43 *
44 * SYNOPSIS:
45 *
46 * double x, y, i1e();
47 *
48 * y = i1e( x );
49 *
50 *
51 *
52 * DESCRIPTION:
53 *
54 * Returns exponentially scaled modified Bessel function
55 * of order one of the argument.
56 *
57 * The function is defined as i1(x) = -i exp(-|x|) j1( ix ).
58 *
59 *
60 *
61 * ACCURACY:
62 *
63 *                      Relative error:
64 * arithmetic   domain     # trials      peak         rms
65 *    IEEE      0, 30       30000       2.0e-15     2.0e-16
66 * See i1().
67 *
68 */
69
70/*                                                      i1.c 2          */
71
72
73/*
74Cephes Math Library Release 2.8:  June, 2000
75Copyright 1985, 1987, 2000 by Stephen L. Moshier
76*/
77
78#include "mconf.h"
79
80/* Chebyshev coefficients for exp(-x) I1(x) / x
81 * in the interval [0,8].
82 *
83 * lim(x->0){ exp(-x) I1(x) / x } = 1/2.
84 */
85
86#ifdef UNK
87static double A[] =
88{
89 2.77791411276104639959E-18,
90-2.11142121435816608115E-17,
91 1.55363195773620046921E-16,
92-1.10559694773538630805E-15,
93 7.60068429473540693410E-15,
94-5.04218550472791168711E-14,
95 3.22379336594557470981E-13,
96-1.98397439776494371520E-12,
97 1.17361862988909016308E-11,
98-6.66348972350202774223E-11,
99 3.62559028155211703701E-10,
100-1.88724975172282928790E-9,
101 9.38153738649577178388E-9,
102-4.44505912879632808065E-8,
103 2.00329475355213526229E-7,
104-8.56872026469545474066E-7,
105 3.47025130813767847674E-6,
106-1.32731636560394358279E-5,
107 4.78156510755005422638E-5,
108-1.61760815825896745588E-4,
109 5.12285956168575772895E-4,
110-1.51357245063125314899E-3,
111 4.15642294431288815669E-3,
112-1.05640848946261981558E-2,
113 2.47264490306265168283E-2,
114-5.29459812080949914269E-2,
115 1.02643658689847095384E-1,
116-1.76416518357834055153E-1,
117 2.52587186443633654823E-1
118};
119#endif
120
121#ifdef DEC
122static unsigned short A[] = {
1230021514,0174520,0060742,0000241,
1240122302,0137206,0016120,0025663,
1250023063,0017437,0026235,0176536,
1260123637,0052523,0170150,0125632,
1270024410,0165770,0030251,0044134,
1280125143,0012160,0162170,0054727,
1290025665,0075702,0035716,0145247,
1300126413,0116032,0176670,0015462,
1310027116,0073425,0110351,0105242,
1320127622,0104034,0137530,0037364,
1330030307,0050645,0120776,0175535,
1340131001,0130331,0043523,0037455,
1350031441,0026160,0010712,0100174,
1360132076,0164761,0022706,0017500,
1370032527,0015045,0115076,0104076,
1380133146,0001714,0015434,0144520,
1390033550,0161166,0124215,0077050,
1400134136,0127715,0143365,0157170,
1410034510,0106652,0013070,0064130,
1420135051,0117126,0117264,0123761,
1430035406,0045355,0133066,0175751,
1440135706,0061420,0054746,0122440,
1450036210,0031232,0047235,0006640,
1460136455,0012373,0144235,0011523,
1470036712,0107437,0036731,0015111,
1480137130,0156742,0115744,0172743,
1490037322,0033326,0124667,0124740,
1500137464,0123210,0021510,0144556,
1510037601,0051433,0111123,0177721
152};
153#endif
154
155#ifdef IBMPC
156static unsigned short A[] = {
1570x4014,0x0c3c,0x9f2a,0x3c49,
1580x0576,0xc38a,0x57d0,0xbc78,
1590xbfac,0xe593,0x63e3,0x3ca6,
1600x1573,0x7e0d,0xeaaa,0xbcd3,
1610x290c,0x0615,0x1d7f,0x3d01,
1620x0b3b,0x1c8f,0x628e,0xbd2c,
1630xd955,0x4779,0xaf78,0x3d56,
1640x0366,0x5fb7,0x7383,0xbd81,
1650x3154,0xb21d,0xcee2,0x3da9,
1660x07de,0x97eb,0x5103,0xbdd2,
1670xdf6c,0xb43f,0xea34,0x3df8,
1680x67e6,0x28ea,0x361b,0xbe20,
1690x5010,0x0239,0x258e,0x3e44,
1700xc3e8,0x24b8,0xdd3e,0xbe67,
1710xd108,0xb347,0xe344,0x3e8a,
1720x992a,0x8363,0xc079,0xbeac,
1730xafc5,0xd511,0x1c4e,0x3ecd,
1740xbbcf,0xb8de,0xd5f9,0xbeeb,
1750x0d0b,0x42c7,0x11b5,0x3f09,
1760x94fe,0xd3d6,0x33ca,0xbf25,
1770xdf7d,0xb6c6,0xc95d,0x3f40,
1780xd4a4,0x0b3c,0xcc62,0xbf58,
1790xa1b4,0x49d3,0x0653,0x3f71,
1800xa26a,0x7913,0xa29f,0xbf85,
1810x2349,0xe7bb,0x51e3,0x3f99,
1820x9ebc,0x537c,0x1bbc,0xbfab,
1830xf53c,0xd536,0x46da,0x3fba,
1840x192e,0x0469,0x94d1,0xbfc6,
1850x7ffa,0x724a,0x2a63,0x3fd0
186};
187#endif
188
189#ifdef MIEEE
190static unsigned short A[] = {
1910x3c49,0x9f2a,0x0c3c,0x4014,
1920xbc78,0x57d0,0xc38a,0x0576,
1930x3ca6,0x63e3,0xe593,0xbfac,
1940xbcd3,0xeaaa,0x7e0d,0x1573,
1950x3d01,0x1d7f,0x0615,0x290c,
1960xbd2c,0x628e,0x1c8f,0x0b3b,
1970x3d56,0xaf78,0x4779,0xd955,
1980xbd81,0x7383,0x5fb7,0x0366,
1990x3da9,0xcee2,0xb21d,0x3154,
2000xbdd2,0x5103,0x97eb,0x07de,
2010x3df8,0xea34,0xb43f,0xdf6c,
2020xbe20,0x361b,0x28ea,0x67e6,
2030x3e44,0x258e,0x0239,0x5010,
2040xbe67,0xdd3e,0x24b8,0xc3e8,
2050x3e8a,0xe344,0xb347,0xd108,
2060xbeac,0xc079,0x8363,0x992a,
2070x3ecd,0x1c4e,0xd511,0xafc5,
2080xbeeb,0xd5f9,0xb8de,0xbbcf,
2090x3f09,0x11b5,0x42c7,0x0d0b,
2100xbf25,0x33ca,0xd3d6,0x94fe,
2110x3f40,0xc95d,0xb6c6,0xdf7d,
2120xbf58,0xcc62,0x0b3c,0xd4a4,
2130x3f71,0x0653,0x49d3,0xa1b4,
2140xbf85,0xa29f,0x7913,0xa26a,
2150x3f99,0x51e3,0xe7bb,0x2349,
2160xbfab,0x1bbc,0x537c,0x9ebc,
2170x3fba,0x46da,0xd536,0xf53c,
2180xbfc6,0x94d1,0x0469,0x192e,
2190x3fd0,0x2a63,0x724a,0x7ffa
220};
221#endif
222
223/*                                                      i1.c    */
224
225/* Chebyshev coefficients for exp(-x) sqrt(x) I1(x)
226 * in the inverted interval [8,infinity].
227 *
228 * lim(x->inf){ exp(-x) sqrt(x) I1(x) } = 1/sqrt(2pi).
229 */
230
231#ifdef UNK
232static double B[] =
233{
234 7.51729631084210481353E-18,
235 4.41434832307170791151E-18,
236-4.65030536848935832153E-17,
237-3.20952592199342395980E-17,
238 2.96262899764595013876E-16,
239 3.30820231092092828324E-16,
240-1.88035477551078244854E-15,
241-3.81440307243700780478E-15,
242 1.04202769841288027642E-14,
243 4.27244001671195135429E-14,
244-2.10154184277266431302E-14,
245-4.08355111109219731823E-13,
246-7.19855177624590851209E-13,
247 2.03562854414708950722E-12,
248 1.41258074366137813316E-11,
249 3.25260358301548823856E-11,
250-1.89749581235054123450E-11,
251-5.58974346219658380687E-10,
252-3.83538038596423702205E-9,
253-2.63146884688951950684E-8,
254-2.51223623787020892529E-7,
255-3.88256480887769039346E-6,
256-1.10588938762623716291E-4,
257-9.76109749136146840777E-3,
258 7.78576235018280120474E-1
259};
260#endif
261
262#ifdef DEC
263static unsigned short B[] = {
2640022012,0125555,0115227,0043456,
2650021642,0156127,0052075,0145203,
2660122526,0072435,0111231,0011664,
2670122424,0001544,0161671,0114403,
2680023252,0144257,0163532,0142121,
2690023276,0132162,0174045,0013204,
2700124007,0077154,0057046,0110517,
2710124211,0066650,0116127,0157073,
2720024473,0133413,0130551,0107504,
2730025100,0064741,0032631,0040364,
2740124675,0045101,0071551,0012400,
2750125745,0161054,0071637,0011247,
2760126112,0117410,0035525,0122231,
2770026417,0037237,0131034,0176427,
2780027170,0100373,0024742,0025725,
2790027417,0006417,0105303,0141446,
2800127246,0163716,0121202,0060137,
2810130431,0123122,0120436,0166000,
2820131203,0144134,0153251,0124500,
2830131742,0005234,0122732,0033006,
2840132606,0157751,0072362,0121031,
2850133602,0043372,0047120,0015626,
2860134747,0165774,0001125,0046462,
2870136437,0166402,0117746,0155137,
2880040107,0050305,0125330,0124241
289};
290#endif
291
292#ifdef IBMPC
293static unsigned short B[] = {
2940xe8e6,0xb352,0x556d,0x3c61,
2950xb950,0xea87,0x5b8a,0x3c54,
2960x2277,0xb253,0xcea3,0xbc8a,
2970x3320,0x9c77,0x806c,0xbc82,
2980x588a,0xfceb,0x5915,0x3cb5,
2990xa2d1,0x5f04,0xd68e,0x3cb7,
3000xd22a,0x8bc4,0xefcd,0xbce0,
3010xfbc7,0x138a,0x2db5,0xbcf1,
3020x31e8,0x762d,0x76e1,0x3d07,
3030x281e,0x26b3,0x0d3c,0x3d28,
3040x22a0,0x2e6d,0xa948,0xbd17,
3050xe255,0x8e73,0xbc45,0xbd5c,
3060xb493,0x076a,0x53e1,0xbd69,
3070x9fa3,0xf643,0xe7d3,0x3d81,
3080x457b,0x653c,0x101f,0x3daf,
3090x7865,0xf158,0xe1a1,0x3dc1,
3100x4c0c,0xd450,0xdcf9,0xbdb4,
3110xdd80,0x5423,0x34ca,0xbe03,
3120x3528,0x9ad5,0x790b,0xbe30,
3130x46c1,0x94bb,0x4153,0xbe5c,
3140x5443,0x2e9e,0xdbfd,0xbe90,
3150x0373,0x49ca,0x48df,0xbed0,
3160xa9a6,0x804a,0xfd7f,0xbf1c,
3170xdb4c,0x53fc,0xfda0,0xbf83,
3180x1514,0xb55b,0xea18,0x3fe8
319};
320#endif
321
322#ifdef MIEEE
323static unsigned short B[] = {
3240x3c61,0x556d,0xb352,0xe8e6,
3250x3c54,0x5b8a,0xea87,0xb950,
3260xbc8a,0xcea3,0xb253,0x2277,
3270xbc82,0x806c,0x9c77,0x3320,
3280x3cb5,0x5915,0xfceb,0x588a,
3290x3cb7,0xd68e,0x5f04,0xa2d1,
3300xbce0,0xefcd,0x8bc4,0xd22a,
3310xbcf1,0x2db5,0x138a,0xfbc7,
3320x3d07,0x76e1,0x762d,0x31e8,
3330x3d28,0x0d3c,0x26b3,0x281e,
3340xbd17,0xa948,0x2e6d,0x22a0,
3350xbd5c,0xbc45,0x8e73,0xe255,
3360xbd69,0x53e1,0x076a,0xb493,
3370x3d81,0xe7d3,0xf643,0x9fa3,
3380x3daf,0x101f,0x653c,0x457b,
3390x3dc1,0xe1a1,0xf158,0x7865,
3400xbdb4,0xdcf9,0xd450,0x4c0c,
3410xbe03,0x34ca,0x5423,0xdd80,
3420xbe30,0x790b,0x9ad5,0x3528,
3430xbe5c,0x4153,0x94bb,0x46c1,
3440xbe90,0xdbfd,0x2e9e,0x5443,
3450xbed0,0x48df,0x49ca,0x0373,
3460xbf1c,0xfd7f,0x804a,0xa9a6,
3470xbf83,0xfda0,0x53fc,0xdb4c,
3480x3fe8,0xea18,0xb55b,0x1514
349};
350#endif
351
352/*                                                      i1.c    */
353#ifdef ANSIPROT
354extern double chbevl ( double, void *, int );
355extern double exp ( double );
356extern double sqrt ( double );
357extern double fabs ( double );
358#else
359double chbevl(), exp(), sqrt(), fabs();
360#endif
361
362double i1(x)
363double x;
364{ 
365double y, z;
366
367z = fabs(x);
368if( z <= 8.0 )
369        {
370        y = (z/2.0) - 2.0;
371        z = chbevl( y, A, 29 ) * z * exp(z);
372        }
373else
374        {
375        z = exp(z) * chbevl( 32.0/z - 2.0, B, 25 ) / sqrt(z);
376        }
377if( x < 0.0 )
378        z = -z;
379return( z );
380}
381
382/*                                                      i1e()   */
383
384double i1e( x )
385double x;
386{ 
387double y, z;
388
389z = fabs(x);
390if( z <= 8.0 )
391        {
392        y = (z/2.0) - 2.0;
393        z = chbevl( y, A, 29 ) * z;
394        }
395else
396        {
397        z = chbevl( 32.0/z - 2.0, B, 25 ) / sqrt(z);
398        }
399if( x < 0.0 )
400        z = -z;
401return( z );
402}
Note: See TracBrowser for help on using the repository browser.