23 #include <gsl/gsl_cdf.h>
24 #include <gsl/gsl_sf.h>
27 #include <lal/LALChisq.h>
28 #include <lal/LALConstants.h>
29 #include <lal/XLALGSL.h>
30 #include <lal/XLALError.h>
81 if((chi2 < 0.0) || (dof <= 0.0))
90 XLAL_CALLGSL(ln_prob = log1p(-gsl_cdf_chisq_P(chi2, dof)));
91 }
else if(ln_prob < -600.) {
94 const double a = dof / 2.;
95 const double x = chi2 / 2.;
109 for(i = 1., sum = 0., term = 1.; fabs(term/sum) > 1e-17; i++) {
110 double factor = (
a - i) /
x;
113 if(fabs(factor) >= 1.)
118 if(fabs(factor) >= 1. || i > 100.)
122 if(fabs(factor) >= 1. || i > 100.)
128 ln_prob = (
a - 1.) * log(
x) -
x + log1p(sum);
#define XLAL_CALLGSL(statement)
double XLALLogChisqCCDF(double chi2, double dof)
Compute the natural logarithm of the complementary cumulative probability function of the distributi...
#define LAL_LN2
natural log of 2, ln(2)
#define XLAL_ERROR_REAL8(...)
Macro to invoke a failure from a XLAL routine returning a REAL8.
@ XLAL_EDIVERGE
Series is diverging.
@ XLAL_ERANGE
Output range error.
@ XLAL_EMAXITER
Exceeded maximum number of iterations.
@ XLAL_ELOSS
Loss of accuracy.
@ XLAL_EDOM
Input domain error.