/* qlgam
*
* Natural logarithm of gamma function
*
*
*
* SYNOPSIS :
*
* int qlgam ( x , y ) ;
* QELT * x , * y ;
*
* qlgam ( x , y ) ;
*
*
*
* DESCRIPTION :
*
* Returns the base e ( 2 . 718 . . . ) logarithm of the absolute
* value of the gamma function of the argument .
*
*/
/* qgamma
*
* Gamma function
*
*
*
* SYNOPSIS :
*
* int qgamma ( x , y ) ;
* QELT * x , * y ;
*
* qgamma ( x , y ) ;
*
*
*
* DESCRIPTION :
*
* Returns gamma function of the argument .
*
* qgamma ( x ) = exp ( qlgam ( x ) )
*
*/
/*
Cephes Math Library Release 2 . 2 : July , 1992
Copyright 1984 , 1987 , 1989 , 1992 by Stephen L . Moshier
*/
#include "qhead.h"
extern QELT qpi[], qeul[];
/* constants for Stirling's formula */
#define NG 55
char *gstrs[] = {
"7645992940484742892248134246724347500528752413412307906683593870759797606269585779977930217515" ,
"1518" ,"110" ,"109" ,
"-3469342247847828789552088659323852541399766785760491146870005891371501266319724897592306597338057" ,
"209191710" ,"108" ,"107" ,
"36373903172617414408151820151593427169231298640581690038930816378281879873386202346572901" ,
"642" ,"106" ,"105" ,
"-319533631363830011287103352796174274671189606078272738327103470162849568365549721224053" ,
"1590" ,"104" ,"103" ,
"3204019410860907078243020782116241775491817197152717450679002501086861530836678158791" ,
"4326" ,"102" ,"101" ,
"-94598037819122125295227433069493721872702841533066936133385696204311395415197247711" ,
"33330" ,"100" ,"99" ,
"67908260672905495624051117546403605607342195728504487509073961249992947058239" ,
"6" ,"98" ,"97" ,
"-211600449597266513097597728109824233673043954389060234150638733420050668349987259" ,
"4501770" ,"96" ,"95" ,
"1220813806579744469607301679413201203958508415202696621436215105284649447" ,
"6" ,"94" ,"93" ,
"-1295585948207537527989427828538576749659341483719435143023316326829946247" ,
"1410" ,"92" ,"91" ,
"1179057279021082799884123351249215083775254949669647116231545215727922535" ,
"272118" ,"90" ,"89" ,
"-1311426488674017507995511424019311843345750275572028644296919890574047" ,
"61410" ,"88" ,"87" ,
"660714619417678653573847847426261496277830686653388931761996983" ,"6" ,
"86" ,"85" ,
"-2024576195935290360231131160111731009989917391198090877281083932477" ,
"3404310" ,"84" ,"83" ,
"1677014149185145836823154509786269900207736027570253414881613" ,"498" ,
"82" ,"81" ,
"-4603784299479457646935574969019046849794257872751288919656867" ,"230010" ,
"80" ,"79" ,
"414846365575400828295179035549542073492199375372400483487" ,"3318" ,"78" ,"77" ,
"-24655088825935372707687196040585199904365267828865801" ,"30" ,"76" ,"75" ,
"34152417289221168014330073731472635186688307783087" ,"6" ,"74" ,"73" ,
"-5827954961669944110438277244641067365282488301844260429" ,"140100870" ,
"72" ,"71" ,
"1505381347333367003803076567377857208511438160235" ,"4686" ,"70" ,"69" ,
"-78773130858718728141909149208474606244347001" ,"30" ,"68" ,"67" ,
"1472600022126335654051619428551932342241899101" ,"64722" ,"66" ,"65" ,
"-106783830147866529886385444979142647942017" ,"510" ,"64" ,"63" ,
"12300585434086858541953039857403386151" ,"6" ,"62" ,"61" ,
"-1215233140483755572040304994079820246041491" ,"56786730" ,"60" ,"59" ,
"84483613348880041862046775994036021" ,"354" ,"58" ,"57" ,
"-2479392929313226753685415739663229" ,"870" ,"56" ,"55" ,
"29149963634884862421418123812691" ,"798" ,"54" ,"53" ,
"-801165718135489957347924991853" ,"1590" ,"52" ,"51" ,
"495057205241079648212477525" ,"66" ,"50" ,"49" ,
"-5609403368997817686249127547" ,"46410" ,"48" ,"47" ,
"596451111593912163277961" ,"282" ,"46" ,"45" ,
"-27833269579301024235023" ,"690" ,"44" ,"43" ,
"1520097643918070802691" ,"1806" ,"42" ,"41" ,
"-261082718496449122051" ,"13530" ,"40" ,"39" ,
"2929993913841559" ,"6" ,"38" ,"37" ,
"-26315271553053477373" ,"1919190" ,"36" ,"35" ,
"2577687858367" ,"6" ,"34" ,"33" ,
"-7709321041217" ,"510" ,"32" ,"31" ,
"8615841276005" ,"14322" ,"30" ,"29" ,
"-23749461029" ,"870" ,"28" ,"27" ,
"8553103" ,"6" ,"26" ,"25" ,
"-236364091" ,"2730" ,"24" ,"23" ,
"854513" ,"138" ,"22" ,"21" ,
"-174611" ,"330" ,"20" ,"19" ,
"43867" ,"798" ,"18" ,"17" ,
"-3617" ,"510" ,"16" ,"15" ,
"7" ,"6" ,"14" ,"13" ,
"-691" ,"2730" ,"12" ,"11" ,
"5" ,"66" ,"10" ,"9" ,
"-1" ,"30" ,"8" ,"7" ,
"1" ,"42" ,"6" ,"5" ,
"-1" ,"30" ,"4" ,"3" ,
"1" ,"6" ,"2" ,"1" ,
};
/* This is global so it can be used by qcgamma.c. */
QELT qgamcof[NG][NQ];
#if 0
static QELT ggamcof[NG][NQ] = {
/* -1215233140483755572040304994079820246041491/(56786730*60*59) */
{0 xffff,0 x4067,0 x0000,0 x989a,0 x1506,0 x8967,0 x2663,0 xf8cc,
0 x3b4f,0 x4518,0 x35e1,0 x174b,0 x18c9,0 xbd60,0 xa7d4,0 xb5c7,
0 x3e81,0 xcd5c,0 xee1b,0 xa1e0,0 x619a,0 xaa6b,0 x15cb,0 x7924,},
/* 84483613348880041862046775994036021/(354*58*57) */
{0 x0000,0 x4060,0 x0000,0 xe940,0 xb372,0 x3e6c,0 x7d0e,0 x7770,
0 xe671,0 x0431,0 x6dcb,0 x45c0,0 xeb78,0 xe86d,0 x69d5,0 xedfb,
0 xfdaa,0 x6336,0 x8772,0 x837d,0 x2bb8,0 x3de9,0 xb8b2,0 xd64f,},
/* -2479392929313226753685415739663229/(870*56*55) */
{0 xffff,0 x405a,0 x0000,0 xbf58,0 x2a43,0 x3556,0 xfb17,0 x24c9,
0 x5ab5,0 x6cbe,0 xc2ef,0 x3ba1,0 xb5ef,0 x128b,0 x1478,0 x2409,
0 xb737,0 xc796,0 xcbec,0 x2ef3,0 xba1b,0 x5ef1,0 x28b1,0 x4782,},
/* 29149963634884862421418123812691/(798*54*53) */
{0 x0000,0 x4054,0 x0000,0 xa8eb,0 xfe48,0 xda17,0 xdd99,0 x9790,
0 x760b,0 x0ce0,0 x256e,0 xc758,0 x797b,0 xf482,0 x6900,0 x66ba,
0 x7710,0 xd482,0 x31e8,0 x3250,0 x2fff,0 xebcc,0 x7550,0 x7f8b,},
/* -801165718135489957347924991853/(1590*52*51) */
{0 xffff,0 x404e,0 x0000,0 xa0ef,0 x80e5,0 x7954,0 x084c,0 xda64,
0 x925c,0 x6c86,0 x491a,0 x694d,0 xeef0,0 x8cb9,0 xcebd,0 x0717,
0 x30f3,0 xc513,0 xf899,0 x9b37,0 x6479,0 x67b1,0 xc1db,0 x9e70,},
/* 495057205241079648212477525/(66*50*49) */
{0 x0000,0 x4048,0 x0000,0 xa5f7,0 xeef9,0 xe71a,0 xc7c8,0 x0326,
0 xab4c,0 xc8bf,0 x3f7c,0 x478f,0 x4715,0 xb086,0 x40e9,0 x0b3d,
0 x95ed,0 x5188,0 xa0d9,0 xd86b,0 xa7f9,0 xaad3,0 x322f,0 xcfdf,},
/* -5609403368997817686249127547/(46410*48*47) */
{0 xffff,0 x4042,0 x0000,0 xb9e0,0 x9405,0 x8ad8,0 x9016,0 xb4f9,
0 x2ff9,0 x86cd,0 xeea2,0 x09d8,0 xd881,0 xad45,0 x7156,0 x1f50,
0 xa7d3,0 x0f4b,0 x3a8c,0 x9209,0 x871f,0 xa77c,0 x3ae3,0 x6671,},
/* 596451111593912163277961/(282*46*45) */
{0 x0000,0 x403c,0 x0000,0 xe2e1,0 x337f,0 x5af0,0 xbed9,0 x0b6b,
0 x0a35,0 x2d4f,0 x335c,0 x83da,0 x6597,0 xd322,0 x6a6f,0 x46ba,
0 x523a,0 x04c2,0 xcb44,0 x4e98,0 x6e10,0 xdd6c,0 x4012,0 x1349,},
/* -27833269579301024235023/(690*44*43) */
{0 xffff,0 x4037,0 x0000,0 x977d,0 x7628,0 x7772,0 x9bcb,0 x4050,
0 x9f4f,0 xd884,0 x644b,0 x7203,0 x7c5e,0 x1516,0 x61b4,0 xcbd5,
0 x6936,0 x7a8e,0 x3a5c,0 x877f,0 x7942,0 xe745,0 x7deb,0 xabff,},
/* 1520097643918070802691/(1806*42*41) */
{0 x0000,0 x4031,0 x0000,0 xde46,0 x6b7c,0 x78fb,0 xaae3,0 xc3a9,
0 xe6da,0 xeae4,0 x6d98,0 xeeec,0 xac9e,0 x8573,0 xed1e,0 xaac0,
0 x952d,0 x3b2d,0 xcf5d,0 x7d42,0 x4e93,0 x0f91,0 x4416,0 xc3fc,},
/* -261082718496449122051/(13530*40*39) */
{0 xffff,0 x402c,0 x0000,0 xb400,0 x5bde,0 x03d4,0 x642a,0 x2435,
0 x8171,0 x4af6,0 x42a2,0 x4358,0 x1714,0 xaf64,0 x2a24,0 x3581,
0 x714a,0 xf642,0 xa243,0 x5817,0 x14af,0 x642a,0 x2435,0 x8171,},
/* 2929993913841559/(6*38*37) */
{0 x0000,0 x4027,0 x0000,0 xa1bb,0 xcde4,0 xea01,0 x2735,0 x0b88,
0 x1273,0 x50b8,0 x8127,0 x350b,0 x8812,0 x7350,0 xb881,0 x2735,
0 x0b88,0 x1273,0 x50b8,0 x8127,0 x350b,0 x8812,0 x7350,0 xb881,},
/* -26315271553053477373/(1919190*36*35) */
{0 xffff,0 x4022,0 x0000,0 xa228,0 x8cec,0 xf233,0 x76ae,0 xa602,
0 x4d5c,0 x4976,0 x1634,0 xda88,0 xc079,0 x3f07,0 xa1f8,0 xf306,
0 x6b7e,0 xa521,0 xc5cd,0 xdbb1,0 x324e,0 x3cd1,0 x0483,0 xf9be,},
/* 2577687858367/(6*34*33) */
{0 x0000,0 x401d,0 x0000,0 xb694,0 xd07b,0 x219d,0 xbcc4,0 x8676,
0 xf312,0 x19db,0 xcc48,0 x676f,0 x3121,0 x9dbc,0 xc486,0 x76f3,
0 x1219,0 xdbcc,0 x4867,0 x6f31,0 x219d,0 xbcc4,0 x8676,0 xf312,},
/* -7709321041217/(510*32*31) */
{0 xffff,0 x4018,0 x0000,0 xe884,0 x4d8a,0 x169a,0 xbbc4,0 x0616,
0 x9abb,0 xc406,0 x169a,0 xbbc4,0 x0616,0 x9abb,0 xc406,0 x169a,
0 xbbc4,0 x0616,0 x9abb,0 xc406,0 x169a,0 xbbc4,0 x0616,0 x9abc,},
/* 8615841276005/(14322*30*29) */
{0 x0000,0 x4014,0 x0000,0 xa8d1,0 x044d,0 x3708,0 xd1c2,0 x19ee,
0 x4fdc,0 x4469,0 xccae,0 xdcb0,0 x0698,0 x234d,0 x582b,0 x9609,
0 x3d5e,0 xe562,0 xc084,0 x6967,0 xb29e,0 xe369,0 xd34f,0 x6a58,},
/* -23749461029/(870*28*27) */
{0 xffff,0 x4010,0 x0000,0 x8d0c,0 xc570,0 xe255,0 xbf59,0 xff6e,
0 xec24,0 xb48f,0 xf1b3,0 x94d9,0 x2e2f,0 xd250,0 x842c,0 x8d54,
0 x1cdb,0 xcbc6,0 x8b5d,0 xebd1,0 x01b8,0 xd006,0 xa04a,0 xa199,},
/* 8553103/(6*26*25) */
{0 x0000,0 x400c,0 x0000,0 x8911,0 xa740,0 xda74,0 x0da7,0 x40da,
0 x740d,0 xa740,0 xda74,0 x0da7,0 x40da,0 x740d,0 xa740,0 xda74,
0 x0da7,0 x40da,0 x740d,0 xa740,0 xda74,0 x0da7,0 x40da,0 x740e,},
/* -236364091/(2730*24*23) */
{0 xffff,0 x4008,0 x0000,0 x9cd9,0 x292e,0 x6660,0 xd55b,0 x3f71,
0 x2eb9,0 xe07c,0 xa39d,0 xb44a,0 x9292,0 xe666,0 x0d55,0 xb3f7,
0 x12eb,0 x9e07,0 xca39,0 xdb44,0 xa929,0 x2e66,0 x60d5,0 x5b3f,},
/* 854513/(138*22*21) */
{0 x0000,0 x4004,0 x0000,0 xd672,0 x2191,0 x6700,0 x2d3a,0 x7a9c,
0 x8864,0 x59c0,0 x0b4e,0 x9ea7,0 x2219,0 x1670,0 x02d3,0 xa7a9,
0 xc886,0 x459c,0 x00b4,0 xe9ea,0 x7221,0 x9167,0 x002d,0 x3a7b,},
/* -174611/(330*20*19) */
{0 xffff,0 x4001,0 x0000,0 xb23b,0 x3808,0 xc0f9,0 xcf6d,0 xedce,
0 x7312,0 xcc3e,0 xa607,0 x48b1,0 x4c1f,0 x4aa7,0 x0223,0 xb380,
0 x8c0f,0 x9cf6,0 xdedc,0 xe731,0 x2cc3,0 xea60,0 x748b,0 x14c2,},
/* 43867/(798*18*17) */
{0 x0000,0 x3ffe,0 x0000,0 xb7f4,0 xb1c0,0 xf033,0 xffd0,0 xc3b7,
0 xf4b1,0 xc0f0,0 x33ff,0 xd0c3,0 xb7f4,0 xb1c0,0 xf033,0 xffd0,
0 xc3b7,0 xf4b1,0 xc0f0,0 x33ff,0 xd0c3,0 xb7f4,0 xb1c0,0 xf034,},
/* -3617/(510*16*15) */
{0 xffff,0 x3ffb,0 x0000,0 xf214,0 x3658,0 x7a9c,0 xbee1,0 x0325,
0 x4769,0 x8bad,0 xcff2,0 x1436,0 x587a,0 x9cbe,0 xe103,0 x2547,
0 x698b,0 xadcf,0 xf214,0 x3658,0 x7a9c,0 xbee1,0 x0325,0 x476a,},
/* 7/(6*14*13) */
{0 x0000,0 x3ff9,0 x0000,0 xd20d,0 x20d2,0 x0d20,0 xd20d,0 x20d2,
0 x0d20,0 xd20d,0 x20d2,0 x0d20,0 xd20d,0 x20d2,0 x0d20,0 xd20d,
0 x20d2,0 x0d20,0 xd20d,0 x20d2,0 x0d20,0 xd20d,0 x20d2,0 x0d21,},
/* -691/(2730*12*11) */
{0 xffff,0 x3ff7,0 x0000,0 xfb55,0 x86cc,0 xc9e3,0 xe40f,0 xb558,
0 x6ccc,0 x9e3e,0 x40fb,0 x5586,0 xccc9,0 xe3e4,0 x0fb5,0 x586c,
0 xcc9e,0 x3e40,0 xfb55,0 x86cc,0 xc9e3,0 xe40f,0 xb558,0 x6ccd,},
/* 5/(66*10*9) */
{0 x0000,0 x3ff6,0 x0000,0 xdca8,0 xf158,0 xc7f9,0 x1ab8,0 x7539,
0 xc037,0 x2a3c,0 x5631,0 xfe46,0 xae1d,0 x4e70,0 x0dca,0 x8f15,
0 x8c7f,0 x91ab,0 x8753,0 x9c03,0 x72a3,0 xc563,0 x1fe4,0 x6ae2,},
/* -1/(30*8*7) */
{0 xffff,0 x3ff6,0 x0000,0 x9c09,0 xc09c,0 x09c0,0 x9c09,0 xc09c,
0 x09c0,0 x9c09,0 xc09c,0 x09c0,0 x9c09,0 xc09c,0 x09c0,0 x9c09,
0 xc09c,0 x09c0,0 x9c09,0 xc09c,0 x09c0,0 x9c09,0 xc09c,0 x09c1,},
/* 1/(42*6*5) */
{0 x0000,0 x3ff6,0 x0000,0 xd00d,0 x00d0,0 x0d00,0 xd00d,0 x00d0,
0 x0d00,0 xd00d,0 x00d0,0 x0d00,0 xd00d,0 x00d0,0 x0d00,0 xd00d,
0 x00d0,0 x0d00,0 xd00d,0 x00d0,0 x0d00,0 xd00d,0 x00d0,0 x0d01,},
/* -1/(30*4*3) */
{0 xffff,0 x3ff8,0 x0000,0 xb60b,0 x60b6,0 x0b60,0 xb60b,0 x60b6,
0 x0b60,0 xb60b,0 x60b6,0 x0b60,0 xb60b,0 x60b6,0 x0b60,0 xb60b,
0 x60b6,0 x0b60,0 xb60b,0 x60b6,0 x0b60,0 xb60b,0 x60b6,0 x0b61,},
/* 1/(6*2*1) */
{0 x0000,0 x3ffd,0 x0000,0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,
0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,
0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,0 xaaaa,0 xaaab,},
};
#endif
/* log(2*pi)/2 */
#if WORDSIZE == 32
QELT qgam12[] = {
0 ,EXPONE-1 ,0 ,0 xeb3f8e43,0 x25f5a534,0 x94bc9001,0 x44192023,0 xcfb08f8d,
0 x13458b4d,0 xdec6a313,0 x3daa155d,0 x212f9d7f,0 xe00e86bf,0 x93eabf90
};
#else
QELT qgam12[] = {
0 x0000,EXPONE-1 ,0 x0000,0 xeb3f,0 x8e43,0 x25f5,0 xa534,0 x94bc,
0 x9001,0 x4419,0 x2023,0 xcfb0,0 x8f8d,0 x1345,0 x8b4d,0 xdec6,
0 xa313,0 x3daa,0 x155d,0 x212f,0 x9d7f,0 xe00e,0 x86bf,0 x93eb,
};
#endif
extern QELT q32[], qone[], qhalf[];
/* Initialize Stirling formula coefficients from ASCII strings. */
int qgamini = 0 ;
int asctoq(), qfloor(), qinfin();
int initqgam()
{
QELT den[NQ], temp[NQ];
int i, k;
k = 0 ;
for ( i=0 ; i<NG; i++ )
{
asctoq( gstrs[k++], qgamcof[i] );
asctoq( gstrs[k++], den );
asctoq( gstrs[k++], temp );
qmul( den, temp, den );
asctoq( gstrs[k++], temp );
qmul( den, temp, den );
qdiv( den, qgamcof[i], qgamcof[i] );
}
qgamini = 1 ;
return 0 ;
}
/* natural logarithm of gamma function */
int qlgam( x, y )
QELT *x, *y;
{
QELT v[NQ], w[NQ], g[NQ], xx[NQ], t[NQ];
QELT *p;
long lr;
int i;
if ( qgamini == 0 )
initqgam();
qmov( x, xx );
if ( xx[0 ] != 0 )
{
/* Test for negative integer. */
qfloor( xx, t );
if ( qcmp(xx, t) == 0 )
{
qinfin(y);
y[0 ] = 0 ;
return (0 );
}
xx[0 ] = 0 ;
qlgam( xx, t );
qmul( xx, qpi, g ); /* PI/(x * sin(PI*x)) */
qsin( g, g );
qmul( xx, g, g );
qdiv( g, qpi, y );
y[0 ] = 0 ;
qlog( y, y );
qsub( t, y, y ); /* ... /gamma(x) */
return (0 );
}
/* range reduction: transform argument to be greater than 32 */
qmov( qone, v );
if ( xx[1 ] > (QELT) (EXPONE + 5 ) )
goto donrecur;
qifrac( xx, &lr, t );
while ( lr < 62 )
{
qmul( xx, v, v );
qadd( qone, xx, xx );
lr += 1 ;
}
donrecur:
qdiv( v, qone, v );
/* Avoid overflow of xx * xx. */
if ( (int ) (xx[1 ] - EXPONE) >= (MAXEXP - EXPONE)/2 )
{
qclear(g);
goto asymp;
}
/* Asymptotic expansion in 1/x**2 for Stirling's formula */
qmul( xx, xx, w );
qdiv( w, qone, w );
p = &qgamcof[0 ][0 ];
qmul( w, p, g );
p += NQ;
qadd( g, p, g );
for ( i=0 ; i<NG-2 ; i++ )
{
qmul( w, g, g );
p += NQ;
qadd( g, p, g );
}
qdiv( xx, g, g );
asymp:
/* g + (x - 0.5)*log(x) - x + qgam12 */
qsub( qhalf, xx, t );
qlog( xx, w );
qmul( t, w, t );
qsub( xx, t, t );
qadd( qgam12, t, t );
qadd( g, t, g );
qlog( v, t );
qadd( t, g, y );
return 0 ;
}
/* qgamma() */
/* gamma function check routine */
int qgamma( xx, y )
QELT *xx, *y;
{
QELT t[NQ], s[NQ], x[NQ];
if ( qgamini == 0 )
initqgam();
qmov( xx, x );
if ( x[0 ] != 0 )
{
/* Test for negative integer. */
qfloor( xx, t );
if ( qcmp(xx, t) == 0 )
{
qinfin(y);
y[0 ] = 0 ;
return 0 ;
}
x[0 ] = 0 ;
qgamma( x, t );
qmul( x, qpi, s );
qsin( s, s );
qmul( x, s, s );
qmul( s, t, t );
qdiv( t, qpi, y );
y[0 ] = ~y[0 ];
return (0 );
}
qlgam( x, y );
qexp( y, y );
return 0 ;
}
/* Asymptotic expansion in 1/x**2 for Stirling's formula */
int qlstir( xx, y )
QELT *xx, *y;
{
QELT w[NQ], g[NQ];
QELT *p;
int i;
if ( qgamini == 0 )
initqgam();
qmul( xx, xx, w );
qdiv( w, qone, w );
p = &qgamcof[0 ][0 ];
qmul( w, p, g );
p += NQ;
qadd( g, p, g );
for ( i=0 ; i<NG-2 ; i++ )
{
qmul( w, g, g );
p += NQ;
qadd( g, p, g );
}
qdiv( xx, g, y );
return 0 ;
}
Messung V0.5 in Prozent C=88 H=75 G=81