1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group. In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The Berkeley software License Agreement specifies the terms and conditions
.\" for redistribution.
.\"
.\"
.\" Copyright (c) 1983 Regents of the University of California.
.\" All rights reserved.
.\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Copyright (c) 2001, The IEEE and The Open Group. All Rights Reserved.
.\" Portions Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
.\"
.TH LGAMMA 3M "Jul 12, 2006" "SunOS 5.11" "Mathematical Library Functions"
.SH NAME
lgamma, lgammaf, lgammal, lgamma_r, lgammaf_r, lgammal_r, gamma, gammaf,
gammal, gamma_r, gammaf_r, gammal_r \- log gamma function
.SH SYNOPSIS
.LP
.nf
c99 [ \fIflag\fR... ] \fIfile\fR... \fB-lm\fR [ \fIlibrary\fR... ]
#include <math.h>
extern int signgam;
\fBdouble\fR \fBlgamma\fR(\fBdouble\fR \fIx\fR);
.fi
.LP
.nf
\fBfloat\fR \fBlgammaf\fR(\fBfloat\fR \fIx\fR);
.fi
.LP
.nf
\fBlong double\fR \fBlgammal\fR(\fBlong double\fR \fIx\fR);
.fi
.LP
.nf
\fBdouble\fR \fBgamma\fR(\fBdouble\fR \fIx\fR);
.fi
.LP
.nf
\fBfloat\fR \fBgammaf\fR(\fBfloat\fR \fIx\fR);
.fi
.LP
.nf
\fBlong double\fR \fBgammal\fR(\fBlong double\fR \fIx\fR);
.fi
.LP
.nf
\fBdouble\fR \fBlgamma_r\fR(\fBdouble\fR \fIx\fR, \fBint *\fR\fIsigngamp\fR);
.fi
.LP
.nf
\fBfloat\fR \fBlgammaf_r\fR(\fBfloat\fR \fIx\fR, \fBint *\fR\fIsigngamp\fR);
.fi
.LP
.nf
\fBlong double\fR \fBlgammal_r\fR(\fBlong double\fR \fIx\fR, \fBint *\fR\fIsigngamp\fR);
.fi
.LP
.nf
\fBdouble\fR \fBgamma_r\fR(\fBdouble\fR \fIx\fR, \fBint *\fR\fIsigngamp\fR);
.fi
.LP
.nf
\fBfloat\fR \fBgammaf_r\fR(\fBfloat\fR \fIx\fR, \fBint *\fR\fIsigngamp\fR);
.fi
.LP
.nf
\fBlong double\fR \fBgammal_r\fR(\fBlong double\fR \fIx\fR, \fBint *\fR\fIsigngamp\fR);
.fi
.SH DESCRIPTION
.sp
.LP
These functions return
.sp
ln||~(x)|
.sp
.LP
where
.sp
|~(x) = integral from 0 to +Infinity of pow(t,x-1)*exp(-t) dt
.sp
.LP
for x > 0 and
.sp
|~(x) = n/(|~(1-x)sin(nx))
.sp
.LP
for x < 1.
.sp
.LP
These functions use the external integer \fBsigngam\fR to return the sign of
\fB|~(x)\fR while \fBlgamma_r()\fR and \fBgamma_r()\fR use the user-allocated
space addressed by \fBsigngamp\fR.
.SH RETURN VALUES
.sp
.LP
Upon successful completion, these functions return the logarithmic gamma of
\fIx\fR.
.sp
.LP
If \fIx\fR is a non-positive integer, a pole error occurs and these functions
return +\fBHUGE_VAL\fR, +\fBHUGE_VALF\fR, and +\fBHUGE_VALL\fR, respectively.
.sp
.LP
If \fIx\fR is NaN, a NaN is returned.
.sp
.LP
If \fIx\fR is 1 or 2, +0 shall be returned.
.sp
.LP
If \fIx\fR is \(+-Inf, +Inf is returned.
.SH ERRORS
.sp
.LP
These functions will fail if:
.sp
.ne 2
.mk
.na
\fBPole Error\fR
.ad
.RS 14n
.rt
The \fIx\fR argument is a negative integer or 0.
.sp
If the integer expression (\fBmath_errhandling\fR & \fBMATH_ERREXCEPT\fR) is
non-zero, then the divide-by-zero floating-point exception is raised.
.RE
.SH USAGE
.sp
.LP
An application wanting to check for exceptions should call
\fBfeclearexcept\fR(\fBFE_ALL_EXCEPT\fR) before calling these functions. On
return, if \fBfetestexcept\fR(\fBFE_INVALID\fR | \fBFE_DIVBYZERO\fR |
\fBFE_OVERFLOW\fR | \fBFE_UNDERFLOW\fR) is non-zero, an exception has been
raised. An application should either examine the return value or check the
floating point exception flags to detect exceptions.
.sp
.LP
In the case of \fBlgamma()\fR, do not use the expression
\fBsigngam*exp(lgamma(x))\fR to compute
.sp
`g := |~(x)'
.sp
.LP
Instead compute \fBlgamma()\fR first:
.sp
.LP
\fBlg = lgamma(x); g = signgam*exp(lg);\fR
.sp
.LP
only after \fBlgamma()\fR has returned can \fBsigngam\fR be correct. Note that
\fB|~(x)\fR must overflow when \fIx\fR is large enough, underflow when
\(mi\fIx\fR is large enough, and generate a division by 0 exception at the
singularities \fIx\fR a nonpositive integer.
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
tab( ) box;
cw(2.75i) |cw(2.75i)
lw(2.75i) |lw(2.75i)
.
ATTRIBUTE TYPE ATTRIBUTE VALUE
_
Interface Stability See below.
_
MT-Level See below.
.TE
.sp
.LP
The \fBlgamma()\fR, \fBlgammaf()\fR, \fBlgammal()\fR, and \fBgamma()\fR
functions are Standard. The \fBlgamma_r()\fR, \fBlgammaf_r()\fR,
\fBlgammal_r()\fR, \fBgamma_r()\fR, \fBgammaf_r()\fR, and \fBgammal_r()\fR,
functions are Stable.
.sp
.LP
The \fBlgamma()\fR, \fBlgammaf()\fR, \fBlgammal()\fR, \fBgamma()\fR,
\fBgammaf()\fR, and \fBgammal()\fR functions are Unsafe in multithreaded
applications. The \fBlgamma_r()\fR, \fBlgammaf_r()\fR, \fBlgammal_r()\fR,
\fBgamma_r()\fR, \fBgammaf_r()\fR, and \fBgammal_r()\fR functions are MT-Safe
and should be used instead.
.SH SEE ALSO
.sp
.LP
\fBexp\fR(3M), \fBfeclearexcept\fR(3M), \fBfetestexcept\fR(3M),
\fBisnan\fR(3M), \fBmath.h\fR(3HEAD), \fBattributes\fR(5), \fBstandards\fR(5)
.SH NOTES
.sp
.LP
When compiling multithreaded applications, the \fB_REENTRANT\fR flag must be
defined on the compile line. This flag should only be used in multithreaded
applications.
|