1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
/* dlngam.f -- translated by f2c (version 20041007).
You must link the resulting object file with libf2c:
on Microsoft Windows system, link with libf2c.lib;
on Linux or Unix systems, link with .../path/to/libf2c.a -lm
or, if you install libf2c.a in a standard place, with -lf2c -lm
-- in that order, at the end of the command line, as in
cc *.o -lf2c -lm
Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
http://www.netlib.org/f2c/libf2c.zip
*/
/** This routine has been editted to be thread safe **/
#define V3P_NETLIB_SRC
#include "v3p_netlib.h"
/* Table of constant values */
static integer c__2 = 2;
static integer c__4 = 4;
static integer c__3 = 3;
static integer c__1 = 1;
/* DECK DLNGAM */
doublereal dlngam_(doublereal *x)
{
/* Initialized data */
static doublereal sq2pil = .91893853320467274178032973640562;
static doublereal sqpi2l = .225791352644727432363097614947441;
static doublereal pi = 3.1415926535897932384626433832795;
// static logical first = TRUE_;
/* System generated locals */
doublereal ret_val = 0.0, d__1, d__2;
/* Builtin functions */
double log(doublereal), sqrt(doublereal), sin(doublereal), d_int(
doublereal *);
/* Local variables */
doublereal y, temp;
/* static */ doublereal xmax, dxrel;
extern doublereal d1mach_(integer *), d9lgmc_(doublereal *), dgamma_(
doublereal *);
extern /* Subroutine */ int xermsg_(char *, char *, char *, integer *,
integer *, ftnlen, ftnlen, ftnlen);
doublereal sinpiy;
/* ***BEGIN PROLOGUE DLNGAM */
/* ***PURPOSE Compute the logarithm of the absolute value of the Gamma */
/* function. */
/* ***LIBRARY SLATEC (FNLIB) */
/* ***CATEGORY C7A */
/* ***TYPE DOUBLE PRECISION (ALNGAM-S, DLNGAM-D, CLNGAM-C) */
/* ***KEYWORDS ABSOLUTE VALUE, COMPLETE GAMMA FUNCTION, FNLIB, LOGARITHM, */
/* SPECIAL FUNCTIONS */
/* ***AUTHOR Fullerton, W., (LANL) */
/* ***DESCRIPTION */
/* DLNGAM(X) calculates the double precision logarithm of the */
/* absolute value of the Gamma function for double precision */
/* argument X. */
/* ***REFERENCES (NONE) */
/* ***ROUTINES CALLED D1MACH, D9LGMC, DGAMMA, XERMSG */
/* ***REVISION HISTORY (YYMMDD) */
/* 770601 DATE WRITTEN */
/* 890531 Changed all specific intrinsics to generic. (WRB) */
/* 890531 REVISION DATE from Version 3.2 */
/* 891214 Prologue converted to Version 4.0 format. (BAB) */
/* 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) */
/* 900727 Added EXTERNAL statement. (WRB) */
/* ***END PROLOGUE DLNGAM */
/* ***FIRST EXECUTABLE STATEMENT DLNGAM */
// d1mach has been made thread safe, so there is no need for the
// statics in determining these values
// if (first) {
// temp = 1. / log(d1mach_(&c__2));
// xmax = temp * d1mach_(&c__2);
// dxrel = sqrt(d1mach_(&c__4));
// }
// first = FALSE_;
temp = 1. / log(d1mach_(&c__2));
xmax = temp * d1mach_(&c__2);
dxrel = sqrt(d1mach_(&c__4));
y = abs(*x);
if (y > 10.) {
goto L20;
}
/* LOG (ABS (DGAMMA(X)) ) FOR ABS(X) .LE. 10.0 */
ret_val = log((d__1 = dgamma_(x), abs(d__1)));
return ret_val;
/* LOG ( ABS (DGAMMA(X)) ) FOR ABS(X) .GT. 10.0 */
L20:
if (y > xmax) {
xermsg_("SLATEC", "DLNGAM", "ABS(X) SO BIG DLNGAM OVERFLOWS", &c__2, &
c__2, (ftnlen)6, (ftnlen)6, (ftnlen)30);
}
if (*x > 0.) {
ret_val = sq2pil + (*x - .5) * log(*x) - *x + d9lgmc_(&y);
}
if (*x > 0.) {
return ret_val;
}
sinpiy = (d__1 = sin(pi * y), abs(d__1));
if (sinpiy == 0.) {
xermsg_("SLATEC", "DLNGAM", "X IS A NEGATIVE INTEGER", &c__3, &c__2, (
ftnlen)6, (ftnlen)6, (ftnlen)23);
}
d__2 = *x - .5;
if ((d__1 = (*x - d_int(&d__2)) / *x, abs(d__1)) < dxrel) {
xermsg_("SLATEC", "DLNGAM", "ANSWER LT HALF PRECISION BECAUSE X TOO "
"NEAR NEGATIVE INTEGER", &c__1, &c__1, (ftnlen)6, (ftnlen)6, (
ftnlen)60);
}
ret_val = sqpi2l + (*x - .5) * log(y) - *x - log(sinpiy) - d9lgmc_(&y);
return ret_val;
} /* dlngam_ */
|