Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / specfunc / bessel_Inu.c
1 /* specfunc/bessel_Inu.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 <config.h>
23 #include <gsl/gsl_math.h>
24 #include <gsl/gsl_errno.h>
25 #include <gsl/gsl_sf_exp.h>
26 #include <gsl/gsl_sf_gamma.h>
27 #include <gsl/gsl_sf_bessel.h>
28
29 #include "error.h"
30
31 #include "bessel.h"
32 #include "bessel_temme.h"
33
34
35 /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
36
37 int
38 gsl_sf_bessel_Inu_scaled_e(double nu, double x, gsl_sf_result * result)
39 {
40   /* CHECK_POINTER(result) */
41
42   if(x < 0.0 || nu < 0.0) {
43     DOMAIN_ERROR(result);
44   }
45   else if(x*x < 10.0*(nu+1.0)) {
46     gsl_sf_result b;
47     double ex = exp(-x);
48     int stat = gsl_sf_bessel_IJ_taylor_e(nu, x, 1, 100, GSL_DBL_EPSILON, &b);
49     result->val  = b.val * ex;
50     result->err  = b.err * ex;
51     result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
52     return stat;
53   }
54   else if(0.5/(nu*nu + x*x) < GSL_ROOT3_DBL_EPSILON) {
55     return gsl_sf_bessel_Inu_scaled_asymp_unif_e(nu, x, result);
56   }
57   else {
58     int N = (int)(nu + 0.5);
59     double mu = nu - N;      /* -1/2 <= mu <= 1/2 */ 
60     double K_mu, K_mup1, Kp_mu;
61     double K_nu, K_nup1, K_num1;
62     double I_nu_ratio;
63     int stat_Irat;
64     int stat_Kmu;
65     int n;
66
67     /* obtain K_mu, K_mup1 */
68     if(x < 2.0) {
69       stat_Kmu = gsl_sf_bessel_K_scaled_temme(mu, x, &K_mu, &K_mup1, &Kp_mu);
70     }
71     else {
72       stat_Kmu = gsl_sf_bessel_K_scaled_steed_temme_CF2(mu, x, &K_mu, &K_mup1, &Kp_mu);
73     }
74
75     /* recurse forward to obtain K_num1, K_nu */
76     K_nu   = K_mu;
77     K_nup1 = K_mup1;
78
79     for(n=0; n<N; n++) {
80       K_num1 = K_nu;
81       K_nu   = K_nup1;
82       K_nup1 = 2.0*(mu+n+1)/x * K_nu + K_num1;
83     }
84
85     /* calculate I_{nu+1}/I_nu */
86     stat_Irat = gsl_sf_bessel_I_CF1_ser(nu, x, &I_nu_ratio);
87
88     /* solve for I_nu */
89     result->val = 1.0/(x * (K_nup1 + I_nu_ratio * K_nu));
90     result->err = GSL_DBL_EPSILON * (0.5*N + 2.0) * fabs(result->val);
91
92     return GSL_ERROR_SELECT_2(stat_Kmu, stat_Irat);
93   }
94 }
95
96
97 int
98 gsl_sf_bessel_Inu_e(double nu, double x, gsl_sf_result * result)
99 {
100   gsl_sf_result b;
101   int stat_I = gsl_sf_bessel_Inu_scaled_e(nu, x, &b);
102   int stat_e = gsl_sf_exp_mult_err_e(x, fabs(x*GSL_DBL_EPSILON),
103                                         b.val, b.err,
104                                         result);
105   return GSL_ERROR_SELECT_2(stat_e, stat_I);
106 }
107
108
109 /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
110
111 #include "eval.h"
112
113 double gsl_sf_bessel_Inu_scaled(double nu, double x)
114 {
115   EVAL_RESULT(gsl_sf_bessel_Inu_scaled_e(nu, x, &result));
116 }
117
118
119 double gsl_sf_bessel_Inu(double nu, double x)
120 {
121   EVAL_RESULT(gsl_sf_bessel_Inu_e(nu, x, &result));
122 }