Lines Matching +full:high +full:- +full:z
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
41 * The algorithm remains, but the code has been re-arranged to facilitate
65 * xleft > x > iota: smaller_gam(x) where iota = 1e-17.
66 * iota > x > -itoa: Handle x near 0.
67 * -iota > x : neg_gam
70 * -Inf: return NaN and raise invalid;
72 * other x ~< 177.79: return +-0 and raise underflow;
73 * +-0: return +-Inf and raise divide-by-zero;
87 * (Accurate to 2.8*10^-19 absolute)
91 static const volatile double tiny = 1e-300;
96 * equal-ripples:
98 * log(G(x)) ~= (x-0.5)*(log(x)-1) + 0.5(log(2*pi)-1) + 1/x*P(1/(x*x))
100 * Keep extra precision in multiplying (x-.5)(log(x)-1), to avoid
101 * premature round-off.
103 * Accurate to max(ulp(1/128) absolute, 2^-66 relative) error.
107 ln2pi_lo = -6.7792953272582197e-6,
108 Pa0 = 8.3333333333333329e-02, /* 0x3fb55555, 0x55555555 */
109 Pa1 = -2.7777777777735404e-03, /* 0xbf66c16c, 0x16c145ec */
110 Pa2 = 7.9365079044114095e-04, /* 0x3f4a01a0, 0x183de82d */
111 Pa3 = -5.9523715464225254e-04, /* 0xbf438136, 0x0e681f62 */
112 Pa4 = 8.4161391899445698e-04, /* 0x3f4b93f8, 0x21042a13 */
113 Pa5 = -1.9065246069191080e-03, /* 0xbf5f3c8b, 0x357cb64e */
114 Pa6 = 5.9047708485785158e-03, /* 0x3f782f99, 0xdaf5d65f */
115 Pa7 = -1.6484018705183290e-02; /* 0xbf90e12f, 0xc4fb4df0 */
120 double p, z, thi, tlo, xhi, xlo; in large_gam() local
123 z = 1 / (x * x); in large_gam()
124 p = Pa0 + z * (Pa1 + z * (Pa2 + z * (Pa3 + z * (Pa4 + z * (Pa5 + in large_gam()
125 z * (Pa6 + z * Pa7)))))); in large_gam()
129 u.a -= 1; in large_gam()
131 /* Split (x - 0.5) in high and low parts. */ in large_gam()
132 x -= 0.5; in large_gam()
134 xlo = x - xhi; in large_gam()
136 /* Compute t = (x-.5)*(log(x)-1) in extra precision. */ in large_gam()
145 u.b = thi - u.a; in large_gam()
152 * [1.066.., 2.066..] accurate to 4.25e-19.
154 * Returns r.a + r.b = a0 + (z + c)^2 * p / q, with r.a truncated.
158 a0_hi = 8.8560319441088875e-1,
159 a0_lo = -4.9964270364690197e-17,
161 a0_hi = 8.8560319441088875e-01, /* 0x3fec56dc, 0x82a74aef */
162 a0_lo = -4.9642368725563397e-17, /* 0xbc8c9deb, 0xaa64afc3 */
164 P0 = 6.2138957182182086e-1,
165 P1 = 2.6575719865153347e-1,
166 P2 = 5.5385944642991746e-3,
167 P3 = 1.3845669830409657e-3,
168 P4 = 2.4065995003271137e-3,
171 Q2 = -2.0747456194385994e-1,
172 Q3 = -1.4673413178200542e-1,
173 Q4 = 3.0787817615617552e-2,
174 Q5 = 5.1244934798066622e-3,
175 Q6 = -1.7601274143166700e-3,
176 Q7 = 9.3502102357378894e-5,
177 Q8 = 6.1327550747244396e-6;
180 ratfun_gam(double z, double c) in ratfun_gam() argument
185 q = Q0 + z * (Q1 + z * (Q2 + z * (Q3 + z * (Q4 + z * (Q5 + in ratfun_gam()
186 z * (Q6 + z * (Q7 + z * Q8))))))); in ratfun_gam()
187 p = P0 + z * (P1 + z * (P2 + z * (P3 + z * P4))); in ratfun_gam()
190 /* Split z into high and low parts. */ in ratfun_gam()
191 thi = (float)z; in ratfun_gam()
192 tlo = (z - thi) + c; in ratfun_gam()
193 tlo *= (thi + z); in ratfun_gam()
195 /* Split (z+c)^2 into high and low parts. */ in ratfun_gam()
199 tlo += (q - thi); in ratfun_gam()
201 /* Split p/q into high and low parts. */ in ratfun_gam()
203 r.b = p - r.a; in ratfun_gam()
206 thi *= r.a; /* t = (z+c)^2*(P/Q) */ in ratfun_gam()
208 r.b = ((a0_hi - r.a) + thi) + tlo; in ratfun_gam()
222 left = -0.3955078125, /* left boundary for rat. approx */
223 x0 = 4.6163214496836236e-1; /* xmin - 1 */
231 y = x - 1; in small_gam()
233 yy = ratfun_gam(y - x0, 0); in small_gam()
238 yy.a = r.a - 1; in small_gam()
239 y = y - 1 ; in small_gam()
240 r.b = yy.b = y - yy.a; in small_gam()
243 for (ym1 = y - 1; ym1 > left + x0; y = ym1--, yy.a--) { in small_gam()
247 r.b += (t - r.a); in small_gam()
251 yy = ratfun_gam(y - x0, 0); in small_gam()
267 d = (t + x) * (x - t); in smaller_gam()
270 xlo = x - xhi; in smaller_gam()
273 t = 1 - x0; in smaller_gam()
275 d = 1 - x0; in smaller_gam()
276 d -= t; in smaller_gam()
281 xlo = x - xhi; in smaller_gam()
282 t = x - x0; in smaller_gam()
283 d = - x0 - t; in smaller_gam()
289 r.a -= d * xhi; in smaller_gam()
290 r.a -= d * xlo; in smaller_gam()
306 double y, z; in neg_gam() local
310 return ((x - x) / zero); in neg_gam()
312 z = y - x; in neg_gam()
313 if (z > 0.5) in neg_gam()
314 z = 1 - z; in neg_gam()
318 sgn = -1; in neg_gam()
320 if (z < 0.25) in neg_gam()
321 z = sinpi(z); in neg_gam()
323 z = cospi(0.5 - z); in neg_gam()
325 /* Special case: G(1-x) = Inf; G(x) may be nonzero. */ in neg_gam()
326 if (x < -170) { in neg_gam()
328 if (x < -190) in neg_gam()
331 y = 1 - x; /* exact: 128 < |x| < 255 */ in neg_gam()
333 lsine = __log__D(M_PI / z); /* = TRUNC(log(u)) + small */ in neg_gam()
334 lg.a -= lsine.a; /* exact (opposite signs) */ in neg_gam()
335 lg.b -= lsine.b; in neg_gam()
336 y = -(lg.a + lg.b); in neg_gam()
337 z = (y + lg.a) + lg.b; in neg_gam()
338 y = __exp__D(y, z); in neg_gam()
339 if (sgn < 0) y = -y; in neg_gam()
343 y = 1 - x; in neg_gam()
344 if (1 - y == x) in neg_gam()
346 else /* 1-x is inexact */ in neg_gam()
347 y = - x * tgamma(-x); in neg_gam()
349 if (sgn < 0) y = -y; in neg_gam()
350 return (M_PI / (y * z)); in neg_gam()
353 * xmax comes from lgamma(xmax) - emax * log(2) = 0.
362 static const double iota = 0x1p-56;
382 if (x > -iota) { in tgamma()
384 u.a = 1 - tiny; /* raise inexact */ in tgamma()
389 return (x - x); /* x is NaN or -Inf */ in tgamma()