44 Float gammafn(Float x)
46 const static double gamcs[42] = {
47 +.8571195590989331421920062399942e-2,
48 +.4415381324841006757191315771652e-2,
49 +.5685043681599363378632664588789e-1,
50 -.4219835396418560501012500186624e-2,
51 +.1326808181212460220584006796352e-2,
52 -.1893024529798880432523947023886e-3,
53 +.3606925327441245256578082217225e-4,
54 -.6056761904460864218485548290365e-5,
55 +.1055829546302283344731823509093e-5,
56 -.1811967365542384048291855891166e-6,
57 +.3117724964715322277790254593169e-7,
58 -.5354219639019687140874081024347e-8,
59 +.9193275519859588946887786825940e-9,
60 -.1577941280288339761767423273953e-9,
61 +.2707980622934954543266540433089e-10,
62 -.4646818653825730144081661058933e-11,
63 +.7973350192007419656460767175359e-12,
64 -.1368078209830916025799499172309e-12,
65 +.2347319486563800657233471771688e-13,
66 -.4027432614949066932766570534699e-14,
67 +.6910051747372100912138336975257e-15,
68 -.1185584500221992907052387126192e-15,
69 +.2034148542496373955201026051932e-16,
70 -.3490054341717405849274012949108e-17,
71 +.5987993856485305567135051066026e-18,
72 -.1027378057872228074490069778431e-18,
73 +.1762702816060529824942759660748e-19,
74 -.3024320653735306260958772112042e-20,
75 +.5188914660218397839717833550506e-21,
76 -.8902770842456576692449251601066e-22,
77 +.1527474068493342602274596891306e-22,
78 -.2620731256187362900257328332799e-23,
79 +.4496464047830538670331046570666e-24,
80 -.7714712731336877911703901525333e-25,
81 +.1323635453126044036486572714666e-25,
82 -.2270999412942928816702313813333e-26,
83 +.3896418998003991449320816639999e-27,
84 -.6685198115125953327792127999999e-28,
85 +.1146998663140024384347613866666e-28,
86 -.1967938586345134677295103999999e-29,
87 +.3376448816585338090334890666666e-30,
88 -.5793070335782135784625493333333e-31
95 #ifdef NOMORE_FOR_THREADS 97 static double xmin = 0, xmax = 0., xsml = 0., dxrel = 0.;
102 ngam = chebyshev_init(gamcs, 42, DBL_EPSILON/20);
103 gammalims(&xmin, &xmax);
104 xsml = exp(fmax2(log(DBL_MIN), -log(DBL_MAX)) + 0.01);
106 dxrel = sqrt(DBL_EPSILON);
115 # define xmin -170.5674972726612 116 # define xmax 171.61447887182298 117 # define xsml 2.2474362225598545e-308 118 # define dxrel 1.490116119384765696e-8 121 if(ISNAN(x))
return x;
125 if (x == 0 || (x < 0 && x == round(x))) {
126 ML_ERROR(ME_DOMAIN,
"gammafn");
142 value = chebyshev_eval(y * 2 - 1, gamcs, ngam) + .9375;
153 if (x < -0.5 && fabs(x - (
int)trunc(x - 0.5) / x) < dxrel) {
154 ML_ERROR(ME_PRECISION,
"gammafn");
159 ML_ERROR(ME_RANGE,
"gammafn");
160 if(x > 0)
return ML_POSINF;
161 else return ML_NEGINF;
166 for (i = 0; i < n; i++) {
174 for (i = 1; i <= n; i++) {
184 ML_ERROR(ME_RANGE,
"gammafn");
189 ML_ERROR(ME_UNDERFLOW,
"gammafn");
193 if(y <= 50 && y == (
int)trunc(y)) {
195 for (i = 2; i < y; i++) value *= i;
198 value = exp((y - 0.5) * log(y) - y + M_LN_SQRT_2PI +
199 ((2*y == (
int)trunc(2*y))? stirlerr(y) : lgammacor(y)));
204 if (fabs((x - (
int)trunc(x - 0.5))/x) < dxrel){
209 ML_ERROR(ME_PRECISION,
"gammafn");
214 ML_ERROR(ME_RANGE,
"gammafn");
218 return -M_PI / (y * sinpiy * value);