1 /* specfunc/bessel_J1.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_trig.h>
26 #include <gsl/gsl_sf_bessel.h>
31 #include "bessel_amp_phase.h"
32 #include "cheb_eval.c"
34 #define ROOT_EIGHT (2.0*M_SQRT2)
36 /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
39 /* based on SLATEC besj1, 1983 version, w. fullerton */
41 /* chebyshev expansions
43 series for bj1 on the interval 0. to 1.60000d+01
44 with weighted error 4.48e-17
45 log weighted error 16.35
46 significant figures required 15.77
47 decimal places required 16.89
50 static double bj1_data[12] = {
54 -0.004631514809625081,
56 -0.000008678948686278,
58 -0.000000003936093079,
60 -0.000000000000632761,
62 -0.000000000000000044,
64 static cheb_series bj1_cs = {
72 /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
74 int gsl_sf_bessel_J1_e(const double x, gsl_sf_result * result)
78 /* CHECK_POINTER(result) */
85 else if(y < 2.0*GSL_DBL_MIN) {
86 UNDERFLOW_ERROR(result);
88 else if(y < ROOT_EIGHT * GSL_SQRT_DBL_EPSILON) {
95 cheb_eval_e(&bj1_cs, 0.125*y*y-1.0, &c);
96 result->val = x * (0.25 + c.val);
97 result->err = fabs(x * c.err);
101 /* Because the leading term in the phase is y,
102 * which we assume is exactly known, the error
103 * in the cos() evaluation is bounded.
105 const double z = 32.0/(y*y) - 1.0;
109 const int stat_ca = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bm1_cs, z, &ca);
110 const int stat_ct = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bth1_cs, z, &ct);
111 const int stat_sp = gsl_sf_bessel_sin_pi4_e(y, ct.val/y, &sp);
112 const double sqrty = sqrt(y);
113 const double ampl = (0.75 + ca.val) / sqrty;
114 result->val = (x < 0.0 ? -ampl : ampl) * sp.val;
115 result->err = fabs(sp.val) * ca.err/sqrty + fabs(ampl) * sp.err;
116 result->err += GSL_DBL_EPSILON * fabs(result->val);
117 return GSL_ERROR_SELECT_3(stat_ca, stat_ct, stat_sp);
121 /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
125 double gsl_sf_bessel_J1(const double x)
127 EVAL_RESULT(gsl_sf_bessel_J1_e(x, &result));