Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ gamma(3) — OSF/1 X2.0-8 MIPS

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exp(3)

math(3)

matherr(3)

gamma(3)  —  Subroutines

Digital

NAME

lgamma, gamma − Computes the logarithm of the gamma function

LIBRARY

Math Library (libm.a)

SYNOPSIS

#include <math.h>

double gamma (
    double x );

double lgamma (
    double x );

extern int signgam;

PARAMETERS

xSpecifies some positive double value. 

DESCRIPTION

The gamma() and lgamma() functions return the logarithm of the absolute value of the gamma of x, or ln(|G(x)|), where the gamma of x, or G(x), is defined as:

∞∫0e−ttx−1dt

The names lgamma() and gamma() are different functions for the same operation.  Unless stated otherwise, references to and examples that use the gamma() function also apply to the lgamma() function. 

The sign of the gamma of x is returned in the external integer variable signgam. The x parameter cannot be a nonpositive integer.  The gamma of x is defined over the reals, except the nonpositive integers. 

Only after gamma() has returned can signgam be correct. Note too that G(x) must overflow when x is large enough, and spawn a division by zero when x is a nonpositive integer. 

You can use the following C program fragment to calculate G if you need to detect the overflow:

if ((y = gamma(x)) > LN_MAXDOUBLE
   error();
y = signgam ∗ exp(y);

For the preceding example to work, you also need to define LN_MAXDOUBLE in the <values.h> header file as the least value that causes exp() to overflow. 

NOTES

To compute

g = gamma (x)

do not use the expression

g = signgam ∗ exp (gamma (x))

Instead, use the following sequence:

lg = gamma (x);
g = signgam ∗ exp (lg);

The preceding sequence is necessary because the C language does not specify evaluation order, and signgam is modified by the call to the gamma() function. 

AES Support Level:
Trial use

RETURN VALUES

If the gamma() function fails, either INF or NaN is returned. 

ERRORS

The gamma() function can fail if:

[EDOM]The value of x is a nonpositive integer or NaN (Not a Number). 

[ERANGE]The value to be returned would have caused overflow. 

ENVIRONMENT

In the SVID-2 habitat:

       •The lgamma() function is not available. 

       •For nonnegative integer arguments, the gamma() function returns −HUGE, sets errno to EDOM, and prints a message that indicates SING on the standard error output. 

       •If the correct value would overflow, the gamma() function returns HUGE and sets errno to ERANGE. 

       •Error-handling procedures can be changed with the matherr() function. 

RELATED INFORMATION

Functions: exp(3), math(3), matherr(3)
 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026