xref: /freebsd/lib/msun/man/lgamma.3 (revision 4543ef516683042d46f3bd3bb8a4f3f746e00499)
1.\" Copyright (c) 1985, 1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd December 8, 2017
29.Dt LGAMMA 3
30.Os
31.Sh NAME
32.Nm lgamma ,
33.Nm lgamma_r ,
34.Nm lgammaf ,
35.Nm lgammaf_r ,
36.Nm lgammal ,
37.Nm lgammal_r ,
38.Nm gamma ,
39.Nm gamma_r ,
40.Nm gammaf ,
41.Nm gammaf_r ,
42.Nm tgamma ,
43.Nm tgammaf ,
44.Nm tgammal ,
45.Nd log gamma functions, gamma function
46.Sh LIBRARY
47.Lb libm
48.Sh SYNOPSIS
49.In math.h
50.Ft extern int
51.Fa signgam ;
52.sp
53.Ft double
54.Fn lgamma "double x"
55.Ft double
56.Fn lgamma_r "double x" "int *signgamp"
57.Ft float
58.Fn lgammaf "float x"
59.Ft float
60.Fn lgammaf_r "float x" "int *signgamp"
61.Ft "long double"
62.Fn lgammal "long double x"
63.Ft "long double"
64.Fn lgammal_r "long double x" "int *signgamp"
65.Ft double
66.Fn gamma "double x"
67.Ft double
68.Fn gamma_r "double x" "int *signgamp"
69.Ft float
70.Fn gammaf "float x"
71.Ft float
72.Fn gammaf_r "float x" "int *signgamp"
73.Ft "long double"
74.Fn tgamma "double x"
75.Ft float
76.Fn tgammaf "float x"
77.Ft "long double"
78.Fn tgammal "long double x"
79.Sh DESCRIPTION
80.Fn lgamma x ,
81.Fn lgammaf x ,
82and
83.Fn lgammal x
84.if t \{\
85return ln\||\(*G(x)| where
86.Bd -unfilled -offset indent
87\(*G(x) = \(is\d\s8\z0\s10\u\u\s8\(if\s10\d t\u\s8x\-1\s10\d e\u\s8\-t\s10\d dt	for x > 0 and
88\(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px))	for x < 1.
89.Ed
90.\}
91.if n \
92return ln\||\(*G(x)|.
93The external integer
94.Fa signgam
95returns the sign of \(*G(x).
96.Pp
97.Fn lgamma_r x signgamp ,
98.Fn lgammaf_r x signgamp ,
99and
100.Fn lgammal_r x signgamp
101provide the same functionality as
102.Fn lgamma x ,
103.Fn lgammaf x ,
104and
105.Fn lgammal x ,
106but the caller must provide an integer to store the sign of \(*G(x).
107.Pp
108The
109.Fn tgamma x ,
110.Fn tgammaf x ,
111and
112.Fn tgammal x
113functions return \(*G(x), with no effect on
114.Fa signgam .
115.Pp
116.Fn gamma ,
117.Fn gammaf ,
118.Fn gamma_r ,
119and
120.Fn gammaf_r
121are deprecated aliases for
122.Fn lgamma ,
123.Fn lgammaf ,
124.Fn lgamma_r ,
125and
126.Fn lgammaf_r ,
127respectively.
128.Sh IDIOSYNCRASIES
129Do not use the expression
130.Dq Li signgam\(**exp(lgamma(x))
131to compute g := \(*G(x).
132Instead use a program like this (in C):
133.Bd -literal -offset indent
134lg = lgamma(x); g = signgam\(**exp(lg);
135.Ed
136.Pp
137Only after
138.Fn lgamma
139or
140.Fn lgammaf
141has returned can signgam be correct.
142.Pp
143For arguments in its range,
144.Fn tgamma
145is preferred, as for positive arguments
146it is accurate to within one unit in the last place.
147Exponentiation of
148.Fn lgamma
149will lose up to 10 significant bits.
150.Sh RETURN VALUES
151.Fn gamma ,
152.Fn gammaf ,
153.Fn gammal ,
154.Fn gamma_r ,
155.Fn gammaf_r ,
156.Fn gammal_r ,
157.Fn lgamma ,
158.Fn lgammaf ,
159.Fn lgammal ,
160.Fn lgamma_r ,
161.Fn lgammaf_r ,
162and
163.Fn lgammal_r
164return appropriate values unless an argument is out of range.
165Overflow will occur for sufficiently large positive values, and
166non-positive integers.
167For large non-integer negative values,
168.Fn tgamma
169will underflow.
170.Sh BUGS
171To conform with newer C/C++ standards, a stub implementation for
172.Nm tgammal
173was committed to the math library, where
174.Nm tgammal
175is mapped to
176.Nm tgamma .
177Thus, the numerical accuracy is at most that of the 53-bit double
178precision implementation.
179.Sh SEE ALSO
180.Xr math 3
181.Sh STANDARDS
182The
183.Fn lgamma ,
184.Fn lgammaf ,
185.Fn lgammal ,
186.Fn tgamma ,
187.Fn tgammaf ,
188and
189.Fn tgammal
190functions are expected to conform to
191.St -isoC-99 .
192.Sh HISTORY
193The
194.Fn lgamma
195function appeared in
196.Bx 4.3 .
197The
198.Fn gamma
199function appeared in
200.Bx 4.4
201as a function which computed \(*G(x).
202This version was used in
203.Fx 1.1 .
204The name
205.Fn gamma
206was originally dedicated to the
207.Fn lgamma
208function,
209and that usage was restored by switching to Sun's fdlibm in
210.Fx 1.1.5 .
211The
212.Fn tgamma
213function appeared in
214.Fx 5.0 .
215