Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ lgamma(3M) — SunOS 5.5

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

matherr(3M)

lgamma(3M)

NAME

lgamma, lgamma_r, gamma, gamma_r − log gamma function

SYNOPSIS

cc [ flag ... ] file ... −lm [ library ... ]

#include <math.h>

extern int signgam;

double lgamma(double x);

double lgamma_r(double x, int ∗signgamp);

MT-LEVEL

See the NOTES section of this page. 

DESCRIPTION

Both lgamma() and lgamma_r() return

ln|Γ(x)|
where
Γ(x) = ∫0s10∞tx−1e−tdt
for x > 0 and
Γ(x) = π/(Γ(1−x)sin(πx))
for x < 1.

lgamma() uses the external integer signgam to return the sign of Γ(x) while lgamma_r() uses the user-allocated space addressed by signgamp.

IDIOSYNCRASIES

In the case of lgamma(), do not use the expression signgam∗exp(lgamma(x)) to compute ‘g := Γ(x)’.  Instead compute lgamma() first:

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

only after lgamma() has returned can signgam be correct.  Note that Γ(x) must overflow when x is large enough, underflow when −x is large enough, and generate a division by 0 exception at the singularities x a nonpositive integer. 

RETURN VALUES

For exceptional cases, matherr(3M) tabulates the values to be returned as dictated by various Standards. 

SEE ALSO

matherr(3M)

NOTES

Although lgamma_r() is not mentioned by POSIX.4a Draft 6, it was added to complete the functionality provided by similar thread-safe functions.  This interface is subject to change to be compatible with the "spirit" of POSIX.4a when it is approved as a standard. 

When compiling multi-thread applications, the _REENTRANT flag must be defined on the compile line.  This flag should only be used in multi-thread applications. 

lgamma() is unsafe in multithreaded applications.  lgamma_r() should be used instead.  should be used instead. 

SunOS 5.5  —  Last change: 18 Jul 1994

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