1 /* specfunc/bessel_K0.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_exp.h>
26 #include <gsl/gsl_sf_bessel.h>
30 #include "chebyshev.h"
31 #include "cheb_eval.c"
33 /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
35 /* based on SLATEC bk0(), bk0e() */
37 /* chebyshev expansions
39 series for bk0 on the interval 0. to 4.00000d+00
40 with weighted error 3.57e-19
41 log weighted error 18.45
42 significant figures required 17.99
43 decimal places required 18.97
45 series for ak0 on the interval 1.25000d-01 to 5.00000d-01
46 with weighted error 5.34e-17
47 log weighted error 16.27
48 significant figures required 14.92
49 decimal places required 16.89
51 series for ak02 on the interval 0. to 1.25000d-01
52 with weighted error 2.34e-17
53 log weighted error 16.63
54 significant figures required 14.67
55 decimal places required 17.20
58 static double bk0_data[11] = {
59 -0.03532739323390276872,
60 0.3442898999246284869,
61 0.03597993651536150163,
62 0.00126461541144692592,
63 0.00002286212103119451,
64 0.00000025347910790261,
65 0.00000000190451637722,
66 0.00000000001034969525,
67 0.00000000000004259816,
68 0.00000000000000013744,
69 0.00000000000000000035
71 static cheb_series bk0_cs = {
78 static double ak0_data[17] = {
97 static cheb_series ak0_cs = {
104 static double ak02_data[14] = {
105 -0.01201869826307592,
106 -0.00917485269102569,
108 -0.00000401361417543,
110 -0.00000000777011043,
112 -0.00000000003158592,
114 -0.00000000000020743,
116 -0.00000000000000192,
120 static cheb_series ak02_cs = {
128 /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
130 int gsl_sf_bessel_K0_scaled_e(const double x, gsl_sf_result * result)
132 /* CHECK_POINTER(result) */
135 DOMAIN_ERROR(result);
138 const double lx = log(x);
139 const double ex = exp(x);
143 cheb_eval_e(&bk0_cs, 0.5*x*x-1.0, &c);
144 stat_I0 = gsl_sf_bessel_I0_e(x, &I0);
145 result->val = ex * ((-lx+M_LN2)*I0.val - 0.25 + c.val);
146 result->err = ex * ((M_LN2+fabs(lx))*I0.err + c.err);
147 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
151 const double sx = sqrt(x);
153 cheb_eval_e(&ak0_cs, (16.0/x-5.0)/3.0, &c);
154 result->val = (1.25 + c.val) / sx;
155 result->err = c.err / sx;
156 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
160 const double sx = sqrt(x);
162 cheb_eval_e(&ak02_cs, 16.0/x-1.0, &c);
163 result->val = (1.25 + c.val) / sx;
164 result->err = (c.err + GSL_DBL_EPSILON) / sx;
165 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
171 int gsl_sf_bessel_K0_e(const double x, gsl_sf_result * result)
173 /* CHECK_POINTER(result) */
176 DOMAIN_ERROR(result);
179 const double lx = log(x);
183 cheb_eval_e(&bk0_cs, 0.5*x*x-1.0, &c);
184 stat_I0 = gsl_sf_bessel_I0_e(x, &I0);
185 result->val = (-lx+M_LN2)*I0.val - 0.25 + c.val;
186 result->err = (fabs(lx) + M_LN2) * I0.err + c.err;
187 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
191 gsl_sf_result K0_scaled;
192 int stat_K0 = gsl_sf_bessel_K0_scaled_e(x, &K0_scaled);
193 int stat_e = gsl_sf_exp_mult_err_e(-x, GSL_DBL_EPSILON*fabs(x),
194 K0_scaled.val, K0_scaled.err,
196 return GSL_ERROR_SELECT_2(stat_e, stat_K0);
201 /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
205 double gsl_sf_bessel_K0_scaled(const double x)
207 EVAL_RESULT(gsl_sf_bessel_K0_scaled_e(x, &result));
210 double gsl_sf_bessel_K0(const double x)
212 EVAL_RESULT(gsl_sf_bessel_K0_e(x, &result));