43 Float lgammafn_sign(Float x,
int *sgn)
47 #ifdef NOMORE_FOR_THREADS 48 static double xmax = 0.;
49 static double dxrel = 0.;
52 xmax = d1mach(2)/log(d1mach(2));
53 dxrel = sqrt (d1mach(4));
60 #define xmax 2.5327372760800758e+305 61 #define dxrel 1.490116119384765625e-8 64 if (sgn != NULL) *sgn = 1;
67 if(ISNAN(x))
return x;
70 if (sgn != NULL && x < 0 && fmod(floor(-x), 2.) == 0)
73 if (x <= 0 && x == trunc(x)) {
74 ML_ERROR(ME_RANGE,
"lgamma");
80 if (y < 1e-306)
return -log(y);
81 if (y <= 10)
return log(fabs(gammafn(x)));
86 ML_ERROR(ME_RANGE,
"lgamma");
93 return(x*(log(x) - 1.));
95 return(M_LN_SQRT_2PI + (x - 0.5) * log(x) - x);
98 return M_LN_SQRT_2PI + (x - 0.5) * log(x) - x + lgammacor(x);
101 sinpiy = fabs(sinpi(y));
105 MATHLIB_WARNING(
" ** should NEVER happen! *** [lgamma.c: Neg.int, y=%g]\n",y);
109 ans = M_LN_SQRT_PId2 + (x - 0.5) * log(y) - x - log(sinpiy) - lgammacor(y);
111 if(fabs((x - trunc(x - 0.5)) * ans / x) < dxrel) {
116 ML_ERROR(ME_PRECISION,
"lgamma");
122 template<
class Float>
123 Float lgammafn(Float x)
125 return lgammafn_sign(x, NULL);