Sun Microsystems, Inc.
spacerspacer
spacer   www.sun.com docs.sun.com | | |  
spacer
black dot
   
A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z
    
 
Mathematical Library Functionslgamma(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 gamma(double x);
 double lgamma_r(double x, int *signgamp);
 double gamma_r(double x, int *signgamp);

DESCRIPTION

 

The lgamma(), gamma(), lgamma_r(), and gamma_r() functions return



 ln||~(x)|


where



 |~(x) = integral from 0 to +Infinity of pow(t,x-1)*exp(-t) dt


for x > 0 and



 |~(x) = n/(|~(1-x)sin(nx))


for x < 1.

The lgamma() and gamma() functions use the external integer signgam to return the sign of |~(x) while lgamma_r() and gamma_r() use 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.

ATTRIBUTES

 

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPEATTRIBUTE VALUE
MT-LevelSee NOTES below.

SEE ALSO

 

matherr(3M), attributes(5), standards(5)

NOTES

 

Although lgamma_r() is not mentioned by POSIX 1003.1c, it was added to complete the functionality provided by similar thread-safe functions.

The gamma() function is currently maintained for compatibility with SVID3 (see standards(5)). It and the gamma_r() function may be removed from a future release. The lgamma() and lgamma_r() functions should be used instead.

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.

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


SunOS 5.9Go To TopLast Changed 26 Jul 2000

 
      
      
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.