#include#includestaticlongdoublegammln (constlongdouble&xx )
{longdoublex,
tmp,
ser;staticlongdoublecof[6]={76.18009173,-86.50532033,24.01409822,-1.231739516,0.120858003e-2,-0.536382e-5};intj;
x=xx-1.0;
tmp=x+5.5;
tmp-=( x+0.5)*log ( tmp );
ser=1.0;for( j=0; j<=5; j++)
{
x+=1.0;
ser+=cof[j]/x;
}return-tmp+log (2.50662827465*ser );
}staticvoidgcf (longdouble*gammcf,constlongdouble&a,constlongdouble&x,longdouble*gln )
{constunsignedintITMAX=100;constlongdoubleEPS=3.0e-7;
unsignedintn=0;longdoublegold=0.0,
g,
fac=1.0,
b1=1.0;longdoubleb0=0.0,
anf,
ana,
an,
a1,
a0=1.0;*gln=gammln ( a );
a1=x;for( n=1; n<=ITMAX; n++)
{
an=(float) n;
ana=an-a;
a0=( a1+a0*ana )*fac;
b0=( b1+b0*ana )*fac;
anf=an*fac;
a1=x*a0+anf*a1;
b1=x*b0+anf*b1;if( a1 )
{
fac=1.0/a1;
g=b1*fac;if( fabs ( ( g-gold )/g )
{*gammcf=exp (-x+a*log ( x )-(*gln ) )*g;return;
}
gold=g;
}
}if("a too large, ITMAX too small in routine GCF")
exit ( EXIT_FAILURE );
}staticvoidgser (longdouble*gamser,constlongdouble&a,constlongdouble&x,longdouble*gln )
{constunsignedintITMAX=100;constlongdoubleEPS=3.0e-7;
unsignedintn=0;longdoublesum,
del,
ap;*gln=gammln ( a );if( x<=0.0)
{if( x<0.0)if("x less than 0 in routine GSER")
exit ( EXIT_FAILURE );*gamser=0.0;return;
}else{
ap=a;
del=sum=1.0/a;for( n=1; n<=ITMAX; n++)
{
ap+=1.0;
del*=x/ap;
sum+=del;if( fabs ( del )
{*gamser=sum*exp (-x+a*log ( x )-(*gln ) );return;
}
}if("a too large, ITMAX too small in routine GSER")
exit ( EXIT_FAILURE );return;
}
}longdoublegammq (constlongdouble&a,constlongdouble&x )
{longdoublegamser,
gammcf,
gln;if( x<0.0||a<=0.0)if("Invalid arguments in routine gammq.")
exit ( EXIT_FAILURE );if( x
{
gser (&gamser, a, x,&gln );return1.0-gamser;
}else{
gcf (&gammcf, a, x,&gln );returngammcf;
}
}