Debian Codegraph @

upstream/debian-unstable/man3/lgamma.3

raw
1 .\" Copyright 2002, Walter Harms <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: GPL-1.0-or-later
5 .\"
6 .TH lgamma 3 2026-02-08 "Linux man-pages 6.18"
7 .SH NAME
8 lgamma, lgammaf, lgammal, lgamma_r, lgammaf_r, lgammal_r, signgam \-
9 log gamma function
10 .SH LIBRARY
11 Math library
12 .RI ( libm ,\~ \-lm )
13 .SH SYNOPSIS
14 .nf
15 .B #include <math.h>
16 .P
17 .BI "double lgamma(double " x );
18 .BI "float lgammaf(float " x );
19 .BI "long double lgammal(long double " x );
20 .P
21 .BI "double lgamma_r(double " x ", int *" signp );
22 .BI "float lgammaf_r(float " x ", int *" signp );
23 .BI "long double lgammal_r(long double " x ", int *" signp );
24 .P
25 .BI "extern int " signgam ;
26 .fi
27 .P
28 .RS -4
29 Feature Test Macro Requirements for glibc (see
30 .BR feature_test_macros (7)):
31 .RE
32 .P
33 .nf
34 .BR lgamma ():
35 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE
36 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
37 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
38 .fi
39 .P
40 .BR lgammaf (),
41 .BR lgammal ():
42 .nf
43 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
44 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
45 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
46 .fi
47 .P
48 .BR lgamma_r (),
49 .BR lgammaf_r (),
50 .BR lgammal_r ():
51 .nf
52 /* Since glibc 2.19: */ _DEFAULT_SOURCE
53 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
54 .fi
55 .P
56 .IR signgam :
57 .nf
58 _XOPEN_SOURCE
59 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
60 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
61 .fi
62 .SH DESCRIPTION
63 For the definition of the Gamma function, see
64 .BR tgamma (3).
65 .P
66 The
67 .BR lgamma (),
68 .BR lgammaf (),
69 and
70 .BR lgammal ()
71 functions return the natural logarithm of
72 the absolute value of the Gamma function.
73 The sign of the Gamma function is returned in the
74 external integer
75 .I signgam
76 declared in
77 .IR <math.h> .
78 It is 1 when the Gamma function is positive or zero, \-1
79 when it is negative.
80 .P
81 Since using a constant location
82 .I signgam
83 is not thread-safe, the functions
84 .BR lgamma_r (),
85 .BR lgammaf_r (),
86 and
87 .BR lgammal_r ()
88 have been introduced;
89 they return the sign via the argument
90 .IR signp .
91 .SH RETURN VALUE
92 On success, these functions return the natural logarithm of Gamma(x).
93 .P
94 If
95 .I x
96 is a NaN, a NaN is returned.
97 .P
98 If
99 .I x
100 is 1 or 2, +0 is returned.
101 .P
102 If
103 .I x
104 is positive infinity or negative infinity,
105 positive infinity is returned.
106 .P
107 If
108 .I x
109 is a nonpositive integer,
110 a pole error occurs,
111 and the functions return
112 .RB + HUGE_VAL ,
113 .RB + HUGE_VALF ,
114 or
115 .RB + HUGE_VALL ,
116 respectively.
117 .P
118 If the result overflows,
119 a range error occurs,
120 .\" e.g., lgamma(DBL_MAX)
121 and the functions return
122 .BR HUGE_VAL ,
123 .BR HUGE_VALF ,
124 or
125 .BR HUGE_VALL ,
126 respectively, with the correct mathematical sign.
127 .SH ERRORS
128 See
129 .BR math_error (7)
130 for information on how to determine whether an error has occurred
131 when calling these functions.
132 .P
133 The following errors can occur:
134 .TP
135 Pole error: \f[I]x\f[] is a nonpositive integer
136 .I errno
137 is set to
138 .B ERANGE
139 (but see BUGS).
140 A divide-by-zero floating-point exception
141 .RB ( FE_DIVBYZERO )
142 is raised.
143 .TP
144 Range error: result overflow
145 .I errno
146 is set to
147 .BR ERANGE .
148 An overflow floating-point exception
149 .RB ( FE_OVERFLOW )
150 is raised.
151 .\" glibc (as at 2.8) also supports an inexact
152 .\" exception for various cases.
153 .SH STANDARDS
154 .TP
155 .BR lgamma ()
156 .TQ
157 .BR lgammaf ()
158 .TQ
159 .BR lgammal ()
160 C11, POSIX.1-2008.
161 .TP
162 .I signgam
163 POSIX.1-2008.
164 .TP
165 .BR lgamma_r ()
166 .TQ
167 .BR lgammaf_r ()
168 .TQ
169 .BR lgammal_r ()
170 None.
171 .SH HISTORY
172 .TP
173 .BR lgamma ()
174 .TQ
175 .BR lgammaf ()
176 .TQ
177 .BR lgammal ()
178 C99, POSIX.1-2001.
179 .TP
180 .I signgam
181 POSIX.1-2001.
182 .TP
183 .BR lgamma_r ()
184 .TQ
185 .BR lgammaf_r ()
186 .TQ
187 .BR lgammal_r ()
188 None.
189 .SH BUGS
190 In glibc 2.9 and earlier,
191 .\" https://www.sourceware.org/bugzilla/show_bug.cgi?id=6777
192 when a pole error occurs,
193 .I errno
194 is set to
195 .BR EDOM ;
196 instead of the POSIX-mandated
197 .BR ERANGE .
198 Since glibc 2.10, glibc does the right thing.
199 .SH SEE ALSO
200 .BR tgamma (3)