0

I need to calculate chi squared cdf from x->infinity with n=255 degrees of freedom. I cannot seem to get it to work. You can find formulae for chi squared distributions using google. Here is my non-functional approximation code:

```
double riemannsum(double(*fnc)(double),double dx, double xmin, double xmax)
{
double ret=0;
double x=xmin;
while (x<xmax)
{
ret+=fnc(x);
x+=dx;
}
return ret;
}
double lowergammaintegrand(double x)
{
return pow(x,254)*pow(M_E,-x);//I am only using 255 degrees of freedom in this program
}
double lowergamma(double x)
{
return riemannsum(&lowergammaintegrand,10,x,10000000);
}
double chicdf(double x)
{
static double gamma1275=3.40511e214;//this is Gamma(127.5)=Gamma(k/2)
return lowergamma(x)/gamma1275;
}
```