/* gammal.c
*
* Gamma function
*
*
*
* SYNOPSIS :
*
* long double x , y , gammal ( ) ;
* extern int sgngam ;
*
* y = gammal ( x ) ;
*
*
*
* DESCRIPTION :
*
* Returns gamma function of the argument . The result is
* correctly signed , and the sign ( + 1 or - 1 ) is also
* returned in a global ( extern ) variable named sgngam .
* This variable is also filled in by the logarithmic gamma
* function lgam ( ) .
*
* Arguments | x | < = 13 are reduced by recurrence and the function
* approximated by a rational function of degree 7 / 8 in the
* interval ( 2 , 3 ) . Large arguments are handled by Stirling ' s
* formula . Large negative arguments are made positive using
* a reflection formula .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE - 40 , + 40 10000 3 . 6 e - 19 7 . 9 e - 20
* IEEE - 1755 , + 1755 10000 4 . 8 e - 18 6 . 5 e - 19
*
* Accuracy for large arguments is dominated by error in powl ( ) .
*
*/
/* lgaml()
*
* Natural logarithm of gamma function
*
*
*
* SYNOPSIS :
*
* long double x , y , lgaml ( ) ;
* extern int sgngam ;
*
* y = lgaml ( x ) ;
*
*
*
* DESCRIPTION :
*
* Returns the base e ( 2 . 718 . . . ) logarithm of the absolute
* value of the gamma function of the argument .
* The sign ( + 1 or - 1 ) of the gamma function is returned in a
* global ( extern ) variable named sgngam .
*
* For arguments greater than 33 , the logarithm of the gamma
* function is approximated by the logarithmic version of
* Stirling ' s formula using a polynomial approximation of
* degree 4 . Arguments between - 33 and + 33 are reduced by
* recurrence to the interval [ 2 , 3 ] of a rational approximation .
* The cosecant reflection formula is employed for arguments
* less than - 33 .
*
* Arguments greater than MAXLGML ( 10 ^ 4928 ) return MAXNUML .
*
*
*
* ACCURACY :
*
*
* arithmetic domain # trials peak rms
* IEEE - 40 , 40 100000 2 . 2 e - 19 4 . 6 e - 20
* IEEE 10 ^ - 2000 , 10 ^ + 2000 20000 1 . 6 e - 19 3 . 3 e - 20
* The error criterion was relative when the function magnitude
* was greater than one but absolute when it was less than one .
*
*/
/* gamma.c */
/* gamma function */
/*
Copyright 1994 by Stephen L . Moshier
*/
#include "mconf.h"
/*
gamma ( x + 2 ) = gamma ( x + 2 ) P ( x ) / Q ( x )
0 < = x < = 1
Relative error
n = 7 , d = 8
Peak error = 1 . 83 e - 20
Relative error spread = 8 . 4 e - 23
*/
#if UNK
static long double P[8 ] = {
4 .212760487471622013093 E-5 L,
4 .542931960608009155600 E-4 L,
4 .092666828394035500949 E-3 L,
2 .385363243461108252554 E-2 L,
1 .113062816019361559013 E-1 L,
3 .629515436640239168939 E-1 L,
8 .378004301573126728826 E-1 L,
1 .000000000000000000009 E0L,
};
static long double Q[9 ] = {
-1 .397148517476170440917 E-5 L,
2 .346584059160635244282 E-4 L,
-1 .237799246653152231188 E-3 L,
-7 .955933682494738320586 E-4 L,
2 .773706565840072979165 E-2 L,
-4 .633887671244534213831 E-2 L,
-2 .243510905670329164562 E-1 L,
4 .150160950588455434583 E-1 L,
9 .999999999999999999908 E-1 L,
};
#endif
#if IBMPC
static short P[] = {
0 x434a,0 x3f22,0 x2bda,0 xb0b2,0 x3ff0, XPD
0 xf5aa,0 xe82f,0 x335b,0 xee2e,0 x3ff3, XPD
0 xbe6c,0 x3757,0 xc717,0 x861b,0 x3ff7, XPD
0 x7f43,0 x5196,0 xb166,0 xc368,0 x3ff9, XPD
0 x9549,0 x8eb5,0 x8c3a,0 xe3f4,0 x3ffb, XPD
0 x8d75,0 x23af,0 xc8e4,0 xb9d4,0 x3ffd, XPD
0 x29cf,0 x19b3,0 x16c8,0 xd67a,0 x3ffe, XPD
0 x0000,0 x0000,0 x0000,0 x8000,0 x3fff, XPD
};
static short Q[] = {
0 x5473,0 x2de8,0 x1268,0 xea67,0 xbfee, XPD
0 x334b,0 xc2f0,0 xa2dd,0 xf60e,0 x3ff2, XPD
0 xbeed,0 x1853,0 xa691,0 xa23d,0 xbff5, XPD
0 x296e,0 x7cb1,0 x5dfd,0 xd08f,0 xbff4, XPD
0 x0417,0 x7989,0 xd7bc,0 xe338,0 x3ff9, XPD
0 x3295,0 x3698,0 xd580,0 xbdcd,0 xbffa, XPD
0 x75ef,0 x3ab7,0 x4ad3,0 xe5bc,0 xbffc, XPD
0 xe458,0 x2ec7,0 xfd57,0 xd47c,0 x3ffd, XPD
0 x0000,0 x0000,0 x0000,0 x8000,0 x3fff, XPD
};
#endif
#if MIEEE
static long P[24 ] = {
0 x3ff00000,0 xb0b22bda,0 x3f22434a,
0 x3ff30000,0 xee2e335b,0 xe82ff5aa,
0 x3ff70000,0 x861bc717,0 x3757be6c,
0 x3ff90000,0 xc368b166,0 x51967f43,
0 x3ffb0000,0 xe3f48c3a,0 x8eb59549,
0 x3ffd0000,0 xb9d4c8e4,0 x23af8d75,
0 x3ffe0000,0 xd67a16c8,0 x19b329cf,
0 x3fff0000,0 x80000000,0 x00000000,
};
static long Q[27 ] = {
0 xbfee0000,0 xea671268,0 x2de85473,
0 x3ff20000,0 xf60ea2dd,0 xc2f0334b,
0 xbff50000,0 xa23da691,0 x1853beed,
0 xbff40000,0 xd08f5dfd,0 x7cb1296e,
0 x3ff90000,0 xe338d7bc,0 x79890417,
0 xbffa0000,0 xbdcdd580,0 x36983295,
0 xbffc0000,0 xe5bc4ad3,0 x3ab775ef,
0 x3ffd0000,0 xd47cfd57,0 x2ec7e458,
0 x3fff0000,0 x80000000,0 x00000000,
};
#endif
/*
static long double P [ ] = {
- 3 . 01525602666895735709 e0L ,
- 3 . 25157411956062339893 e1L ,
- 2 . 92929976820724030353 e2L ,
- 1 . 70730828800510297666 e3L ,
- 7 . 96667499622741999770 e3L ,
- 2 . 59780216007146401957 e4L ,
- 5 . 99650230220855581642 e4L ,
- 7 . 15743521530849602425 e4L
} ;
static long double Q [ ] = {
1 . 00000000000000000000 e0L ,
- 1 . 67955233807178858919 e1L ,
8 . 85946791747759881659 e1L ,
5 . 69440799097468430177 e1L ,
- 1 . 98526250512761318471 e3L ,
3 . 31667508019495079814 e3L ,
1 . 60577839621734713377 e4L ,
- 2 . 97045081369399940529 e4L ,
- 7 . 15743521530849602412 e4L
} ;
*/
#define MAXGAML 1755 .455 L
/*static long double LOGPI = 1.14472988584940017414L;*/
/* Stirling's formula for the gamma function
gamma ( x ) = sqrt ( 2 pi ) x ^ ( x - . 5 ) exp ( - x ) ( 1 + 1 / x P ( 1 / x ) )
z ( x ) = x
13 < = x < = 1024
Relative error
n = 8 , d = 0
Peak error = 9 . 44 e - 21
Relative error spread = 8 . 8 e - 4
*/
#if UNK
static long double STIR[9 ] = {
7 .147391378143610789273 E-4 L,
-2 .363848809501759061727 E-5 L,
-5 .950237554056330156018 E-4 L,
6 .989332260623193171870 E-5 L,
7 .840334842744753003862 E-4 L,
-2 .294719747873185405699 E-4 L,
-2 .681327161876304418288 E-3 L,
3 .472222222230075327854 E-3 L,
8 .333333333333331800504 E-2 L,
};
#endif
#if IBMPC
static short STIR[] = {
0 x6ede,0 x69f7,0 x54e3,0 xbb5d,0 x3ff4, XPD
0 xc395,0 x0295,0 x4443,0 xc64b,0 xbfef, XPD
0 xba6f,0 x7c59,0 x5e47,0 x9bfb,0 xbff4, XPD
0 x5704,0 x1a39,0 xb11d,0 x9293,0 x3ff1, XPD
0 x30b7,0 x1a21,0 x98b2,0 xcd87,0 x3ff4, XPD
0 xbef3,0 x7023,0 x6a08,0 xf09e,0 xbff2, XPD
0 x3a1c,0 x5ac8,0 x3478,0 xafb9,0 xbff6, XPD
0 xc3c9,0 x906e,0 x38e3,0 xe38e,0 x3ff6, XPD
0 xa1d5,0 xaaaa,0 xaaaa,0 xaaaa,0 x3ffb, XPD
};
#endif
#if MIEEE
static long STIR[27 ] = {
0 x3ff40000,0 xbb5d54e3,0 x69f76ede,
0 xbfef0000,0 xc64b4443,0 x0295c395,
0 xbff40000,0 x9bfb5e47,0 x7c59ba6f,
0 x3ff10000,0 x9293b11d,0 x1a395704,
0 x3ff40000,0 xcd8798b2,0 x1a2130b7,
0 xbff20000,0 xf09e6a08,0 x7023bef3,
0 xbff60000,0 xafb93478,0 x5ac83a1c,
0 x3ff60000,0 xe38e38e3,0 x906ec3c9,
0 x3ffb0000,0 xaaaaaaaa,0 xaaaaa1d5,
};
#endif
#define MAXSTIR 1024 .0 L
static long double SQTPI = 2 .50662827463100050242 E0L;
/* 1/gamma(x) = z P(z)
* z ( x ) = 1 / x
* 0 < x < 0 . 03125
* Peak relative error 4 . 2 e - 23
*/
#if UNK
static long double S[9 ] = {
-1 .193945051381510095614 E-3 L,
7 .220599478036909672331 E-3 L,
-9 .622023360406271645744 E-3 L,
-4 .219773360705915470089 E-2 L,
1 .665386113720805206758 E-1 L,
-4 .200263503403344054473 E-2 L,
-6 .558780715202540684668 E-1 L,
5 .772156649015328608253 E-1 L,
1 .000000000000000000000 E0L,
};
#endif
#if IBMPC
static short S[] = {
0 xbaeb,0 xd6d3,0 x25e5,0 x9c7e,0 xbff5, XPD
0 xfe9a,0 xceb4,0 xc74e,0 xec9a,0 x3ff7, XPD
0 x9225,0 xdfef,0 xb0e9,0 x9da5,0 xbff8, XPD
0 x10b0,0 xec17,0 x87dc,0 xacd7,0 xbffa, XPD
0 x6b8d,0 x7515,0 x1905,0 xaa89,0 x3ffc, XPD
0 xf183,0 x126b,0 xf47d,0 xac0a,0 xbffa, XPD
0 x7bf6,0 x57d1,0 xa013,0 xa7e7,0 xbffe, XPD
0 xc7a9,0 x7db0,0 x67e3,0 x93c4,0 x3ffe, XPD
0 x0000,0 x0000,0 x0000,0 x8000,0 x3fff, XPD
};
#endif
#if MIEEE
static long S[27 ] = {
0 xbff50000,0 x9c7e25e5,0 xd6d3baeb,
0 x3ff70000,0 xec9ac74e,0 xceb4fe9a,
0 xbff80000,0 x9da5b0e9,0 xdfef9225,
0 xbffa0000,0 xacd787dc,0 xec1710b0,
0 x3ffc0000,0 xaa891905,0 x75156b8d,
0 xbffa0000,0 xac0af47d,0 x126bf183,
0 xbffe0000,0 xa7e7a013,0 x57d17bf6,
0 x3ffe0000,0 x93c467e3,0 x7db0c7a9,
0 x3fff0000,0 x80000000,0 x00000000,
};
#endif
/* 1/gamma(-x) = z P(z)
* z ( x ) = 1 / x
* 0 < x < 0 . 03125
* Peak relative error 5 . 16 e - 23
* Relative error spread = 2 . 5 e - 24
*/
#if UNK
static long double SN[9 ] = {
1 .133374167243894382010 E-3 L,
7 .220837261893170325704 E-3 L,
9 .621911155035976733706 E-3 L,
-4 .219773343731191721664 E-2 L,
-1 .665386113944413519335 E-1 L,
-4 .200263503402112910504 E-2 L,
6 .558780715202536547116 E-1 L,
5 .772156649015328608727 E-1 L,
-1 .000000000000000000000 E0L,
};
#endif
#if IBMPC
static short SN[] = {
0 x5dd1,0 x02de,0 xb9f7,0 x948d,0 x3ff5, XPD
0 x989b,0 xdd68,0 xc5f1,0 xec9c,0 x3ff7, XPD
0 x2ca1,0 x18f0,0 x386f,0 x9da5,0 x3ff8, XPD
0 x783f,0 x41dd,0 x87d1,0 xacd7,0 xbffa, XPD
0 x7a5b,0 xd76d,0 x1905,0 xaa89,0 xbffc, XPD
0 x7f64,0 x1234,0 xf47d,0 xac0a,0 xbffa, XPD
0 x5e26,0 x57d1,0 xa013,0 xa7e7,0 x3ffe, XPD
0 xc7aa,0 x7db0,0 x67e3,0 x93c4,0 x3ffe, XPD
0 x0000,0 x0000,0 x0000,0 x8000,0 xbfff, XPD
};
#endif
#if MIEEE
static long SN[27 ] = {
0 x3ff50000,0 x948db9f7,0 x02de5dd1,
0 x3ff70000,0 xec9cc5f1,0 xdd68989b,
0 x3ff80000,0 x9da5386f,0 x18f02ca1,
0 xbffa0000,0 xacd787d1,0 x41dd783f,
0 xbffc0000,0 xaa891905,0 xd76d7a5b,
0 xbffa0000,0 xac0af47d,0 x12347f64,
0 x3ffe0000,0 xa7e7a013,0 x57d15e26,
0 x3ffe0000,0 x93c467e3,0 x7db0c7aa,
0 xbfff0000,0 x80000000,0 x00000000,
};
#endif
int sgngaml = 0 ;
extern int sgngaml;
extern long double MAXLOGL, MAXNUML, PIL;
/* #define PIL 3.14159265358979323846L */
/* #define MAXNUML 1.189731495357231765021263853E4932L */
#ifdef ANSIPROT
extern long double fabsl ( long double );
extern long double lgaml ( long double );
extern long double logl ( long double );
extern long double expl ( long double );
extern long double gammal ( long double );
extern long double sinl ( long double );
extern long double floorl ( long double );
extern long double powl ( long double , long double );
extern long double polevll ( long double , void *, int );
extern long double p1evll ( long double , void *, int );
extern int isnanl ( long double );
extern int isfinitel ( long double );
static long double stirf ( long double );
#else
long double fabsl(), lgaml(), logl(), expl(), gammal(), sinl();
long double floorl(), powl(), polevll(), p1evll(), isnanl(), isfinitel();
static long double stirf();
#endif
#ifdef INFINITIES
extern long double INFINITYL;
#endif
#ifdef NANS
extern long double NANL;
#endif
/* Gamma function computed by Stirling's formula.
*/
static long double stirf(x)
long double x;
{
long double y, w, v;
w = 1 .0 L/x;
/* For large x, use rational coefficients from the analytical expansion. */
if ( x > 1024 .0 L )
w = (((((6 .97281375836585777429 E-5 L * w
+ 7 .84039221720066627474 E-4 L) * w
- 2 .29472093621399176955 E-4 L) * w
- 2 .68132716049382716049 E-3 L) * w
+ 3 .47222222222222222222 E-3 L) * w
+ 8 .33333333333333333333 E-2 L) * w
+ 1 .0 L;
else
w = 1 .0 L + w * polevll( w, STIR, 8 );
y = expl(x);
if ( x > MAXSTIR )
{ /* Avoid overflow in pow() */
v = powl( x, 0 .5 L * x - 0 .25 L );
y = v * (v / y);
}
else
{
y = powl( x, x - 0 .5 L ) / y;
}
y = SQTPI * y * w;
return ( y );
}
long double gammal(x)
long double x;
{
long double p, q, z;
int i;
sgngaml = 1 ;
#ifdef NANS
if ( isnanl(x) )
return (NANL);
#endif
#ifdef INFINITIES
if (x == INFINITYL)
return (INFINITYL);
#ifdef NANS
if (x == -INFINITYL)
goto gamnan;
#endif
#endif
q = fabsl(x);
if ( q > 13 .0 L )
{
if ( q > MAXGAML )
goto goverf;
if ( x < 0 .0 L )
{
p = floorl(q);
if ( p == q )
{
gamnan:
#ifdef NANS
mtherr( "gammal" , DOMAIN );
return (NANL);
#else
goto goverf;
#endif
}
i = p;
if ( (i & 1 ) == 0 )
sgngaml = -1 ;
z = q - p;
if ( z > 0 .5 L )
{
p += 1 .0 L;
z = q - p;
}
z = q * sinl( PIL * z );
z = fabsl(z) * stirf(q);
if ( z <= PIL/MAXNUML )
{
goverf:
#ifdef INFINITIES
return ( sgngaml * INFINITYL);
#else
mtherr( "gammal" , OVERFLOW );
return ( sgngaml * MAXNUML);
#endif
}
z = PIL/z;
}
else
{
z = stirf(x);
}
return ( sgngaml * z );
}
z = 1 .0 L;
while ( x >= 3 .0 L )
{
x -= 1 .0 L;
z *= x;
}
while ( x < -0 .03125 L )
{
z /= x;
x += 1 .0 L;
}
if ( x <= 0 .03125 L )
goto small;
while ( x < 2 .0 L )
{
z /= x;
x += 1 .0 L;
}
if ( x == 2 .0 L )
return (z);
x -= 2 .0 L;
p = polevll( x, P, 7 );
q = polevll( x, Q, 8 );
return ( z * p / q );
small:
if ( x == 0 .0 L )
{
goto gamnan;
}
else
{
if ( x < 0 .0 L )
{
x = -x;
q = z / (x * polevll( x, SN, 8 ));
}
else
q = z / (x * polevll( x, S, 8 ));
}
return q;
}
/* A[]: Stirling's formula expansion of log gamma
* B [ ] , C [ ] : log gamma function between 2 and 3
*/
/* log gamma(x) = ( x - 0.5 ) * log(x) - x + LS2PI + 1/x A(1/x^2)
* x > = 8
* Peak relative error 1 . 51 e - 21
* Relative spread of error peaks 5 . 67 e - 21
*/
#if UNK
static long double A[7 ] = {
4 .885026142432270781165 E-3 L,
-1 .880801938119376907179 E-3 L,
8 .412723297322498080632 E-4 L,
-5 .952345851765688514613 E-4 L,
7 .936507795855070755671 E-4 L,
-2 .777777777750349603440 E-3 L,
8 .333333333333331447505 E-2 L,
};
#endif
#if IBMPC
static short A[] = {
0 xd984,0 xcc08,0 x91c2,0 xa012,0 x3ff7, XPD
0 x3d91,0 x0304,0 x3da1,0 xf685,0 xbff5, XPD
0 x3bdc,0 xaad1,0 xd492,0 xdc88,0 x3ff4, XPD
0 x8b20,0 x9fce,0 x844e,0 x9c09,0 xbff4, XPD
0 xf8f2,0 x30e5,0 x0092,0 xd00d,0 x3ff4, XPD
0 x4d88,0 x03a8,0 x60b6,0 xb60b,0 xbff6, XPD
0 x9fcc,0 xaaaa,0 xaaaa,0 xaaaa,0 x3ffb, XPD
};
#endif
#if MIEEE
static long A[21 ] = {
0 x3ff70000,0 xa01291c2,0 xcc08d984,
0 xbff50000,0 xf6853da1,0 x03043d91,
0 x3ff40000,0 xdc88d492,0 xaad13bdc,
0 xbff40000,0 x9c09844e,0 x9fce8b20,
0 x3ff40000,0 xd00d0092,0 x30e5f8f2,
0 xbff60000,0 xb60b60b6,0 x03a84d88,
0 x3ffb0000,0 xaaaaaaaa,0 xaaaa9fcc,
};
#endif
/* log gamma(x+2) = x B(x)/C(x)
* 0 < = x < = 1
* Peak relative error 7 . 16 e - 22
* Relative spread of error peaks 4 . 78 e - 20
*/
#if UNK
static long double B[7 ] = {
-2 .163690827643812857640 E3L,
-8 .723871522843511459790 E4L,
-1 .104326814691464261197 E6L,
-6 .111225012005214299996 E6L,
-1 .625568062543700591014 E7L,
-2 .003937418103815175475 E7L,
-8 .875666783650703802159 E6L,
};
static long double C[7 ] = {
/* 1.000000000000000000000E0L,*/
-5 .139481484435370143617 E2L,
-3 .403570840534304670537 E4L,
-6 .227441164066219501697 E5L,
-4 .814940379411882186630 E6L,
-1 .785433287045078156959 E7L,
-3 .138646407656182662088 E7L,
-2 .099336717757895876142 E7L,
};
#endif
#if IBMPC
static short B[] = {
0 x9557,0 x4995,0 x0da1,0 x873b,0 xc00a, XPD
0 xfe44,0 x9af8,0 x5b8c,0 xaa63,0 xc00f, XPD
0 x5aa8,0 x7cf5,0 x3684,0 x86ce,0 xc013, XPD
0 x259a,0 x258c,0 xf206,0 xba7f,0 xc015, XPD
0 xbe18,0 x1ca3,0 xc0a0,0 xf80a,0 xc016, XPD
0 x168f,0 x2c42,0 x6717,0 x98e3,0 xc017, XPD
0 x2051,0 x9d55,0 x92c8,0 x876e,0 xc016, XPD
};
static short C[] = {
/*0x0000,0x0000,0x0000,0x8000,0x3fff, XPD*/
0 xaa77,0 xcf2f,0 xae76,0 x807c,0 xc008, XPD
0 xb280,0 x0d74,0 xb55a,0 x84f3,0 xc00e, XPD
0 xa505,0 xcd30,0 x81dc,0 x9809,0 xc012, XPD
0 x3369,0 x4246,0 xb8c2,0 x92f0,0 xc015, XPD
0 x63cf,0 x6aee,0 xbe6f,0 x8837,0 xc017, XPD
0 x26bb,0 xccc7,0 xb009,0 xef75,0 xc017, XPD
0 x462b,0 xbae8,0 xab96,0 xa02a,0 xc017, XPD
};
#endif
#if MIEEE
static long B[21 ] = {
0 xc00a0000,0 x873b0da1,0 x49959557,
0 xc00f0000,0 xaa635b8c,0 x9af8fe44,
0 xc0130000,0 x86ce3684,0 x7cf55aa8,
0 xc0150000,0 xba7ff206,0 x258c259a,
0 xc0160000,0 xf80ac0a0,0 x1ca3be18,
0 xc0170000,0 x98e36717,0 x2c42168f,
0 xc0160000,0 x876e92c8,0 x9d552051,
};
static long C[21 ] = {
/*0x3fff0000,0x80000000,0x00000000,*/
0 xc0080000,0 x807cae76,0 xcf2faa77,
0 xc00e0000,0 x84f3b55a,0 x0d74b280,
0 xc0120000,0 x980981dc,0 xcd30a505,
0 xc0150000,0 x92f0b8c2,0 x42463369,
0 xc0170000,0 x8837be6f,0 x6aee63cf,
0 xc0170000,0 xef75b009,0 xccc726bb,
0 xc0170000,0 xa02aab96,0 xbae8462b,
};
#endif
/* log( sqrt( 2*pi ) ) */
static long double LS2PI = 0 .91893853320467274178 L;
#define MAXLGM 1 .04848146839019521116 e+4928 L
/* Logarithm of gamma function */
long double lgaml(x)
long double x;
{
long double p, q, w, z, f, nx;
int i;
sgngaml = 1 ;
#ifdef NANS
if ( isnanl(x) )
return (NANL);
#endif
#ifdef INFINITIES
if ( !isfinitel(x) )
return (INFINITYL);
#endif
if ( x < -34 .0 L )
{
q = -x;
w = lgaml(q); /* note this modifies sgngam! */
p = floorl(q);
if ( p == q )
{
#ifdef INFINITIES
mtherr( "lgaml" , SING );
return (INFINITYL);
#else
goto loverf;
#endif
}
i = p;
if ( (i & 1 ) == 0 )
sgngaml = -1 ;
else
sgngaml = 1 ;
z = q - p;
if ( z > 0 .5 L )
{
p += 1 .0 L;
z = p - q;
}
z = q * sinl( PIL * z );
if ( z == 0 .0 L )
goto loverf;
/* z = LOGPI - logl( z ) - w; */
z = logl( PIL/z ) - w;
return ( z );
}
if ( x < 13 .0 L )
{
z = 1 .0 L;
nx = floorl( x + 0 .5 L );
f = x - nx;
while ( x >= 3 .0 L )
{
nx -= 1 .0 L;
x = nx + f;
z *= x;
}
while ( x < 2 .0 L )
{
if ( fabsl(x) <= 0 .03125 )
goto lsmall;
z /= nx + f;
nx += 1 .0 L;
x = nx + f;
}
if ( z < 0 .0 L )
{
sgngaml = -1 ;
z = -z;
}
else
sgngaml = 1 ;
if ( x == 2 .0 L )
return ( logl(z) );
x = (nx - 2 .0 L) + f;
p = x * polevll( x, B, 6 ) / p1evll( x, C, 7 );
return ( logl(z) + p );
}
if ( x > MAXLGM )
{
loverf:
#ifdef INFINITIES
return ( sgngaml * INFINITYL );
#else
mtherr( "lgaml" , OVERFLOW );
return ( sgngaml * MAXNUML );
#endif
}
q = ( x - 0 .5 L ) * logl(x) - x + LS2PI;
if ( x > 1 .0 e10L )
return (q);
p = 1 .0 L/(x*x);
q += polevll( p, A, 6 ) / x;
return ( q );
lsmall:
if ( x == 0 .0 L )
goto loverf;
if ( x < 0 .0 L )
{
x = -x;
q = z / (x * polevll( x, SN, 8 ));
}
else
q = z / (x * polevll( x, S, 8 ));
if ( q < 0 .0 L )
{
sgngaml = -1 ;
q = -q;
}
else
sgngaml = 1 ;
q = logl( q );
return (q);
}
Messung V0.5 in Prozent C=97 H=89 G=93
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-06-13)
¤
*© Formatika GbR, Deutschland