gamma(3M)


gamma: gamma, lgamma, signgam -- log gamma functions

Synopsis

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

#include <math.h>

double gamma(double x);

double lgamma(double x);

extern int signgam;

Description

lgamma- log gamma function

signgam- storage for sign of lgamma

gamma and lgamma return



ln (|GREEK CAPITAL LETTER GAMMA(x)|)

where GREEK CAPITAL LETTER GAMMA(x) is defined as

The sign of GREEK CAPITAL LETTER GAMMA(x) is returned in the external integer signgam. The argument x may not be a non-positive integer.

The following C program fragment might be used to calculate GREEK CAPITAL LETTER GAMMA:

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

where LN_MAXDOUBLE is the least value that causes exp to return a range error, and is defined in the values.h header file.

Errors

For non-positive integer arguments, a value that will compare equal to +HUGE_VAL is returned and errno is set to EDOM. On systems that support IEEE exceptions, the divide by zero exception is raised.

If the correct value would overflow, gamma and lgamma return a value that will compare equal to +HUGE_VAL and set errno to ERANGE.

On systems that support IEEE NaN, if x is a quiet NaN, that value is returned. If x is a signaling NaN, a quiet NaN is returned and the invalid operation exception is raised. In either case, errno is set to EDOM.

If the program was compiled with the -Xt compilation mode, a value that will compare equal to HUGE is returned instead of HUGE_VAL. In addition, for non-positive integer arguments, a message indicating SING error is printed on the standard error output. These error handling procedures may be changed with the function matherr.

References

cc(1), exp(3M), matherr(3M), values(5)
30 January 1998
© 1998 The Santa Cruz Operation, Inc. All rights reserved.