7 static float srtopi = 2.0/sqrt(2.0*
M_PI);
8 static float upl = 100.0;
11 if(ndof <= 0)
return prob;
12 if(chisq < 0.0)
return prob;
15 if(chisq > upl)
return prob;
16 float sum =
exp(-0.5*chisq);
21 if(m == 1)
return sum;
22 for(
int i = 2; i <= m; i++) {
23 term = 0.5*term*chisq/(i-1);
30 float srty = sqrt(chisq);
31 float temp = srty/M_SQRT2;
33 if(ndof == 1)
return prob;
34 if(ndof == 3)
return (srtopi*srty*sum+prob);
36 for(
int i = 1; i <= m; i++) {
37 term = term*chisq/(2*i+1);
40 return (srtopi*srty*sum + prob);
46 float srty = sqrt(chisq) - sqrt(ndof - 0.5);
47 if(srty < 12.0) prob=0.5*erfc(srty);