Print this page
5261 libm should stop using synonyms.h
5298 fabs is 0-sized, confuses dis(1) and others
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Approved by: Gordon Ross <gwr@nexenta.com>
5262 libm needs to be carefully unifdef'd
5268 libm doesn't need to hide symbols which are already local
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Approved by: Gordon Ross <gwr@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/m9x/tgammal.c
+++ new/usr/src/lib/libm/common/m9x/tgammal.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 */
21 21
22 22 /*
23 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25 /*
26 26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 27 * Use is subject to license terms.
28 28 */
29 29
30 -#if defined(ELFOBJ)
31 -#pragma weak tgammal = __tgammal
32 -#endif
30 +#pragma weak __tgammal = tgammal
33 31
34 32 #include "libm.h"
35 33 #include <sys/isa_defs.h>
36 34
37 35 #if defined(_BIG_ENDIAN)
38 36 #define H0_WORD(x) ((unsigned *) &x)[0]
39 37 #define H3_WORD(x) ((unsigned *) &x)[3]
40 38 #define CHOPPED(x) (long double) ((double) (x))
41 39 #else
42 40 #define H0_WORD(x) ((((int *) &x)[2] << 16) | \
43 41 (0x0000ffff & (((unsigned *) &x)[1] >> 15)))
44 42 #define H3_WORD(x) ((unsigned *) &x)[0]
45 43 #define CHOPPED(x) (long double) ((float) (x))
46 44 #endif
47 45
48 46 struct LDouble {
49 47 long double h, l;
50 48 };
51 49
52 50 /* INDENT OFF */
53 51 /* Primary interval GTi() */
54 52 static const long double P1[] = {
55 53 +0.709086836199777919037185741507610124611513720557L,
56 54 +4.45754781206489035827915969367354835667391606951e-0001L,
57 55 +3.21049298735832382311662273882632210062918153852e-0002L,
58 56 -5.71296796342106617651765245858289197369688864350e-0003L,
59 57 +6.04666892891998977081619174969855831606965352773e-0003L,
60 58 +8.99106186996888711939627812174765258822658645168e-0004L,
61 59 -6.96496846144407741431207008527018441810175568949e-0005L,
62 60 +1.52597046118984020814225409300131445070213882429e-0005L,
63 61 +5.68521076168495673844711465407432189190681541547e-0007L,
64 62 +3.30749673519634895220582062520286565610418952979e-0008L,
65 63 };
66 64 static const long double Q1[] = {
67 65 +1.0+0000L,
68 66 +1.35806511721671070408570853537257079579490650668e+0000L,
69 67 +2.97567810153429553405327140096063086994072952961e-0001L,
70 68 -1.52956835982588571502954372821681851681118097870e-0001L,
71 69 -2.88248519561420109768781615289082053597954521218e-0002L,
72 70 +1.03475311719937405219789948456313936302378395955e-0002L,
73 71 +4.12310203243891222368965360124391297374822742313e-0004L,
74 72 -3.12653708152290867248931925120380729518332507388e-0004L,
75 73 +2.36672170850409745237358105667757760527014332458e-0005L,
76 74 };
77 75 static const long double P2[] = {
78 76 +0.428486815855585429730209907810650135255270600668084114L,
79 77 +2.62768479103809762805691743305424077975230551176e-0001L,
80 78 +3.81187532685392297608310837995193946591425896150e-0002L,
81 79 +3.00063075891811043820666846129131255948527925381e-0003L,
82 80 +2.47315407812279164228398470797498649142513408654e-0003L,
83 81 +3.62838199917848372586173483147214880464782938664e-0004L,
84 82 +3.43991105975492623982725644046473030098172692423e-0006L,
85 83 +4.56902151569603272237014240794257659159045432895e-0006L,
86 84 +2.13734755837595695602045100675540011352948958453e-0007L,
87 85 +9.74123440547918230781670266967882492234877125358e-0009L,
88 86 };
89 87 static const long double Q2[] = {
90 88 +1.0L,
91 89 +9.18284118632506842664645516830761489700556179701e-0001L,
92 90 -6.41430858837830766045202076965923776189154874947e-0003L,
93 91 -1.24400885809771073213345747437964149775410921376e-0001L,
94 92 +4.69803798146251757538856567522481979624746875964e-0003L,
95 93 +7.18309447069495315914284705109868696262662082731e-0003L,
96 94 -8.75812626987894695112722600697653425786166399105e-0004L,
97 95 -1.23539972377769277995959339188431498626674835169e-0004L,
98 96 +3.10019017590151598732360097849672925448587547746e-0005L,
99 97 -1.77260223349332617658921874288026777465782364070e-0006L,
100 98 };
101 99 static const long double P3[] = {
102 100 +0.3824094797345675048502747661075355640070439388902L,
103 101 +3.42198093076618495415854906335908427159833377774e-0001L,
104 102 +9.63828189500585568303961406863153237440702754858e-0002L,
105 103 +8.76069421042696384852462044188520252156846768667e-0003L,
106 104 +1.86477890389161491224872014149309015261897537488e-0003L,
107 105 +8.16871354540309895879974742853701311541286944191e-0004L,
108 106 +6.83783483674600322518695090864659381650125625216e-0005L,
109 107 -1.10168269719261574708565935172719209272190828456e-0006L,
110 108 +9.66243228508380420159234853278906717065629721016e-0007L,
111 109 +2.31858885579177250541163820671121664974334728142e-0008L,
112 110 };
113 111 static const long double Q3[] = {
114 112 +1.0L,
115 113 +8.25479821168813634632437430090376252512793067339e-0001L,
116 114 -1.62251363073937769739639623669295110346015576320e-0002L,
117 115 -1.10621286905916732758745130629426559691187579852e-0001L,
118 116 +3.48309693970985612644446415789230015515365291459e-0003L,
119 117 +6.73553737487488333032431261131289672347043401328e-0003L,
120 118 -7.63222008393372630162743587811004613050245128051e-0004L,
121 119 -1.35792670669190631476784768961953711773073251336e-0004L,
122 120 +3.19610150954223587006220730065608156460205690618e-0005L,
123 121 -1.82096553862822346610109522015129585693354348322e-0006L,
124 122 };
125 123
126 124 static const long double
127 125 #if defined(__x86)
128 126 GZ1_h = 0.938204627909682449364570100414084663498215377L,
129 127 GZ1_l = 4.518346116624229420055327632718530617227944106e-20L,
130 128 GZ2_h = 0.885603194410888700264725126309883762587560340L,
131 129 GZ2_l = 1.409077427270497062039119290776508217077297169e-20L,
132 130 GZ3_h = 0.936781411463652321613537060640553022494714241L,
133 131 GZ3_l = 5.309836440284827247897772963887219035221996813e-21L,
134 132 #else
135 133 GZ1_h = 0.938204627909682449409753561580326910854647031L,
136 134 GZ1_l = 4.684412162199460089642452580902345976446297037e-35L,
137 135 GZ2_h = 0.885603194410888700278815900582588658192658794L,
138 136 GZ2_l = 7.501529273890253789219935569758713534641074860e-35L,
139 137 GZ3_h = 0.936781411463652321618846897080837818855399840L,
140 138 GZ3_l = 3.088721217404784363585591914529361687403776917e-35L,
141 139 #endif
142 140 TZ1 = -0.3517214357852935791015625L,
143 141 TZ3 = 0.280530631542205810546875L;
144 142 /* INDENT ON */
145 143
146 144 /* INDENT OFF */
147 145 /*
148 146 * compute gamma(y=yh+yl) for y in GT1 = [1.0000, 1.2845]
149 147 * ...assume yh got 53 or 24(i386) significant bits
150 148 */
151 149 /* INDENT ON */
152 150 static struct LDouble
153 151 GT1(long double yh, long double yl) {
154 152 long double t3, t4, y;
155 153 int i;
156 154 struct LDouble r;
157 155
158 156 y = yh + yl;
159 157 for (t4 = Q1[8], t3 = P1[8] + y * P1[9], i = 7; i >= 0; i--) {
160 158 t4 = t4 * y + Q1[i];
161 159 t3 = t3 * y + P1[i];
162 160 }
163 161 t3 = (y * y) * t3 / t4;
164 162 t3 += (TZ1 * yl + GZ1_l);
165 163 t4 = TZ1 * yh;
166 164 r.h = CHOPPED((t4 + GZ1_h + t3));
167 165 t3 += (t4 - (r.h - GZ1_h));
168 166 r.l = t3;
169 167 return (r);
170 168 }
171 169
172 170 /* INDENT OFF */
173 171 /*
174 172 * compute gamma(y=yh+yl) for y in GT2 = [1.2844, 1.6374]
175 173 * ...assume yh got 53 significant bits
176 174 */
177 175 /* INDENT ON */
178 176 static struct LDouble
179 177 GT2(long double yh, long double yl) {
180 178 long double t3, t4, y;
181 179 int i;
182 180 struct LDouble r;
183 181
184 182 y = yh + yl;
185 183 for (t4 = Q2[9], t3 = P2[9], i = 8; i >= 0; i--) {
186 184 t4 = t4 * y + Q2[i];
187 185 t3 = t3 * y + P2[i];
188 186 }
189 187 t3 = GZ2_l + (y * y) * t3 / t4;
190 188 r.h = CHOPPED((GZ2_h + t3));
191 189 r.l = t3 - (r.h - GZ2_h);
192 190 return (r);
193 191 }
194 192
195 193 /* INDENT OFF */
196 194 /*
197 195 * compute gamma(y=yh+yl) for y in GT3 = [1.6373, 2.0000]
198 196 * ...assume yh got 53 significant bits
199 197 */
200 198 /* INDENT ON */
201 199 static struct LDouble
202 200 GT3(long double yh, long double yl) {
203 201 long double t3, t4, y;
204 202 int i;
205 203 struct LDouble r;
206 204
207 205 y = yh + yl;
208 206 for (t4 = Q3[9], t3 = P3[9], i = 8; i >= 0; i--) {
209 207 t4 = t4 * y + Q3[i];
210 208 t3 = t3 * y + P3[i];
211 209 }
212 210 t3 = (y * y) * t3 / t4;
213 211 t3 += (TZ3 * yl + GZ3_l);
214 212 t4 = TZ3 * yh;
215 213 r.h = CHOPPED((t4 + GZ3_h + t3));
216 214 t3 += (t4 - (r.h - GZ3_h));
217 215 r.l = t3;
218 216 return (r);
219 217 }
220 218
221 219 /* INDENT OFF */
222 220 /* Hex value of GP[0] shoule be 3FB55555 55555555 */
223 221 static const long double GP[] = {
224 222 +0.083333333333333333333333333333333172839171301L,
225 223 -2.77777777777777777777777777492501211999399424104e-0003L,
226 224 +7.93650793650793650793635650541638236350020883243e-0004L,
227 225 -5.95238095238095238057299772679324503339241961704e-0004L,
228 226 +8.41750841750841696138422987977683524926142600321e-0004L,
229 227 -1.91752691752686682825032547823699662178842123308e-0003L,
230 228 +6.41025641022403480921891559356473451161279359322e-0003L,
231 229 -2.95506535798414019189819587455577003732808185071e-0002L,
232 230 +1.79644367229970031486079180060923073476568732136e-0001L,
233 231 -1.39243086487274662174562872567057200255649290646e+0000L,
234 232 +1.34025874044417962188677816477842265259608269775e+0001L,
235 233 -1.56803713480127469414495545399982508700748274318e+0002L,
236 234 +2.18739841656201561694927630335099313968924493891e+0003L,
237 235 -3.55249848644100338419187038090925410976237921269e+0004L,
238 236 +6.43464880437835286216768959439484376449179576452e+0005L,
239 237 -1.20459154385577014992600342782821389605893904624e+0007L,
240 238 +2.09263249637351298563934942349749718491071093210e+0008L,
241 239 -2.96247483183169219343745316433899599834685703457e+0009L,
242 240 +2.88984933605896033154727626086506756972327292981e+0010L,
243 241 -1.40960434146030007732838382416230610302678063984e+0011L, /* 19 */
244 242 };
245 243
246 244 static const long double T3[] = {
247 245 +0.666666666666666666666666666666666634567834260213L, /* T3[0] */
248 246 +0.400000000000000000000000000040853636176634934140L, /* T3[1] */
249 247 +0.285714285714285714285696975252753987869020263448L, /* T3[2] */
250 248 +0.222222222222222225593221101192317258554772129875L, /* T3[3] */
251 249 +0.181818181817850192105847183461778186703779262916L, /* T3[4] */
252 250 +0.153846169861348633757101285952333369222567014596L, /* T3[5] */
253 251 +0.133033462889260193922261296772841229985047571265L, /* T3[6] */
254 252 };
255 253
256 254 static const long double c[] = {
257 255 0.0L,
258 256 1.0L,
259 257 2.0L,
260 258 0.5L,
261 259 1.0e-4930L, /* tiny */
262 260 4.18937683105468750000e-01L, /* hln2pim1_h */
263 261 8.50099203991780329736405617639861397473637783412817152e-07L, /* hln2pim1_l */
264 262 0.418938533204672741780329736405617639861397473637783412817152L, /* hln2pim1 */
265 263 2.16608493865351192653179168701171875e-02L, /* ln2_32hi */
266 264 5.96317165397058692545083025235937919875797669127130e-12L, /* ln2_32lo */
267 265 46.16624130844682903551758979206054839765267053289554989233L, /* invln2_32 */
268 266 #if defined(__x86)
269 267 1.7555483429044629170023839037639845628291e+03L, /* overflow */
270 268 #else
271 269 1.7555483429044629170038892160702032034177e+03L, /* overflow */
272 270 #endif
273 271 };
274 272
275 273 #define zero c[0]
276 274 #define one c[1]
277 275 #define two c[2]
278 276 #define half c[3]
279 277 #define tiny c[4]
280 278 #define hln2pim1_h c[5]
281 279 #define hln2pim1_l c[6]
282 280 #define hln2pim1 c[7]
283 281 #define ln2_32hi c[8]
284 282 #define ln2_32lo c[9]
285 283 #define invln2_32 c[10]
286 284 #define overflow c[11]
287 285
288 286 /*
289 287 * |exp(r) - (1+r+Et0*r^2+...+Et10*r^12)| <= 2^(-128.88) for |r|<=ln2/64
290 288 */
291 289 static const long double Et[] = {
292 290 +5.0000000000000000000e-1L,
293 291 +1.66666666666666666666666666666828835166292152466e-0001L,
294 292 +4.16666666666666666666666666666693398646592712189e-0002L,
295 293 +8.33333333333333333333331748774512601775591115951e-0003L,
296 294 +1.38888888888888888888888845356011511394764753997e-0003L,
297 295 +1.98412698412698413237140350092993252684198882102e-0004L,
298 296 +2.48015873015873016080222025357442659895814371694e-0005L,
299 297 +2.75573192239028921114572986441972140933432317798e-0006L,
300 298 +2.75573192239448470555548102895526369739856219317e-0007L,
301 299 +2.50521677867683935940853997995937600214167232477e-0008L,
302 300 +2.08767928899010367374984448513685566514152147362e-0009L,
303 301 };
304 302
305 303 /*
306 304 * long double precision coefficients for computing log(x)-1 in tgamma.
307 305 * See "algorithm" for details
308 306 *
309 307 * log(x) - 1 = T1(n) + T2(j) + T3(s), where x = 2**n * y, 1<=y<2,
310 308 * j=[64*y], z[j]=1+j/64+1/128, s = (y-z[j])/(y+z[j]), and
311 309 * T1(n) = T1[2n,2n+1] = n*log(2)-1,
312 310 * T2(j) = T2[2j,2j+1] = log(z[j]),
313 311 * T3(s) = 2s + T3[0]s^3 + T3[1]s^5 + T3[2]s^7 + ... + T3[6]s^15
314 312 * Note
315 313 * (1) the leading entries are truncated to 24 binary point.
316 314 * (2) Remez error for T3(s) is bounded by 2**(-136.54)
317 315 */
318 316 static const long double T1[] = {
319 317 -1.000000000000000000000000000000000000000000e+00L,
320 318 +0.000000000000000000000000000000000000000000e+00L,
321 319 -3.068528175354003906250000000000000000000000e-01L,
322 320 -1.904654299957767878541823431924500011926579e-09L,
323 321 +3.862943053245544433593750000000000000000000e-01L,
324 322 +5.579533617547508924291635313615100141107647e-08L,
325 323 +1.079441487789154052734375000000000000000000e+00L,
326 324 +5.389068187551732136437452970422650211661470e-08L,
327 325 +1.772588670253753662109375000000000000000000e+00L,
328 326 +5.198602757555955348583270627230200282215294e-08L,
329 327 +2.465735852718353271484375000000000000000000e+00L,
330 328 +5.008137327560178560729088284037750352769117e-08L,
331 329 +3.158883035182952880859375000000000000000000e+00L,
332 330 +4.817671897564401772874905940845299849351090e-08L,
333 331 +3.852030217647552490234375000000000000000000e+00L,
334 332 +4.627206467568624985020723597652849919904913e-08L,
335 333 +4.545177400112152099609375000000000000000000e+00L,
336 334 +4.436741037572848197166541254460399990458737e-08L,
337 335 +5.238324582576751708984375000000000000000000e+00L,
338 336 +4.246275607577071409312358911267950061012560e-08L,
339 337 +5.931471765041351318359375000000000000000000e+00L,
340 338 +4.055810177581294621458176568075500131566384e-08L,
341 339 };
342 340
343 341 /*
344 342 * T2[2i,2i+1] = log(1+i/64+1/128)
345 343 */
346 344 static const long double T2[] = {
347 345 +7.7821016311645507812500000000000000000000e-03L,
348 346 +3.8810890398166212900061136763678127453570e-08L,
349 347 +2.3167014122009277343750000000000000000000e-02L,
350 348 +4.5159525100885049160962289916579411752759e-08L,
351 349 +3.8318812847137451171875000000000000000000e-02L,
352 350 +5.1454999148021880325123797290345960518164e-08L,
353 351 +5.3244471549987792968750000000000000000000e-02L,
354 352 +4.2968824489897120193786528776939573415076e-08L,
355 353 +6.7950606346130371093750000000000000000000e-02L,
356 354 +5.5562377378300815277772629414034632394030e-08L,
357 355 +8.2443654537200927734375000000000000000000e-02L,
358 356 +1.4673873663533785068668307805914095366600e-08L,
359 357 +9.6729576587677001953125000000000000000000e-02L,
360 358 +4.9870874110342446056487463437015041543346e-08L,
361 359 +1.1081433296203613281250000000000000000000e-01L,
362 360 +3.3378253981382306169323211928098474801099e-08L,
363 361 +1.2470346689224243164062500000000000000000e-01L,
364 362 +1.1608714804222781515380863268491613205318e-08L,
365 363 +1.3840228319168090820312500000000000000000e-01L,
366 364 +3.9667438227482200873601649187393160823607e-08L,
367 365 +1.5191602706909179687500000000000000000000e-01L,
368 366 +1.4956750178196803424896884511327584958252e-08L,
369 367 +1.6524952650070190429687500000000000000000e-01L,
370 368 +4.6394605258578736449277240313729237989366e-08L,
371 369 +1.7840760946273803710937500000000000000000e-01L,
372 370 +4.8010080260010025241510941968354682199540e-08L,
373 371 +1.9139480590820312500000000000000000000000e-01L,
374 372 +4.7091426329609298807561308873447039132856e-08L,
375 373 +2.0421552658081054687500000000000000000000e-01L,
376 374 +1.4847880344628820386196239272213742113867e-08L,
377 375 +2.1687388420104980468750000000000000000000e-01L,
378 376 +5.4099564554931589525744347498478964801484e-08L,
379 377 +2.2937405109405517578125000000000000000000e-01L,
380 378 +4.9970790654210230725046139871550961365282e-08L,
381 379 +2.4171990156173706054687500000000000000000e-01L,
382 380 +3.5325408107597432515913513900103385655073e-08L,
383 381 +2.5391519069671630859375000000000000000000e-01L,
384 382 +1.9284247135543573297906606667466299224747e-08L,
385 383 +2.6596349477767944335937500000000000000000e-01L,
386 384 +5.3719458497979750926537543389268821141517e-08L,
387 385 +2.7786844968795776367187500000000000000000e-01L,
388 386 +1.3154985425144750329234012330820349974537e-09L,
389 387 +2.8963327407836914062500000000000000000000e-01L,
390 388 +1.8504673536253893055525668970003860369760e-08L,
391 389 +3.0126130580902099609375000000000000000000e-01L,
392 390 +2.4769140784919125538233755492657352680723e-08L,
393 391 +3.1275570392608642578125000000000000000000e-01L,
394 392 +6.0778104626049965596883190321597861455475e-09L,
395 393 +3.2411944866180419921875000000000000000000e-01L,
396 394 +1.9992407776871920760434987352182336158873e-08L,
397 395 +3.3535552024841308593750000000000000000000e-01L,
398 396 +2.1672724744319679579814166199074433006807e-08L,
399 397 +3.4646672010421752929687500000000000000000e-01L,
400 398 +4.7241991051621587188425772950711830538414e-08L,
401 399 +3.5745584964752197265625000000000000000000e-01L,
402 400 +3.9274281801569759490140904474434669956562e-08L,
403 401 +3.6832553148269653320312500000000000000000e-01L,
404 402 +2.9676011119845105154050398826897178765758e-08L,
405 403 +3.7907832860946655273437500000000000000000e-01L,
406 404 +2.4325502905656478345631019858881408009210e-08L,
407 405 +3.8971674442291259765625000000000000000000e-01L,
408 406 +6.7171126157142136040035208670510556529487e-09L,
409 407 +4.0024316310882568359375000000000000000000e-01L,
410 408 +1.0181870233355751019951311700799406124957e-09L,
411 409 +4.1065990924835205078125000000000000000000e-01L,
412 410 +1.5736916335153056203175822787661567534220e-08L,
413 411 +4.2096924781799316406250000000000000000000e-01L,
414 412 +4.6826136472066367161506795972449857268707e-08L,
415 413 +4.3117344379425048828125000000000000000000e-01L,
416 414 +2.1024120852577922478955594998480144051225e-08L,
417 415 +4.4127452373504638671875000000000000000000e-01L,
418 416 +3.7069828842770746441661301225362605528786e-08L,
419 417 +4.5127463340759277343750000000000000000000e-01L,
420 418 +1.0731865811707192383079012478685922879010e-08L,
421 419 +4.6117568016052246093750000000000000000000e-01L,
422 420 +3.4961647705430499925597855358603099030515e-08L,
423 421 +4.7097969055175781250000000000000000000000e-01L,
424 422 +2.4667033200046897856056359251373510964634e-08L,
425 423 +4.8068851232528686523437500000000000000000e-01L,
426 424 +1.7020465042442243455448011551208861216878e-08L,
427 425 +4.9030393362045288085937500000000000000000e-01L,
428 426 +5.4424740957290971159645746860530583309571e-08L,
429 427 +4.9982786178588867187500000000000000000000e-01L,
430 428 +7.7705606579463314152470441415126573566105e-09L,
431 429 +5.0926184654235839843750000000000000000000e-01L,
432 430 +5.5247449548366574919228323824878565745713e-08L,
433 431 +5.1860773563385009765625000000000000000000e-01L,
434 432 +2.8574195534496726996364798698556235730848e-08L,
435 433 +5.2786707878112792968750000000000000000000e-01L,
436 434 +1.0839714455426392217778300963558522088193e-08L,
437 435 +5.3704142570495605468750000000000000000000e-01L,
438 436 +4.0191927599879229244153832299023744345999e-08L,
439 437 +5.4613238573074340820312500000000000000000e-01L,
440 438 +5.1867392242179272209231209163864971792889e-08L,
441 439 +5.5514144897460937500000000000000000000000e-01L,
442 440 +5.8565892217715480359515904050170125743178e-08L,
443 441 +5.6407010555267333984375000000000000000000e-01L,
444 442 +3.2732129626227634290090190711817681692354e-08L,
445 443 +5.7291972637176513671875000000000000000000e-01L,
446 444 +2.7190020372374006726626261068626400393936e-08L,
447 445 +5.8169168233871459960937500000000000000000e-01L,
448 446 +5.7295907882911235753725372340709967597394e-08L,
449 447 +5.9038740396499633789062500000000000000000e-01L,
450 448 +4.2637180036751291708123598757577783615014e-08L,
451 449 +5.9900814294815063476562500000000000000000e-01L,
452 450 +4.6697932764615975024461651502060474048774e-08L,
453 451 +6.0755521059036254882812500000000000000000e-01L,
454 452 +3.9634179246672960152791125371893149820625e-08L,
455 453 +6.1602985858917236328125000000000000000000e-01L,
456 454 +1.8626341656366315928196700650292529688219e-08L,
457 455 +6.2443327903747558593750000000000000000000e-01L,
458 456 +8.9744179151050387440546731199093039879228e-09L,
459 457 +6.3276666402816772460937500000000000000000e-01L,
460 458 +5.5428701049364114685035797584887586099726e-09L,
461 459 +6.4103114604949951171875000000000000000000e-01L,
462 460 +3.3371431779336851334405392546708949047361e-08L,
463 461 +6.4922791719436645507812500000000000000000e-01L,
464 462 +2.9430743363812714969905311122271269100885e-08L,
465 463 +6.5735805034637451171875000000000000000000e-01L,
466 464 +2.2361985518423140023245936165514147093250e-08L,
467 465 +6.6542261838912963867187500000000000000000e-01L,
468 466 +1.4155960810278217610006660181148303091649e-08L,
469 467 +6.7342263460159301757812500000000000000000e-01L,
470 468 +4.0610573702719835388801017264750843477878e-08L,
471 469 +6.8135917186737060546875000000000000000000e-01L,
472 470 +5.2940532463479321559568089441735584156689e-08L,
473 471 +6.8923324346542358398437500000000000000000e-01L,
474 472 +3.7773385396340539337814603903232796216537e-08L,
475 473 };
476 474
477 475 /*
478 476 * S[j],S_trail[j] = 2**(j/32.) for the final computation of exp(t+w)
479 477 */
480 478 static const long double S[] = {
481 479 #if defined(__x86)
482 480 +1.0000000000000000000000000e+00L,
483 481 +1.0218971486541166782081522e+00L,
484 482 +1.0442737824274138402382006e+00L,
485 483 +1.0671404006768236181297224e+00L,
486 484 +1.0905077326652576591003302e+00L,
487 485 +1.1143867425958925362894369e+00L,
488 486 +1.1387886347566916536971221e+00L,
489 487 +1.1637248587775775137938619e+00L,
490 488 +1.1892071150027210666875674e+00L,
491 489 +1.2152473599804688780476325e+00L,
492 490 +1.2418578120734840485256747e+00L,
493 491 +1.2690509571917332224885722e+00L,
494 492 +1.2968395546510096659215822e+00L,
495 493 +1.3252366431597412945939118e+00L,
496 494 +1.3542555469368927282668852e+00L,
497 495 +1.3839098819638319548151403e+00L,
498 496 +1.4142135623730950487637881e+00L,
499 497 +1.4451808069770466200253470e+00L,
500 498 +1.4768261459394993113155431e+00L,
501 499 +1.5091644275934227397133885e+00L,
502 500 +1.5422108254079408235859630e+00L,
503 501 +1.5759808451078864864006862e+00L,
504 502 +1.6104903319492543080837174e+00L,
505 503 +1.6457554781539648445110730e+00L,
506 504 +1.6817928305074290860378350e+00L,
507 505 +1.7186192981224779156032914e+00L,
508 506 +1.7562521603732994831094730e+00L,
509 507 +1.7947090750031071864148413e+00L,
510 508 +1.8340080864093424633989166e+00L,
511 509 +1.8741676341102999013002103e+00L,
512 510 +1.9152065613971472938202589e+00L,
513 511 +1.9571441241754002689657438e+00L,
514 512 #else
515 513 +1.00000000000000000000000000000000000e+00L,
516 514 +1.02189714865411667823448013478329942e+00L,
517 515 +1.04427378242741384032196647873992910e+00L,
518 516 +1.06714040067682361816952112099280918e+00L,
519 517 +1.09050773266525765920701065576070789e+00L,
520 518 +1.11438674259589253630881295691960313e+00L,
521 519 +1.13878863475669165370383028384151134e+00L,
522 520 +1.16372485877757751381357359909218536e+00L,
523 521 +1.18920711500272106671749997056047593e+00L,
524 522 +1.21524735998046887811652025133879836e+00L,
525 523 +1.24185781207348404859367746872659561e+00L,
526 524 +1.26905095719173322255441908103233805e+00L,
527 525 +1.29683955465100966593375411779245118e+00L,
528 526 +1.32523664315974129462953709549872168e+00L,
529 527 +1.35425554693689272829801474014070273e+00L,
530 528 +1.38390988196383195487265952726519287e+00L,
531 529 +1.41421356237309504880168872420969798e+00L,
532 530 +1.44518080697704662003700624147167095e+00L,
533 531 +1.47682614593949931138690748037404985e+00L,
534 532 +1.50916442759342273976601955103319352e+00L,
535 533 +1.54221082540794082361229186209073479e+00L,
536 534 +1.57598084510788648645527016018190504e+00L,
537 535 +1.61049033194925430817952066735740067e+00L,
538 536 +1.64575547815396484451875672472582254e+00L,
539 537 +1.68179283050742908606225095246642969e+00L,
540 538 +1.71861929812247791562934437645631244e+00L,
541 539 +1.75625216037329948311216061937531314e+00L,
542 540 +1.79470907500310718642770324212778174e+00L,
543 541 +1.83400808640934246348708318958828892e+00L,
544 542 +1.87416763411029990132999894995444645e+00L,
545 543 +1.91520656139714729387261127029583086e+00L,
546 544 +1.95714412417540026901832225162687149e+00L,
547 545 #endif
548 546 };
549 547 static const long double S_trail[] = {
550 548 #if defined(__x86)
551 549 +0.0000000000000000000000000e+00L,
552 550 +2.6327965667180882569382524e-20L,
553 551 +8.3765863521895191129661899e-20L,
554 552 +3.9798705777454504249209575e-20L,
555 553 +1.0668046596651558640993042e-19L,
556 554 +1.9376009847285360448117114e-20L,
557 555 +6.7081819456112953751277576e-21L,
558 556 +1.9711680502629186462729727e-20L,
559 557 +2.9932584438449523689104569e-20L,
560 558 +6.8887754153039109411061914e-20L,
561 559 +6.8002718741225378942847820e-20L,
562 560 +6.5846917376975403439742349e-20L,
563 561 +1.2171958727511372194876001e-20L,
564 562 +3.5625253228704087115438260e-20L,
565 563 +3.1129551559077560956309179e-20L,
566 564 +5.7519192396164779846216492e-20L,
567 565 +3.7900651177865141593101239e-20L,
568 566 +1.1659262405698741798080115e-20L,
569 567 +7.1364385105284695967172478e-20L,
570 568 +5.2631003710812203588788949e-20L,
571 569 +2.6328853788732632868460580e-20L,
572 570 +5.4583950085438242788190141e-20L,
573 571 +9.5803254376938269960718656e-20L,
574 572 +7.6837733983874245823512279e-21L,
575 573 +2.4415965910835093824202087e-20L,
576 574 +2.6052966871016580981769728e-20L,
577 575 +2.6876456344632553875309579e-21L,
578 576 +1.2861930155613700201703279e-20L,
579 577 +8.8166633394037485606572294e-20L,
580 578 +2.9788615389580190940837037e-20L,
581 579 +5.2352341619805098677422139e-20L,
582 580 +5.2578463064010463732242363e-20L,
583 581 #else
584 582 +0.00000000000000000000000000000000000e+00L,
585 583 +1.80506787420330954745573333054573786e-35L,
586 584 -9.37452029228042742195756741973083214e-35L,
587 585 -1.59696844729275877071290963023149997e-35L,
588 586 +9.11249341012502297851168610167248666e-35L,
589 587 -6.50422820697854828723037477525938871e-35L,
590 588 -8.14846884452585113732569176748815532e-35L,
591 589 -5.06621457672180031337233074514290335e-35L,
592 590 -1.35983097468881697374987563824591912e-35L,
593 591 +9.49742763556319647030771056643324660e-35L,
594 592 -3.28317052317699860161506596533391526e-36L,
595 593 -5.01723570938719041029018653045842895e-35L,
596 594 -2.39147479768910917162283430160264014e-35L,
597 595 -8.35057135763390881529889073794408385e-36L,
598 596 +7.03675688907326504242173719067187644e-35L,
599 597 -5.18248485306464645753689301856695619e-35L,
600 598 +9.42224254862183206569211673639406488e-35L,
601 599 -3.96750082539886230916730613021641828e-35L,
602 600 +7.14352899156330061452327361509276724e-35L,
603 601 +1.15987125286798512424651783410044433e-35L,
604 602 +4.69693347835811549530973921320187447e-35L,
605 603 -3.38651317599500471079924198499981917e-35L,
606 604 -8.58731877429824706886865593510387445e-35L,
607 605 -9.60595154874935050318549936224606909e-35L,
608 606 +9.60973393212801278450755869714178581e-35L,
609 607 +6.37839792144002843924476144978084855e-35L,
610 608 +7.79243078569586424945646112516927770e-35L,
611 609 +7.36133776758845652413193083663393220e-35L,
612 610 -6.47299514791334723003521457561217053e-35L,
613 611 +8.58747441795369869427879806229522962e-35L,
614 612 +2.37181542282517483569165122830269098e-35L,
615 613 -3.02689168209611877300459737342190031e-37L,
616 614 #endif
617 615 };
618 616 /* INDENT ON */
619 617
620 618 /* INDENT OFF */
621 619 /*
622 620 * return tgamma(x) scaled by 2**-m for 8<x<=171.62... using Stirling's formula
623 621 * log(G(x)) ~= (x-.5)*(log(x)-1) + .5(log(2*pi)-1) + (1/x)*P(1/(x*x))
624 622 * = L1 + L2 + L3,
625 623 */
626 624 /* INDENT ON */
627 625 static struct LDouble
628 626 large_gam(long double x, int *m) {
629 627 long double z, t1, t2, t3, z2, t5, w, y, u, r, v;
630 628 long double t24 = 16777216.0L, p24 = 1.0L / 16777216.0L;
631 629 int n2, j2, k, ix, j, i;
632 630 struct LDouble zz;
633 631 long double u2, ss_h, ss_l, r_h, w_h, w_l, t4;
634 632
635 633 /* INDENT OFF */
636 634 /*
637 635 * compute ss = ss.h+ss.l = log(x)-1 (see tgamma_log.h for details)
638 636 *
639 637 * log(x) - 1 = T1(n) + T2(j) + T3(s), where x = 2**n * y, 1<=y<2,
640 638 * j=[64*y], z[j]=1+j/64+1/128, s = (y-z[j])/(y+z[j]), and
641 639 * T1(n) = T1[2n,2n+1] = n*log(2)-1,
642 640 * T2(j) = T2[2j,2j+1] = log(z[j]),
643 641 * T3(s) = 2s + T3[0]s^3 + T3[1]s^5 + ... + T3[6]s^15
644 642 * Note
645 643 * (1) the leading entries are truncated to 24 binary point.
646 644 * (2) Remez error for T3(s) is bounded by 2**(-72.4)
647 645 * 2**(-24)
648 646 * _________V___________________
649 647 * T1(n): |_________|___________________|
650 648 * _______ ______________________
651 649 * T2(j): |_______|______________________|
652 650 * ____ _______________________
653 651 * 2s: |____|_______________________|
654 652 * __________________________
655 653 * + T3(s)-2s: |__________________________|
656 654 * -------------------------------------------
657 655 * [leading] + [Trailing]
658 656 */
659 657 /* INDENT ON */
660 658 ix = H0_WORD(x);
661 659 n2 = (ix >> 16) - 0x3fff; /* exponent of x, range:3-10 */
662 660 y = scalbnl(x, -n2); /* y = scale x to [1,2] */
663 661 n2 += n2; /* 2n */
664 662 j = (ix >> 10) & 0x3f; /* j */
665 663 z = 1.0078125L + (long double) j * 0.015625L; /* z[j]=1+j/64+1/128 */
666 664 j2 = j + j;
667 665 t1 = y + z;
668 666 t2 = y - z;
669 667 r = one / t1;
670 668 u = r * t2; /* u = (y-z)/(y+z) */
671 669 t1 = CHOPPED(t1);
672 670 t4 = T2[j2 + 1] + T1[n2 + 1];
673 671 z2 = u * u;
674 672 k = H0_WORD(u) & 0x7fffffff;
675 673 t3 = T2[j2] + T1[n2];
676 674 for (t5 = T3[6], i = 5; i >= 0; i--)
677 675 t5 = z2 * t5 + T3[i];
678 676 if ((k >> 16) < 0x3fec) { /* |u|<2**-19 */
679 677 t2 = t4 + u * (two + z2 * t5);
680 678 } else {
681 679 t5 = t4 + (u * z2) * t5;
682 680 u2 = u + u;
683 681 v = (long double) ((int) (u2 * t24)) * p24;
684 682 t2 = t5 + r * ((two * t2 - v * t1) - v * (y - (t1 - z)));
685 683 t3 += v;
686 684 }
687 685 ss_h = CHOPPED((t2 + t3));
688 686 ss_l = t2 - (ss_h - t3);
689 687 /* INDENT OFF */
690 688 /*
691 689 * compute ww = (x-.5)*(log(x)-1) + .5*(log(2pi)-1) + 1/x*(P(1/x^2)))
692 690 * where ss = log(x) - 1 in already in extra precision
693 691 */
694 692 /* INDENT ON */
695 693 z = one / x;
696 694 r = x - half;
697 695 r_h = CHOPPED((r));
698 696 w_h = r_h * ss_h + hln2pim1_h;
699 697 z2 = z * z;
700 698 w = (r - r_h) * ss_h + r * ss_l;
701 699 t1 = GP[19];
702 700 for (i = 18; i > 0; i--)
703 701 t1 = z2 * t1 + GP[i];
704 702 w += hln2pim1_l;
705 703 w_l = z * (GP[0] + z2 * t1) + w;
706 704 k = (int) ((w_h + w_l) * invln2_32 + half);
707 705
708 706 /* compute the exponential of w_h+w_l */
709 707
710 708 j = k & 0x1f;
711 709 *m = k >> 5;
712 710 t3 = (long double) k;
713 711
714 712 /* perform w - k*ln2_32 (represent as w_h - w_l) */
715 713 t1 = w_h - t3 * ln2_32hi;
716 714 t2 = t3 * ln2_32lo;
717 715 w = t2 - w_l;
718 716 w_h = t1 - w;
719 717 w_l = w - (t1 - w_h);
720 718
721 719 /* compute exp(w_h-w_l) */
722 720 z = w_h - w_l;
723 721 for (t1 = Et[10], i = 9; i >= 0; i--)
724 722 t1 = z * t1 + Et[i];
725 723 t3 = w_h - (w_l - (z * z) * t1); /* t3 = expm1(z) */
726 724 zz.l = S_trail[j] * (one + t3) + S[j] * t3;
727 725 zz.h = S[j];
728 726 return (zz);
729 727 }
730 728
731 729 /* INDENT OFF */
732 730 /*
733 731 * kpsin(x)= sin(pi*x)/pi
734 732 * 3 5 7 9 11 27
735 733 * = x+ks[0]*x +ks[1]*x +ks[2]*x +ks[3]*x +ks[4]*x + ... + ks[12]*x
736 734 */
737 735 static const long double ks[] = {
738 736 -1.64493406684822643647241516664602518705158902870e+0000L,
739 737 +8.11742425283353643637002772405874238094995726160e-0001L,
740 738 -1.90751824122084213696472111835337366232282723933e-0001L,
741 739 +2.61478478176548005046532613563241288115395517084e-0002L,
742 740 -2.34608103545582363750893072647117829448016479971e-0003L,
743 741 +1.48428793031071003684606647212534027556262040158e-0004L,
744 742 -6.97587366165638046518462722252768122615952898698e-0006L,
745 743 +2.53121740413702536928659271747187500934840057929e-0007L,
746 744 -7.30471182221385990397683641695766121301933621956e-0009L,
747 745 +1.71653847451163495739958249695549313987973589884e-0010L,
748 746 -3.34813314714560776122245796929054813458341420565e-0012L,
749 747 +5.50724992262622033449487808306969135431411753047e-0014L,
750 748 -7.67678132753577998601234393215802221104236979928e-0016L,
751 749 };
752 750 /* INDENT ON */
753 751
754 752 /*
755 753 * assume x is not tiny and positive
756 754 */
757 755 static struct LDouble
758 756 kpsin(long double x) {
759 757 long double z, t1, t2;
760 758 struct LDouble xx;
761 759 int i;
762 760
763 761 z = x * x;
764 762 xx.h = x;
765 763 for (t2 = ks[12], i = 11; i > 0; i--)
766 764 t2 = z * t2 + ks[i];
767 765 t1 = z * x;
768 766 t2 *= z * t1;
769 767 xx.l = t1 * ks[0] + t2;
770 768 return (xx);
771 769 }
772 770
773 771 /* INDENT OFF */
774 772 /*
775 773 * kpcos(x)= cos(pi*x)/pi
776 774 * 2 4 6 8 10 12
777 775 * = 1/pi +kc[0]*x +kc[1]*x +kc[2]*x +kc[3]*x +kc[4]*x +kc[5]*x
778 776 *
779 777 * 2 4 6 8 10 22
780 778 * = 1/pi - pi/2*x +kc[0]*x +kc[1]*x +kc[2]*x +kc[3]*x +...+kc[9]*x
781 779 *
782 780 * -pi/2*x*x = (npi_2_h + npi_2_l) * (x_f+x_l)*(x_f+x_l)
783 781 * = npi_2_h*(x_f+x_l)*(x_f+x_l) + npi_2_l*x*x
784 782 * = npi_2_h*x_f*x_f + npi_2_h*(x*x-x_f*x_f) + npi_2_l*x*x
785 783 * = npi_2_h*x_f*x_f + npi_2_h*(x+x_f)*(x-x_f) + npi_2_l*x*x
786 784 * Here x_f = (long double) (float)x
787 785 * Note that pi/2(in hex) =
788 786 * 1.921FB54442D18469898CC51701B839A252049C1114CF98E804177D4C76273644A29
789 787 * npi_2_h = -pi/2 chopped to 25 bits = -1.921FB50000000000000000000000000 =
790 788 * -1.570796310901641845703125000000000 and
791 789 * npi_2_l =
792 790 * -0.0000004442D18469898CC51701B839A252049C1114CF98E804177D4C76273644A29 =
793 791 * -.0000000158932547735281966916397514420985846996875529104874722961539 =
794 792 * -1.5893254773528196691639751442098584699687552910487472296153e-8
795 793 * 1/pi(in hex) =
796 794 * .517CC1B727220A94FE13ABE8FA9A6EE06DB14ACC9E21C820FF28B1D5EF5DE2B
797 795 * will be splitted into:
798 796 * one_pi_h = 1/pi chopped to 48 bits = .517CC1B727220000000000... and
799 797 * one_pi_l = .0000000000000A94FE13ABE8FA9A6EE06DB14ACC9E21C820FF28B1D5EF5DE2B
800 798 */
801 799
802 800 static const long double
803 801 #if defined(__x86)
804 802 one_pi_h = 0.3183098861481994390487670898437500L, /* 31 bits */
805 803 one_pi_l = 3.559123248900043690127872406891929148e-11L,
806 804 #else
807 805 one_pi_h = 0.31830988618379052468299050815403461456298828125L,
808 806 one_pi_l = 1.46854777018590994109505931010230912897495334688117e-16L,
809 807 #endif
810 808 npi_2_h = -1.570796310901641845703125000000000L,
811 809 npi_2_l = -1.5893254773528196691639751442098584699687552910e-8L;
812 810
813 811 static const long double kc[] = {
814 812 +1.29192819501249250731151312779548918765320728489e+0000L,
815 813 -4.25027339979557573976029596929319207009444090366e-0001L,
816 814 +7.49080661650990096109672954618317623888421628613e-0002L,
817 815 -8.21458866111282287985539464173976555436050215120e-0003L,
818 816 +6.14202578809529228503205255165761204750211603402e-0004L,
819 817 -3.33073432691149607007217330302595267179545908740e-0005L,
820 818 +1.36970959047832085796809745461530865597993680204e-0006L,
821 819 -4.41780774262583514450246512727201806217271097336e-0008L,
822 820 +1.14741409212381858820016567664488123478660705759e-0009L,
823 821 -2.44261236114707374558437500654381006300502749632e-0011L,
824 822 };
825 823 /* INDENT ON */
826 824
827 825 /*
828 826 * assume x is not tiny and positive
829 827 */
830 828 static struct LDouble
831 829 kpcos(long double x) {
832 830 long double z, t1, t2, t3, t4, x4, x8;
833 831 int i;
834 832 struct LDouble xx;
835 833
836 834 z = x * x;
837 835 xx.h = one_pi_h;
838 836 t1 = (long double) ((float) x);
839 837 x4 = z * z;
840 838 t2 = npi_2_l * z + npi_2_h * (x + t1) * (x - t1);
841 839 for (i = 8, t3 = kc[9]; i >= 0; i--)
842 840 t3 = z * t3 + kc[i];
843 841 t3 = one_pi_l + x4 * t3;
844 842 t4 = t1 * t1 * npi_2_h;
845 843 x8 = t2 + t3;
846 844 xx.l = x8 + t4;
847 845 return (xx);
848 846 }
849 847
850 848 /* INDENT OFF */
851 849 static const long double
852 850 /* 0.13486180573279076968979393577465291700642511139552429398233 */
853 851 #if defined(__x86)
854 852 t0z1 = 0.1348618057327907696779385054997035808810L,
855 853 t0z1_l = 1.1855430274949336125392717150257379614654e-20L,
856 854 #else
857 855 t0z1 = 0.1348618057327907696897939357746529168654L,
858 856 t0z1_l = 1.4102088588676879418739164486159514674310e-37L,
859 857 #endif
860 858 /* 0.46163214496836234126265954232572132846819620400644635129599 */
861 859 #if defined(__x86)
862 860 t0z2 = 0.4616321449683623412538115843295472018326L,
863 861 t0z2_l = 8.84795799617412663558532305039261747030640e-21L,
864 862 #else
865 863 t0z2 = 0.46163214496836234126265954232572132343318L,
866 864 t0z2_l = 5.03501162329616380465302666480916271611101e-36L,
867 865 #endif
868 866 /* 0.81977310110050060178786870492160699631174407846245179119586 */
869 867 #if defined(__x86)
870 868 t0z3 = 0.81977310110050060178773362329351925836817L,
871 869 t0z3_l = 1.350816280877379435658077052534574556256230e-22L
872 870 #else
873 871 t0z3 = 0.8197731011005006017878687049216069516957449L,
874 872 t0z3_l = 4.461599916947014419045492615933551648857380e-35L
875 873 #endif
876 874 ;
877 875 /* INDENT ON */
878 876
879 877 /*
880 878 * gamma(x+i) for 0 <= x < 1
881 879 */
882 880 static struct LDouble
883 881 gam_n(int i, long double x) {
884 882 struct LDouble rr = {0.0L, 0.0L}, yy;
885 883 long double r1, r2, t2, z, xh, xl, yh, yl, zh, z1, z2, zl, x5, wh, wl;
886 884
887 885 /* compute yy = gamma(x+1) */
888 886 if (x > 0.2845L) {
889 887 if (x > 0.6374L) {
890 888 r1 = x - t0z3;
891 889 r2 = CHOPPED((r1 - t0z3_l));
892 890 t2 = r1 - r2;
893 891 yy = GT3(r2, t2 - t0z3_l);
894 892 } else {
895 893 r1 = x - t0z2;
896 894 r2 = CHOPPED((r1 - t0z2_l));
897 895 t2 = r1 - r2;
898 896 yy = GT2(r2, t2 - t0z2_l);
899 897 }
900 898 } else {
901 899 r1 = x - t0z1;
902 900 r2 = CHOPPED((r1 - t0z1_l));
903 901 t2 = r1 - r2;
904 902 yy = GT1(r2, t2 - t0z1_l);
905 903 }
906 904 /* compute gamma(x+i) = (x+i-1)*...*(x+1)*yy, 0<i<8 */
907 905 switch (i) {
908 906 case 0: /* yy/x */
909 907 r1 = one / x;
910 908 xh = CHOPPED((x)); /* x is not tiny */
911 909 rr.h = CHOPPED(((yy.h + yy.l) * r1));
912 910 rr.l = r1 * (yy.h - rr.h * xh) - ((r1 * rr.h) * (x - xh) -
913 911 r1 * yy.l);
914 912 break;
915 913 case 1: /* yy */
916 914 rr.h = yy.h;
917 915 rr.l = yy.l;
918 916 break;
919 917 case 2: /* (x+1)*yy */
920 918 z = x + one; /* may not be exact */
921 919 zh = CHOPPED((z));
922 920 rr.h = zh * yy.h;
923 921 rr.l = z * yy.l + (x - (zh - one)) * yy.h;
924 922 break;
925 923 case 3: /* (x+2)*(x+1)*yy */
926 924 z1 = x + one;
927 925 z2 = x + 2.0L;
928 926 z = z1 * z2;
929 927 xh = CHOPPED((z));
930 928 zh = CHOPPED((z1));
931 929 xl = (x - (zh - one)) * (z2 + zh) - (xh - zh * (zh + one));
932 930
933 931 rr.h = xh * yy.h;
934 932 rr.l = z * yy.l + xl * yy.h;
935 933 break;
936 934
937 935 case 4: /* (x+1)*(x+3)*(x+2)*yy */
938 936 z1 = x + 2.0L;
939 937 z2 = (x + one) * (x + 3.0L);
940 938 zh = CHOPPED(z1);
941 939 zl = x - (zh - 2.0L);
942 940 xh = CHOPPED(z2);
943 941 xl = zl * (zh + z1) - (xh - (zh * zh - one));
944 942
945 943 /* wh+wl=(x+2)*yy */
946 944 wh = CHOPPED((z1 * (yy.h + yy.l)));
947 945 wl = (zl * yy.h + z1 * yy.l) - (wh - zh * yy.h);
948 946
949 947 rr.h = xh * wh;
950 948 rr.l = z2 * wl + xl * wh;
951 949
952 950 break;
953 951 case 5: /* ((x+1)*(x+4)*(x+2)*(x+3))*yy */
954 952 z1 = x + 2.0L;
955 953 z2 = x + 3.0L;
956 954 z = z1 * z2;
957 955 zh = CHOPPED((z1));
958 956 yh = CHOPPED((z));
959 957 yl = (x - (zh - 2.0L)) * (z2 + zh) - (yh - zh * (zh + one));
960 958 z2 = z - 2.0L;
961 959 z *= z2;
962 960 xh = CHOPPED((z));
963 961 xl = yl * (z2 + yh) - (xh - yh * (yh - 2.0L));
964 962 rr.h = xh * yy.h;
965 963 rr.l = z * yy.l + xl * yy.h;
966 964 break;
967 965 case 6: /* ((x+1)*(x+2)*(x+3)*(x+4)*(x+5))*yy */
968 966 z1 = x + 2.0L;
969 967 z2 = x + 3.0L;
970 968 z = z1 * z2;
971 969 zh = CHOPPED((z1));
972 970 yh = CHOPPED((z));
973 971 z1 = x - (zh - 2.0L);
974 972 yl = z1 * (z2 + zh) - (yh - zh * (zh + one));
975 973 z2 = z - 2.0L;
976 974 x5 = x + 5.0L;
977 975 z *= z2;
978 976 xh = CHOPPED(z);
979 977 zh += 3.0;
980 978 xl = yl * (z2 + yh) - (xh - yh * (yh - 2.0L));
981 979 /* xh+xl=(x+1)*...*(x+4) */
982 980 /* wh+wl=(x+5)*yy */
983 981 wh = CHOPPED((x5 * (yy.h + yy.l)));
984 982 wl = (z1 * yy.h + x5 * yy.l) - (wh - zh * yy.h);
985 983 rr.h = wh * xh;
986 984 rr.l = z * wl + xl * wh;
987 985 break;
988 986 case 7: /* ((x+1)*(x+2)*(x+3)*(x+4)*(x+5)*(x+6))*yy */
989 987 z1 = x + 3.0L;
990 988 z2 = x + 4.0L;
991 989 z = z2 * z1;
992 990 zh = CHOPPED((z1));
993 991 yh = CHOPPED((z)); /* yh+yl = (x+3)(x+4) */
994 992 yl = (x - (zh - 3.0L)) * (z2 + zh) - (yh - (zh * (zh + one)));
995 993 z1 = x + 6.0L;
996 994 z2 = z - 2.0L; /* z2 = (x+2)*(x+5) */
997 995 z *= z2;
998 996 xh = CHOPPED((z));
999 997 xl = yl * (z2 + yh) - (xh - yh * (yh - 2.0L));
1000 998 /* xh+xl=(x+2)*...*(x+5) */
1001 999 /* wh+wl=(x+1)(x+6)*yy */
1002 1000 z2 -= 4.0L; /* z2 = (x+1)(x+6) */
1003 1001 wh = CHOPPED((z2 * (yy.h + yy.l)));
1004 1002 wl = (z2 * yy.l + yl * yy.h) - (wh - (yh - 6.0L) * yy.h);
1005 1003 rr.h = wh * xh;
1006 1004 rr.l = z * wl + xl * wh;
1007 1005 }
1008 1006 return (rr);
1009 1007 }
1010 1008
1011 1009 long double
1012 1010 tgammal(long double x) {
1013 1011 struct LDouble ss, ww;
1014 1012 long double t, t1, t2, t3, t4, t5, w, y, z, z1, z2, z3, z5;
1015 1013 int i, j, m, ix, hx, xk;
1016 1014 unsigned lx;
1017 1015
1018 1016 hx = H0_WORD(x);
1019 1017 lx = H3_WORD(x);
1020 1018 ix = hx & 0x7fffffff;
1021 1019 y = x;
1022 1020 if (ix < 0x3f8e0000) { /* x < 2**-113 */
1023 1021 return (one / x);
1024 1022 }
1025 1023 if (ix >= 0x7fff0000)
1026 1024 return (x * ((hx < 0)? zero : x)); /* Inf or NaN */
1027 1025 if (x > overflow) /* overflow threshold */
1028 1026 return (x * 1.0e4932L);
1029 1027 if (hx >= 0x40020000) { /* x >= 8 */
1030 1028 ww = large_gam(x, &m);
1031 1029 w = ww.h + ww.l;
1032 1030 return (scalbnl(w, m));
1033 1031 }
1034 1032
1035 1033 if (hx > 0) { /* 0 < x < 8 */
1036 1034 i = (int) x;
1037 1035 ww = gam_n(i, x - (long double) i);
1038 1036 return (ww.h + ww.l);
1039 1037 }
1040 1038 /* INDENT OFF */
1041 1039 /* negative x */
1042 1040 /*
1043 1041 * compute xk =
1044 1042 * -2 ... x is an even int (-inf is considered an even #)
1045 1043 * -1 ... x is an odd int
1046 1044 * +0 ... x is not an int but chopped to an even int
1047 1045 * +1 ... x is not an int but chopped to an odd int
1048 1046 */
1049 1047 /* INDENT ON */
1050 1048 xk = 0;
1051 1049 #if defined(__x86)
1052 1050 if (ix >= 0x403e0000) { /* x >= 2**63 } */
1053 1051 if (ix >= 0x403f0000)
1054 1052 xk = -2;
1055 1053 else
1056 1054 xk = -2 + (lx & 1);
1057 1055 #else
1058 1056 if (ix >= 0x406f0000) { /* x >= 2**112 */
1059 1057 if (ix >= 0x40700000)
1060 1058 xk = -2;
1061 1059 else
1062 1060 xk = -2 + (lx & 1);
1063 1061 #endif
1064 1062 } else if (ix >= 0x3fff0000) {
1065 1063 w = -x;
1066 1064 t1 = floorl(w);
1067 1065 t2 = t1 * half;
1068 1066 t3 = floorl(t2);
1069 1067 if (t1 == w) {
1070 1068 if (t2 == t3)
1071 1069 xk = -2;
1072 1070 else
1073 1071 xk = -1;
1074 1072 } else {
1075 1073 if (t2 == t3)
1076 1074 xk = 0;
1077 1075 else
1078 1076 xk = 1;
1079 1077 }
1080 1078 }
1081 1079
1082 1080 if (xk < 0) {
1083 1081 /* return NaN. Ideally gamma(-n)= (-1)**(n+1) * inf */
1084 1082 return (x - x) / (x - x);
1085 1083 }
1086 1084
1087 1085 /*
1088 1086 * negative underflow thresold -(1774+9ulp)
1089 1087 */
1090 1088 if (x < -1774.0000000000000000000000000000017749370L) {
1091 1089 z = tiny / x;
1092 1090 if (xk == 1)
1093 1091 z = -z;
1094 1092 return (z * tiny);
1095 1093 }
1096 1094
1097 1095 /* INDENT OFF */
1098 1096 /*
1099 1097 * now compute gamma(x) by -1/((sin(pi*y)/pi)*gamma(1+y)), y = -x
1100 1098 */
1101 1099 /*
1102 1100 * First compute ss = -sin(pi*y)/pi so that
1103 1101 * gamma(x) = 1/(ss*gamma(1+y))
1104 1102 */
1105 1103 /* INDENT ON */
1106 1104 y = -x;
1107 1105 j = (int) y;
1108 1106 z = y - (long double) j;
1109 1107 if (z > 0.3183098861837906715377675L)
1110 1108 if (z > 0.6816901138162093284622325L)
1111 1109 ss = kpsin(one - z);
1112 1110 else
1113 1111 ss = kpcos(0.5L - z);
1114 1112 else
1115 1113 ss = kpsin(z);
1116 1114 if (xk == 0) {
1117 1115 ss.h = -ss.h;
1118 1116 ss.l = -ss.l;
1119 1117 }
1120 1118
1121 1119 /* Then compute ww = gamma(1+y), note that result scale to 2**m */
1122 1120 m = 0;
1123 1121 if (j < 7) {
1124 1122 ww = gam_n(j + 1, z);
1125 1123 } else {
1126 1124 w = y + one;
1127 1125 if ((lx & 1) == 0) { /* y+1 exact (note that y<184) */
1128 1126 ww = large_gam(w, &m);
1129 1127 } else {
1130 1128 t = w - one;
1131 1129 if (t == y) { /* y+one exact */
1132 1130 ww = large_gam(w, &m);
1133 1131 } else { /* use y*gamma(y) */
1134 1132 if (j == 7)
1135 1133 ww = gam_n(j, z);
1136 1134 else
1137 1135 ww = large_gam(y, &m);
1138 1136 t4 = ww.h + ww.l;
1139 1137 t1 = CHOPPED((y));
1140 1138 t2 = CHOPPED((t4));
1141 1139 /* t4 will not be too large */
1142 1140 ww.l = y * (ww.l - (t2 - ww.h)) + (y - t1) * t2;
1143 1141 ww.h = t1 * t2;
1144 1142 }
1145 1143 }
1146 1144 }
1147 1145
1148 1146 /* compute 1/(ss*ww) */
1149 1147 t3 = ss.h + ss.l;
1150 1148 t4 = ww.h + ww.l;
1151 1149 t1 = CHOPPED((t3));
1152 1150 t2 = CHOPPED((t4));
1153 1151 z1 = ss.l - (t1 - ss.h); /* (t1,z1) = ss */
1154 1152 z2 = ww.l - (t2 - ww.h); /* (t2,z2) = ww */
1155 1153 t3 = t3 * t4; /* t3 = ss*ww */
1156 1154 z3 = one / t3; /* z3 = 1/(ss*ww) */
1157 1155 t5 = t1 * t2;
1158 1156 z5 = z1 * t4 + t1 * z2; /* (t5,z5) = ss*ww */
1159 1157 t1 = CHOPPED((t3)); /* (t1,z1) = ss*ww */
1160 1158 z1 = z5 - (t1 - t5);
1161 1159 t2 = CHOPPED((z3)); /* leading 1/(ss*ww) */
1162 1160 z2 = z3 * (t2 * z1 - (one - t2 * t1));
1163 1161 z = t2 - z2;
1164 1162
1165 1163 return (scalbnl(z, -m));
1166 1164 }
↓ open down ↓ |
1124 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX