source: sasview/src/sas/models/c_extension/cephes/i0.c @ 50a77df

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 50a77df 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: 8.9 KB
Line 
1/*                                                      i0.c
2 *
3 *      Modified Bessel function of order zero
4 *
5 *
6 *
7 * SYNOPSIS:
8 *
9 * double x, y, i0();
10 *
11 * y = i0( x );
12 *
13 *
14 *
15 * DESCRIPTION:
16 *
17 * Returns modified Bessel function of order zero of the
18 * argument.
19 *
20 * The function is defined as i0(x) = j0( 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         6000       8.2e-17     1.9e-17
33 *    IEEE      0,30        30000       5.8e-16     1.4e-16
34 *
35 */
36/*                                                     i0e.c
37 *
38 *      Modified Bessel function of order zero,
39 *      exponentially scaled
40 *
41 *
42 *
43 * SYNOPSIS:
44 *
45 * double x, y, i0e();
46 *
47 * y = i0e( x );
48 *
49 *
50 *
51 * DESCRIPTION:
52 *
53 * Returns exponentially scaled modified Bessel function
54 * of order zero of the argument.
55 *
56 * The function is defined as i0e(x) = exp(-|x|) j0( ix ).
57 *
58 *
59 *
60 * ACCURACY:
61 *
62 *                      Relative error:
63 * arithmetic   domain     # trials      peak         rms
64 *    IEEE      0,30        30000       5.4e-16     1.2e-16
65 * See i0().
66 *
67 */
68
69/*                                                      i0.c            */
70
71
72/*
73Cephes Math Library Release 2.8:  June, 2000
74Copyright 1984, 1987, 2000 by Stephen L. Moshier
75*/
76
77#include "mconf.h"
78
79/* Chebyshev coefficients for exp(-x) I0(x)
80 * in the interval [0,8].
81 *
82 * lim(x->0){ exp(-x) I0(x) } = 1.
83 */
84
85#ifdef UNK
86static double A[] =
87{
88-4.41534164647933937950E-18,
89 3.33079451882223809783E-17,
90-2.43127984654795469359E-16,
91 1.71539128555513303061E-15,
92-1.16853328779934516808E-14,
93 7.67618549860493561688E-14,
94-4.85644678311192946090E-13,
95 2.95505266312963983461E-12,
96-1.72682629144155570723E-11,
97 9.67580903537323691224E-11,
98-5.18979560163526290666E-10,
99 2.65982372468238665035E-9,
100-1.30002500998624804212E-8,
101 6.04699502254191894932E-8,
102-2.67079385394061173391E-7,
103 1.11738753912010371815E-6,
104-4.41673835845875056359E-6,
105 1.64484480707288970893E-5,
106-5.75419501008210370398E-5,
107 1.88502885095841655729E-4,
108-5.76375574538582365885E-4,
109 1.63947561694133579842E-3,
110-4.32430999505057594430E-3,
111 1.05464603945949983183E-2,
112-2.37374148058994688156E-2,
113 4.93052842396707084878E-2,
114-9.49010970480476444210E-2,
115 1.71620901522208775349E-1,
116-3.04682672343198398683E-1,
117 6.76795274409476084995E-1
118};
119#endif
120
121#ifdef DEC
122static unsigned short A[] = {
1230121642,0162671,0004646,0103567,
1240022431,0115424,0135755,0026104,
1250123214,0023533,0110365,0156635,
1260023767,0033304,0117662,0172716,
1270124522,0100426,0012277,0157531,
1280025254,0155062,0054461,0030465,
1290126010,0131143,0013560,0153604,
1300026517,0170577,0006336,0114437,
1310127227,0162253,0152243,0052734,
1320027724,0142766,0061641,0160200,
1330130416,0123760,0116564,0125262,
1340031066,0144035,0021246,0054641,
1350131537,0053664,0060131,0102530,
1360032201,0155664,0165153,0020652,
1370132617,0061434,0074423,0176145,
1380033225,0174444,0136147,0122542,
1390133624,0031576,0056453,0020470,
1400034211,0175305,0172321,0041314,
1410134561,0054462,0147040,0165315,
1420035105,0124333,0120203,0162532,
1430135427,0013750,0174257,0055221,
1440035726,0161654,0050220,0100162,
1450136215,0131361,0000325,0041110,
1460036454,0145417,0117357,0017352,
1470136702,0072367,0104415,0133574,
1480037111,0172126,0072505,0014544,
1490137302,0055601,0120550,0033523,
1500037457,0136543,0136544,0043002,
1510137633,0177536,0001276,0066150,
1520040055,0041164,0100655,0010521
153};
154#endif
155
156#ifdef IBMPC
157static unsigned short A[] = {
1580xd0ef,0x2134,0x5cb7,0xbc54,
1590xa589,0x977d,0x3362,0x3c83,
1600xbbb4,0x721e,0x84eb,0xbcb1,
1610x5eba,0x93f6,0xe6d8,0x3cde,
1620xfbeb,0xc297,0x5022,0xbd0a,
1630x2627,0x4b26,0x9b46,0x3d35,
1640x1af0,0x62ee,0x164c,0xbd61,
1650xd324,0xe19b,0xfe2f,0x3d89,
1660x6abc,0x7a94,0xfc95,0xbdb2,
1670x3c10,0xcc74,0x98be,0x3dda,
1680x9556,0x13ae,0xd4fe,0xbe01,
1690xcb34,0xa454,0xd903,0x3e26,
1700x30ab,0x8c0b,0xeaf6,0xbe4b,
1710x6435,0x9d4d,0x3b76,0x3e70,
1720x7f8d,0x8f22,0xec63,0xbe91,
1730xf4ac,0x978c,0xbf24,0x3eb2,
1740x6427,0xcba5,0x866f,0xbed2,
1750x2859,0xbe9a,0x3f58,0x3ef1,
1760x1d5a,0x59c4,0x2b26,0xbf0e,
1770x7cab,0x7410,0xb51b,0x3f28,
1780xeb52,0x1f15,0xe2fd,0xbf42,
1790x100e,0x8a12,0xdc75,0x3f5a,
1800xa849,0x201a,0xb65e,0xbf71,
1810xe3dd,0xf3dd,0x9961,0x3f85,
1820xb6f0,0xf121,0x4e9e,0xbf98,
1830xa32d,0xcea8,0x3e8a,0x3fa9,
1840x06ea,0x342d,0x4b70,0xbfb8,
1850x88c0,0x77ac,0xf7ac,0x3fc5,
1860xcd8d,0xc057,0x7feb,0xbfd3,
1870xa22a,0x9035,0xa84e,0x3fe5,
188};
189#endif
190
191#ifdef MIEEE
192static unsigned short A[] = {
1930xbc54,0x5cb7,0x2134,0xd0ef,
1940x3c83,0x3362,0x977d,0xa589,
1950xbcb1,0x84eb,0x721e,0xbbb4,
1960x3cde,0xe6d8,0x93f6,0x5eba,
1970xbd0a,0x5022,0xc297,0xfbeb,
1980x3d35,0x9b46,0x4b26,0x2627,
1990xbd61,0x164c,0x62ee,0x1af0,
2000x3d89,0xfe2f,0xe19b,0xd324,
2010xbdb2,0xfc95,0x7a94,0x6abc,
2020x3dda,0x98be,0xcc74,0x3c10,
2030xbe01,0xd4fe,0x13ae,0x9556,
2040x3e26,0xd903,0xa454,0xcb34,
2050xbe4b,0xeaf6,0x8c0b,0x30ab,
2060x3e70,0x3b76,0x9d4d,0x6435,
2070xbe91,0xec63,0x8f22,0x7f8d,
2080x3eb2,0xbf24,0x978c,0xf4ac,
2090xbed2,0x866f,0xcba5,0x6427,
2100x3ef1,0x3f58,0xbe9a,0x2859,
2110xbf0e,0x2b26,0x59c4,0x1d5a,
2120x3f28,0xb51b,0x7410,0x7cab,
2130xbf42,0xe2fd,0x1f15,0xeb52,
2140x3f5a,0xdc75,0x8a12,0x100e,
2150xbf71,0xb65e,0x201a,0xa849,
2160x3f85,0x9961,0xf3dd,0xe3dd,
2170xbf98,0x4e9e,0xf121,0xb6f0,
2180x3fa9,0x3e8a,0xcea8,0xa32d,
2190xbfb8,0x4b70,0x342d,0x06ea,
2200x3fc5,0xf7ac,0x77ac,0x88c0,
2210xbfd3,0x7feb,0xc057,0xcd8d,
2220x3fe5,0xa84e,0x9035,0xa22a
223};
224#endif
225
226
227/* Chebyshev coefficients for exp(-x) sqrt(x) I0(x)
228 * in the inverted interval [8,infinity].
229 *
230 * lim(x->inf){ exp(-x) sqrt(x) I0(x) } = 1/sqrt(2pi).
231 */
232
233#ifdef UNK
234static double B[] =
235{
236-7.23318048787475395456E-18,
237-4.83050448594418207126E-18,
238 4.46562142029675999901E-17,
239 3.46122286769746109310E-17,
240-2.82762398051658348494E-16,
241-3.42548561967721913462E-16,
242 1.77256013305652638360E-15,
243 3.81168066935262242075E-15,
244-9.55484669882830764870E-15,
245-4.15056934728722208663E-14,
246 1.54008621752140982691E-14,
247 3.85277838274214270114E-13,
248 7.18012445138366623367E-13,
249-1.79417853150680611778E-12,
250-1.32158118404477131188E-11,
251-3.14991652796324136454E-11,
252 1.18891471078464383424E-11,
253 4.94060238822496958910E-10,
254 3.39623202570838634515E-9,
255 2.26666899049817806459E-8,
256 2.04891858946906374183E-7,
257 2.89137052083475648297E-6,
258 6.88975834691682398426E-5,
259 3.36911647825569408990E-3,
260 8.04490411014108831608E-1
261};
262#endif
263
264#ifdef DEC
265static unsigned short B[] = {
2660122005,0066672,0123124,0054311,
2670121662,0033323,0030214,0104602,
2680022515,0170300,0113314,0020413,
2690022437,0117350,0035402,0007146,
2700123243,0000135,0057220,0177435,
2710123305,0073476,0144106,0170702,
2720023777,0071755,0017527,0154373,
2730024211,0052214,0102247,0033270,
2740124454,0017763,0171453,0012322,
2750125072,0166316,0075505,0154616,
2760024612,0133770,0065376,0025045,
2770025730,0162143,0056036,0001632,
2780026112,0015077,0150464,0063542,
2790126374,0101030,0014274,0065457,
2800127150,0077271,0125763,0157617,
2810127412,0104350,0040713,0120445,
2820027121,0023765,0057500,0001165,
2830030407,0147146,0003643,0075644,
2840031151,0061445,0044422,0156065,
2850031702,0132224,0003266,0125551,
2860032534,0000076,0147153,0005555,
2870033502,0004536,0004016,0026055,
2880034620,0076433,0142314,0171215,
2890036134,0146145,0013454,0101104,
2900040115,0171425,0062500,0047133
291};
292#endif
293
294#ifdef IBMPC
295static unsigned short B[] = {
2960x8b19,0x54ca,0xadb7,0xbc60,
2970x9130,0x6611,0x46da,0xbc56,
2980x8421,0x12d9,0xbe18,0x3c89,
2990x41cd,0x0760,0xf3dd,0x3c83,
3000x1fe4,0xabd2,0x600b,0xbcb4,
3010xde38,0xd908,0xaee7,0xbcb8,
3020xfb1f,0xa3ea,0xee7d,0x3cdf,
3030xe6d7,0x9094,0x2a91,0x3cf1,
3040x629a,0x7e65,0x83fe,0xbd05,
3050xbb32,0xcf68,0x5d99,0xbd27,
3060xc545,0x0d5f,0x56ff,0x3d11,
3070xc073,0x6b83,0x1c8c,0x3d5b,
3080x8cec,0xfa26,0x4347,0x3d69,
3090x8d66,0x0317,0x9043,0xbd7f,
3100x7bf2,0x357e,0x0fd7,0xbdad,
3110x7425,0x0839,0x511d,0xbdc1,
3120x004f,0xabe8,0x24fe,0x3daa,
3130x6f75,0xc0f4,0xf9cc,0x3e00,
3140x5b87,0xa922,0x2c64,0x3e2d,
3150xd56d,0x80d6,0x5692,0x3e58,
3160x616e,0xd9cd,0x8007,0x3e8b,
3170xc586,0xc101,0x412b,0x3ec8,
3180x9e52,0x7899,0x0fa3,0x3f12,
3190x9049,0xa2e5,0x998c,0x3f6b,
3200x09cb,0xaca8,0xbe62,0x3fe9
321};
322#endif
323
324#ifdef MIEEE
325static unsigned short B[] = {
3260xbc60,0xadb7,0x54ca,0x8b19,
3270xbc56,0x46da,0x6611,0x9130,
3280x3c89,0xbe18,0x12d9,0x8421,
3290x3c83,0xf3dd,0x0760,0x41cd,
3300xbcb4,0x600b,0xabd2,0x1fe4,
3310xbcb8,0xaee7,0xd908,0xde38,
3320x3cdf,0xee7d,0xa3ea,0xfb1f,
3330x3cf1,0x2a91,0x9094,0xe6d7,
3340xbd05,0x83fe,0x7e65,0x629a,
3350xbd27,0x5d99,0xcf68,0xbb32,
3360x3d11,0x56ff,0x0d5f,0xc545,
3370x3d5b,0x1c8c,0x6b83,0xc073,
3380x3d69,0x4347,0xfa26,0x8cec,
3390xbd7f,0x9043,0x0317,0x8d66,
3400xbdad,0x0fd7,0x357e,0x7bf2,
3410xbdc1,0x511d,0x0839,0x7425,
3420x3daa,0x24fe,0xabe8,0x004f,
3430x3e00,0xf9cc,0xc0f4,0x6f75,
3440x3e2d,0x2c64,0xa922,0x5b87,
3450x3e58,0x5692,0x80d6,0xd56d,
3460x3e8b,0x8007,0xd9cd,0x616e,
3470x3ec8,0x412b,0xc101,0xc586,
3480x3f12,0x0fa3,0x7899,0x9e52,
3490x3f6b,0x998c,0xa2e5,0x9049,
3500x3fe9,0xbe62,0xaca8,0x09cb
351};
352#endif
353
354#ifdef ANSIPROT
355extern double chbevl ( double, void *, int );
356extern double exp ( double );
357extern double sqrt ( double );
358#else
359double chbevl(), exp(), sqrt();
360#endif
361
362double i0(x)
363double x;
364{
365double y;
366
367if( x < 0 )
368        x = -x;
369if( x <= 8.0 )
370        {
371        y = (x/2.0) - 2.0;
372        return( exp(x) * chbevl( y, A, 30 ) );
373        }
374
375return(  exp(x) * chbevl( 32.0/x - 2.0, B, 25 ) / sqrt(x) );
376
377}
378
379
380
381
382double i0e( x )
383double x;
384{
385double y;
386
387if( x < 0 )
388        x = -x;
389if( x <= 8.0 )
390        {
391        y = (x/2.0) - 2.0;
392        return( chbevl( y, A, 30 ) );
393        }
394
395return(  chbevl( 32.0/x - 2.0, B, 25 ) / sqrt(x) );
396
397}
Note: See TracBrowser for help on using the repository browser.