1lgamma(3M)              Mathematical Library Functions              lgamma(3M)
2
3
4

NAME

6       lgamma,  lgammaf,  lgammal, lgamma_r, lgammaf_r, lgammal_r, gamma, gam‐
7       maf, gammal, gamma_r, gammaf_r, gammal_r - log gamma function
8

SYNOPSIS

10       c99 [ flag... ] file... -lm [ library... ]
11       #include <math.h>
12
13       extern int signgam;
14
15       double lgamma(double x);
16
17
18       float lgammaf(float x);
19
20
21       long double lgammal(long double x);
22
23
24       double gamma(double x);
25
26
27       float gammaf(float x);
28
29
30       long double gammal(long double x);
31
32
33       double lgamma_r(double x, int *signgamp);
34
35
36       float lgammaf_r(float x, int *signgamp);
37
38
39       long double lgammal_r(long double x, int *signgamp);
40
41
42       double gamma_r(double x, int *signgamp);
43
44
45       float gammaf_r(float x, int *signgamp);
46
47
48       long double gammal_r(long double x, int *signgamp);
49
50

DESCRIPTION

52       These functions return
53
54       ln||~(x)|
55
56
57       where
58
59       |~(x) = integral from 0 to +Infinity of pow(t,x-1)*exp(-t) dt
60
61
62       for x > 0 and
63
64       |~(x) = n/(|~(1-x)sin(nx))
65
66
67       for x < 1.
68
69
70       These functions use the external integer signgam to return the sign  of
71       |~(x)  while  lgamma_r()  and  gamma_r()  use  the user-allocated space
72       addressed by signgamp.
73

RETURN VALUES

75       Upon successful completion,  these  functions  return  the  logarithmic
76       gamma of x.
77
78
79       If x is a non-positive integer, a pole error occurs and these functions
80       return +HUGE_VAL, +HUGE_VALF, and +HUGE_VALL, respectively.
81
82
83       If x is NaN, a NaN is returned.
84
85
86       If x is 1 or 2, +0 shall be returned.
87
88
89       If x is ±Inf, +Inf is returned.
90

ERRORS

92       These functions will fail if:
93
94       Pole Error    The x argument is a negative integer or 0.
95
96                     If the integer expression (math_errhandling & MATH_ERREX‐
97                     CEPT) is non-zero, then the divide-by-zero floating-point
98                     exception is raised.
99
100

USAGE

102       An application wanting to check for exceptions should  call  feclearex‐
103       cept(FE_ALL_EXCEPT)  before  calling  these  functions.  On  return, if
104       fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is
105       non-zero,  an  exception  has been raised. An application should either
106       examine the return value or check the floating point exception flags to
107       detect exceptions.
108
109
110       In    the    case    of   lgamma(),   do   not   use   the   expression
111       signgam*exp(lgamma(x)) to compute
112
113       `g  := |~(x)'
114
115
116       Instead compute lgamma() first:
117
118
119       lg = lgamma(x); g = signgam*exp(lg);
120
121
122       only after lgamma() has returned can  signgam  be  correct.  Note  that
123       |~(x)  must overflow when x is large enough, underflow when −x is large
124       enough, and generate a division by 0 exception at the singularities x a
125       nonpositive integer.
126

ATTRIBUTES

128       See attributes(5) for descriptions of the following attributes:
129
130
131
132
133       ┌─────────────────────────────┬─────────────────────────────┐
134       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
135       ├─────────────────────────────┼─────────────────────────────┤
136       │Interface Stability          │See below.                   │
137       ├─────────────────────────────┼─────────────────────────────┤
138       │MT-Level                     │See below.                   │
139       └─────────────────────────────┴─────────────────────────────┘
140
141
142       The lgamma(), lgammaf(), lgammal(), and gamma() functions are Standard.
143       The lgamma_r(), lgammaf_r(), lgammal_r(),  gamma_r(),  gammaf_r(),  and
144       gammal_r(), functions are Stable.
145
146
147       The  lgamma(),  lgammaf(),  lgammal(),  gamma(), gammaf(), and gammal()
148       functions are Unsafe in  multithreaded  applications.  The  lgamma_r(),
149       lgammaf_r(),  lgammal_r(),  gamma_r(), gammaf_r(), and gammal_r() func‐
150       tions are MT-Safe and should be used instead.
151

SEE ALSO

153       exp(3M), feclearexcept(3M), fetestexcept(3M), isnan(3M), math.h(3HEAD),
154       attributes(5), standards(5)
155

NOTES

157       When  compiling multithreaded applications, the _REENTRANT flag must be
158       defined on the compile line.  This flag should only be used  in  multi‐
159       threaded applications.
160
161
162
163SunOS 5.11                        12 Jul 2006                       lgamma(3M)
Impressum