Debian Codegraph @

external/gsl/gsl_specfunc__bessel_Y1.c

raw
1 /* specfunc/bessel_Y1.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 /* Author: G. Jungman */
21
22 #include "gsl__config.h"
23 #include "gsl_math.h"
24 #include "gsl_errno.h"
25 #include "gsl_sf_trig.h"
26 #include "gsl_sf_bessel.h"
27
28 #include "gsl_specfunc__error.h"
29
30 #include "gsl_specfunc__bessel.h"
31 #include "gsl_specfunc__bessel_amp_phase.h"
32 #include "gsl_specfunc__cheb_eval.c"
33
34 /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
35
36 /* based on SLATEC besy1, 1977 version, w. fullerton */
37
38 /* chebyshev expansions
39
40 series for by1 on the interval 0. to 1.60000d+01
41 with weighted error 1.87e-18
42 log weighted error 17.73
43 significant figures required 17.83
44 decimal places required 18.30
45 */
46
47 static double by1_data[14] = {
48 0.03208047100611908629,
49 1.262707897433500450,
50 0.00649996189992317500,
51 -0.08936164528860504117,
52 0.01325088122175709545,
53 -0.00089790591196483523,
54 0.00003647361487958306,
55 -0.00000100137438166600,
56 0.00000001994539657390,
57 -0.00000000030230656018,
58 0.00000000000360987815,
59 -0.00000000000003487488,
60 0.00000000000000027838,
61 -0.00000000000000000186
62 };
63 static cheb_series by1_cs = {
64 by1_data,
65 13,
66 -1, 1,
67 10
68 };
69
70
71 /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
72
73 int gsl_sf_bessel_Y1_e(const double x, gsl_sf_result * result)
74 {
75 const double two_over_pi = 2.0/M_PI;
76 const double xmin = 1.571*GSL_DBL_MIN; /*exp ( amax1(alog(r1mach(1)), -alog(r1mach(2)))+.01) */
77 const double x_small = 2.0 * GSL_SQRT_DBL_EPSILON;
78 const double xmax = 1.0/GSL_DBL_EPSILON;
79
80 /* CHECK_POINTER(result) */
81
82 if(x <= 0.0) {
83 DOMAIN_ERROR(result);
84 }
85 else if(x < xmin) {
86 OVERFLOW_ERROR(result);
87 }
88 else if(x < x_small) {
89 const double lnterm = log(0.5*x);
90 gsl_sf_result J1;
91 gsl_sf_result c;
92 int status = gsl_sf_bessel_J1_e(x, &J1);
93 cheb_eval_e(&by1_cs, -1.0, &c);
94 result->val = two_over_pi * lnterm * J1.val + (0.5 + c.val)/x;
95 result->err = fabs(lnterm) * (fabs(GSL_DBL_EPSILON * J1.val) + J1.err) + c.err/x;
96 return status;
97 }
98 else if(x < 4.0) {
99 const double lnterm = log(0.5*x);
100 int status;
101 gsl_sf_result J1;
102 gsl_sf_result c;
103 cheb_eval_e(&by1_cs, 0.125*x*x-1.0, &c);
104 status = gsl_sf_bessel_J1_e(x, &J1);
105 result->val = two_over_pi * lnterm * J1.val + (0.5 + c.val)/x;
106 result->err = fabs(lnterm) * (fabs(GSL_DBL_EPSILON * J1.val) + J1.err) + c.err/x;
107 return status;
108 }
109 else if(x < xmax) {
110 const double z = 32.0/(x*x) - 1.0;
111 gsl_sf_result ca;
112 gsl_sf_result ct;
113 gsl_sf_result cp;
114 const int stat_ca = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bm1_cs, z, &ca);
115 const int stat_ct = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bth1_cs, z, &ct);
116 const int stat_cp = gsl_sf_bessel_cos_pi4_e(x, ct.val/x, &cp);
117 const double sqrtx = sqrt(x);
118 const double ampl = (0.75 + ca.val) / sqrtx;
119 result->val = -ampl * cp.val;
120 result->err = fabs(cp.val) * ca.err/sqrtx + fabs(ampl) * cp.err;
121 result->err += GSL_DBL_EPSILON * fabs(result->val);
122 return GSL_ERROR_SELECT_3(stat_ca, stat_ct, stat_cp);
123 }
124 else {
125 UNDERFLOW_ERROR(result);
126 }
127 }
128
129
130 /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
131
132 #include "gsl_specfunc__eval.h"
133
134 double gsl_sf_bessel_Y1(const double x)
135 {
136 EVAL_RESULT(gsl_sf_bessel_Y1_e(x, &result));
137 }