#pragma weak __tgammaf = tgammaf
#include "libm.h"
#include <math.h>
#if defined(__SUNPRO_C)
#include <sunmath.h>
#endif
#include <sys/isa_defs.h>
#if defined(_BIG_ENDIAN)
#define HIWORD 0
#define LOWORD 1
#else
#define HIWORD 1
#define LOWORD 0
#endif
#define __HI(x) ((int *) &x)[HIWORD]
#define __LO(x) ((unsigned *) &x)[LOWORD]
static const double cr[] = {
+7.09087253435088360271451613398019280077561279443e-0001,
-5.17229560788652108545141978238701790105241761089e-0001,
+5.23403394528150789405825222323770647162337764327e-0001,
-4.54586308717075010784041566069480411732634814899e-0001,
+4.20596490915239085459964590559256913498190955233e-0001,
-3.57307589712377520978332185838241458642142185789e-0001,
+4.28486983980295198166056119223984284434264344578e-0001,
-1.30704539487709138528680121627899735386650103914e-0001,
+1.60856285038051955072861219352655851542955430871e-0001,
-9.22285161346010583774458802067371182158937943507e-0002,
+7.19240511767225260740890292605070595560626179357e-0002,
-4.88158265593355093703112238534484636193260459574e-0002,
+3.82409531118807759081121479786092134814808872880e-0001,
+2.65309888180188647956400403013495759365167853426e-0002,
+8.06815109775079171923561169415370309376296739835e-0002,
-1.54821591666137613928840890835174351674007764799e-0002,
+1.76308239242717268530498313416899188157165183405e-0002,
+0.9382046279096824494097535615803269576988,
+0.8856031944108887002788159005825887332080,
+0.9367814114636523216188468970808378497426,
-0.3517214357852935791015625,
+0.280530631542205810546875,
};
#define P10 cr[0]
#define P11 cr[1]
#define P12 cr[2]
#define P13 cr[3]
#define P14 cr[4]
#define P15 cr[5]
#define P20 cr[6]
#define P21 cr[7]
#define P22 cr[8]
#define P23 cr[9]
#define P24 cr[10]
#define P25 cr[11]
#define P30 cr[12]
#define P31 cr[13]
#define P32 cr[14]
#define P33 cr[15]
#define P34 cr[16]
#define GZ1 cr[17]
#define GZ2 cr[18]
#define GZ3 cr[19]
#define TZ1 cr[20]
#define TZ3 cr[21]
static double
GT1(double y) {
double z, r;
z = y * y;
r = TZ1 * y + z * ((P10 + y * P11 + z * P12) + (z * y) * (P13 + y *
P14 + z * P15));
return (GZ1 + r);
}
static double
GT2(double y) {
double z;
z = y * y;
return (GZ2 + z * ((P20 + y * P21 + z * P22) + (z * y) * (P23 + y *
P24 + z * P25)));
}
static double
GT3(double y) {
double z, r;
z = y * y;
r = TZ3 * y + z * ((P30 + y * P31 + z * P32) + (z * y) * (P33 + y *
P34));
return (GZ3 + r);
}
static const double c[] = {
+1.0,
+2.0,
+0.5,
+1.0e-300,
+6.666717231848518054693623697539230e-0001,
+8.33333330959694065245736888749042811909994573178e-0002,
-2.77765545601667179767706600890361535225507762168e-0003,
+7.77830853479775281781085278324621033523037489883e-0004,
+4.18938533204672741744150788368695779923320328369e-0001,
+2.16608493924982901946e-02,
+4.61662413084468283841e+01,
+5.00004103388988968841156421415669985414073453720e-0001,
+1.66667656752800761782778277828110208108687545908e-0001,
};
#define one c[0]
#define two c[1]
#define half c[2]
#define tiny c[3]
#define A1 c[4]
#define GP0 c[5]
#define GP1 c[6]
#define GP2 c[7]
#define hln2pi c[8]
#define ln2_32 c[9]
#define invln2_32 c[10]
#define Et1 c[11]
#define Et2 c[12]
static const double S[] = {
+1.00000000000000000000e+00,
+1.02189714865411662714e+00,
+1.04427378242741375480e+00,
+1.06714040067682369717e+00,
+1.09050773266525768967e+00,
+1.11438674259589243221e+00,
+1.13878863475669156458e+00,
+1.16372485877757747552e+00,
+1.18920711500272102690e+00,
+1.21524735998046895524e+00,
+1.24185781207348400201e+00,
+1.26905095719173321989e+00,
+1.29683955465100964055e+00,
+1.32523664315974132322e+00,
+1.35425554693689265129e+00,
+1.38390988196383202258e+00,
+1.41421356237309514547e+00,
+1.44518080697704665027e+00,
+1.47682614593949934623e+00,
+1.50916442759342284141e+00,
+1.54221082540794074411e+00,
+1.57598084510788649659e+00,
+1.61049033194925428347e+00,
+1.64575547815396494578e+00,
+1.68179283050742900407e+00,
+1.71861929812247793414e+00,
+1.75625216037329945351e+00,
+1.79470907500310716820e+00,
+1.83400808640934243066e+00,
+1.87416763411029996256e+00,
+1.91520656139714740007e+00,
+1.95714412417540017941e+00,
};
static const double T1[] = {
+1.079441541679835928251696364375e+00,
+1.772588722239781237668928485833e+00,
+2.465735902799726547086160607291e+00,
};
static const double T2[] = {
+7.782140442054948947462900061137e-03,
+2.316705928153437822879916096229e-02,
+3.831886430213659919375532512380e-02,
+5.324451451881228286587019378653e-02,
+6.795066190850774939456527777263e-02,
+8.244366921107459126816006866831e-02,
+9.672962645855111229557105648746e-02,
+1.108143663402901141948061693232e-01,
+1.247034785009572358634065153809e-01,
+1.384023228591191356853258736016e-01,
+1.519160420258419750718034248969e-01,
+1.652495728953071628756114492772e-01,
+1.784076574728182971194002415109e-01,
+1.913948529996294546092988075613e-01,
+2.042155414286908915038203861962e-01,
+2.168739383006143596190895257443e-01,
+2.293741010648458299914807250461e-01,
+2.417199368871451681443075159135e-01,
+2.539152099809634441373232979066e-01,
+2.659635484971379413391259265375e-01,
+2.778684510034563061863500329234e-01,
+2.896332925830426768788930555257e-01,
+3.012613305781617810128755382338e-01,
+3.127557100038968883862465596883e-01,
+3.241194686542119760906707604350e-01,
+3.353555419211378302571795798142e-01,
+3.464667673462085809184621884258e-01,
+3.574558889218037742260094901409e-01,
+3.683255611587076530482301540504e-01,
+3.790783529349694583908533456310e-01,
+3.897167511400252133704636040035e-01,
+4.002431641270127069293251019951e-01,
+4.106599249852683859343062031758e-01,
+4.209692946441296361288671615068e-01,
+4.311734648183713408591724789556e-01,
+4.412745608048752294894964416613e-01,
+4.512746441394585851446923830790e-01,
+4.611757151221701663679999255979e-01,
+4.709797152187910125468978560564e-01,
+4.806885293457519076766184554480e-01,
+4.903039880451938381503461596457e-01,
+4.998278695564493298213314152470e-01,
+5.092619017898079468040749192283e-01,
+5.186077642080456321529769963648e-01,
+5.278670896208423851138922177783e-01,
+5.370414658968836545667292441538e-01,
+5.461324375981356503823972092312e-01,
+5.551415075405015927154803595159e-01,
+5.640701382848029660713842900902e-01,
+5.729197535617855090927567266263e-01,
+5.816917396346224825206107537254e-01,
+5.903874466021763746419167081236e-01,
+5.990081896460833993816000244617e-01,
+6.075552502245417955010851527911e-01,
+6.160298772155140196475659281967e-01,
+6.244332880118935010425387440547e-01,
+6.327666695710378295457864685036e-01,
+6.410311794209312910556013344054e-01,
+6.492279466251098188908399699053e-01,
+6.573580727083600301418900232459e-01,
+6.654226325450904489500926100067e-01,
+6.734226752121667202979603888010e-01,
+6.813592248079030689480715595681e-01,
+6.892332812388089803249143378146e-01,
};
static double
large_gam(double x) {
double ss, zz, z, t1, t2, w, y, u;
unsigned lx;
int k, ix, j, m;
ix = __HI(x);
lx = __LO(x);
m = (ix >> 20) - 0x3ff;
ix = (ix & 0x000fffff) | 0x3ff00000;
__HI(y) = ix;
__LO(y) = lx;
__HI(z) = (ix & 0xffffc000) | 0x2000;
__LO(z) = 0;
j = (ix >> 14) & 0x3f;
t1 = y + z;
t2 = y - z;
u = t2 / t1;
ss = T1[m - 3] + T2[j] + u * (two + A1 * (u * u));
z = one / x;
zz = z * z;
w = ((x - half) * ss + hln2pi) + z * (GP0 + zz * GP1 + (zz * zz) * GP2);
k = (int) (w * invln2_32 + half);
j = k & 0x1f;
m = k >> 5;
z = w - (double) k *ln2_32;
zz = S[j] * (one + z + (z * z) * (Et1 + z * Et2));
__HI(zz) += m << 20;
return (zz);
}
static const double ks[] = {
-1.64493404985645811354476665052005342839447790544e+0000,
+8.11740794458351064092797249069438269367389272270e-0001,
-1.90703144603551216933075809162889536878854055202e-0001,
+2.55742333994264563281155312271481108635575331201e-0002,
};
static double
kpsin(double x) {
double z;
z = x * x;
return (x + (x * z) * ((ks[0] + z * ks[1]) + (z * z) * (ks[2] + z *
ks[3])));
}
static const double kc[] = {
+3.18309886183790671537767526745028724068919291480e-0001,
-1.57079581447762568199467875065854538626594937791e+0000,
+1.29183528092558692844073004029568674027807393862e+0000,
-4.20232949771307685981015914425195471602739075537e-0001,
};
static double
kpcos(double x) {
double z;
z = x * x;
return (kc[0] + z * (kc[1] + z * kc[2] + (z * z) * kc[3]));
}
static const double
t0z1 = 0.134861805732790769689793935774652917006,
t0z2 = 0.461632144968362341262659542325721328468,
t0z3 = 0.819773101100500601787868704921606996312;
static double
gam_n(int i, double x) {
double rr = 0.0L, yy;
double z1, z2;
if (x > 0.2845) {
if (x > 0.6374)
yy = GT3(x - t0z3);
else
yy = GT2(x - t0z2);
} else
yy = GT1(x - t0z1);
switch (i) {
case 0:
rr = yy / x;
break;
case 1:
rr = yy;
break;
case 2:
rr = (x + one) * yy;
break;
case 3:
rr = (x + one) * (x + two) * yy;
break;
case 4:
rr = (x + one) * (x + two) * ((x + 3.0) * yy);
break;
case 5:
z1 = (x + two) * (x + 3.0) * yy;
z2 = (x + one) * (x + 4.0);
rr = z1 * z2;
break;
case 6:
z1 = (x + two) * (x + 3.0);
z2 = (x + 5.0) * yy;
rr = z1 * (z1 - two) * z2;
break;
case 7:
z1 = (x + two) * (x + 3.0);
z2 = (x + 5.0) * (x + 6.0) * yy;
rr = z1 * (z1 - two) * z2;
break;
}
return (rr);
}
float
tgammaf(float xf) {
float zf;
double ss, ww;
double x, y, z;
int i, j, k, ix, hx, xk;
hx = *(int *) &xf;
ix = hx & 0x7fffffff;
x = (double) xf;
if (ix < 0x33800000)
return (1.0F / xf);
if (ix >= 0x7f800000)
return (xf * ((hx < 0)? 0.0F : xf));
if (hx > 0x420C290F)
return (float)(x / tiny);
if (hx >= 0x41000000)
return ((float) large_gam(x));
if (hx > 0) {
i = (int) xf;
return ((float) gam_n(i, x - (double) i));
}
xk = 0;
if (ix >= 0x4b000000) {
if (ix > 0x4b000000)
xk = -2;
else
xk = -2 + (ix & 1);
} else if (ix >= 0x3f800000) {
k = (ix >> 23) - 0x7f;
j = ix >> (23 - k);
if ((j << (23 - k)) == ix)
xk = -2 + (j & 1);
else
xk = j & 1;
}
if (xk < 0) {
zf = xf - xf;
return (zf / zf);
}
if (ix > 0x4224000B) {
if (xk == 0)
z = -tiny;
else
z = tiny;
return ((float)z);
}
y = -x;
j = (int) y;
z = y - (double) j;
if (z > 0.3183098861837906715377675)
if (z > 0.6816901138162093284622325)
ss = kpsin(one - z);
else
ss = kpcos(0.5 - z);
else
ss = kpsin(z);
if (xk == 0)
ss = -ss;
if (j < 7)
ww = gam_n(j + 1, z);
else
ww = large_gam(y + one);
return ((float) (one / (ww * ss)));
}