1 /* specfunc/bessel_I0.c
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 /* Author: G. Jungman */
23 #include <gsl/gsl_math.h>
24 #include <gsl/gsl_errno.h>
25 #include <gsl/gsl_sf_bessel.h>
29 #include "chebyshev.h"
30 #include "cheb_eval.c"
32 /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
35 /* based on SLATEC besi0 */
37 /* chebyshev expansions
39 series for bi0 on the interval 0. to 9.00000d+00
40 with weighted error 2.46e-18
41 log weighted error 17.61
42 significant figures required 17.90
43 decimal places required 18.15
45 series for ai0 on the interval 1.25000d-01 to 3.33333d-01
46 with weighted error 7.87e-17
47 log weighted error 16.10
48 significant figures required 14.69
49 decimal places required 16.76
52 series for ai02 on the interval 0. to 1.25000d-01
53 with weighted error 3.79e-17
54 log weighted error 16.42
55 significant figures required 14.86
56 decimal places required 17.09
59 static double bi0_data[12] = {
60 -.07660547252839144951,
61 1.92733795399380827000,
62 .22826445869203013390,
63 .01304891466707290428,
64 .00043442709008164874,
65 .00000942265768600193,
66 .00000014340062895106,
67 .00000000161384906966,
68 .00000000001396650044,
69 .00000000000009579451,
70 .00000000000000053339,
73 static cheb_series bi0_cs = {
80 static double ai0_data[21] = {
103 static cheb_series ai0_cs = {
110 static double ai02_data[22] = {
134 static cheb_series ai02_cs = {
142 /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
144 int gsl_sf_bessel_I0_scaled_e(const double x, gsl_sf_result * result)
148 /* CHECK_POINTER(result) */
150 if(y < 2.0 * GSL_SQRT_DBL_EPSILON) {
151 result->val = 1.0 - y;
152 result->err = 0.5*y*y;
156 const double ey = exp(-y);
158 cheb_eval_e(&bi0_cs, y*y/4.5-1.0, &c);
159 result->val = ey * (2.75 + c.val);
160 result->err = GSL_DBL_EPSILON * fabs(result->val) + ey * c.err;
164 const double sy = sqrt(y);
166 cheb_eval_e(&ai0_cs, (48.0/y-11.0)/5.0, &c);
167 result->val = (0.375 + c.val) / sy;
168 result->err = 2.0 * GSL_DBL_EPSILON * (0.375 + fabs(c.val)) / sy;
169 result->err += c.err / sy;
170 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
174 const double sy = sqrt(y);
176 cheb_eval_e(&ai02_cs, 16.0/y-1.0, &c);
177 result->val = (0.375 + c.val) / sy;
178 result->err = 2.0 * GSL_DBL_EPSILON * (0.375 + fabs(c.val)) / sy;
179 result->err += c.err / sy;
180 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
186 int gsl_sf_bessel_I0_e(const double x, gsl_sf_result * result)
190 /* CHECK_POINTER(result) */
192 if(y < 2.0 * GSL_SQRT_DBL_EPSILON) {
194 result->err = 0.5*y*y;
199 cheb_eval_e(&bi0_cs, y*y/4.5-1.0, &c);
200 result->val = 2.75 + c.val;
201 result->err = GSL_DBL_EPSILON * (2.75 + fabs(c.val));
202 result->err += c.err;
203 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
206 else if(y < GSL_LOG_DBL_MAX - 1.0) {
207 const double ey = exp(y);
208 gsl_sf_result b_scaled;
209 gsl_sf_bessel_I0_scaled_e(x, &b_scaled);
210 result->val = ey * b_scaled.val;
211 result->err = ey * b_scaled.err + y*GSL_DBL_EPSILON*fabs(result->val);
212 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
216 OVERFLOW_ERROR(result);
220 /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
224 double gsl_sf_bessel_I0_scaled(const double x)
226 EVAL_RESULT(gsl_sf_bessel_I0_scaled_e(x, &result); )
229 double gsl_sf_bessel_I0(const double x)
231 EVAL_RESULT(gsl_sf_bessel_I0_e(x, &result); )