xref: /freebsd/lib/msun/man/lgamma.3 (revision a9dbc63dc2a2c6866b650af62ab04bc59da50d30)
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. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     from: @(#)lgamma.3	6.6 (Berkeley) 12/3/92
33.\" $FreeBSD$
34.\"
35.Dd December 3, 1992
36.Dt LGAMMA 3
37.Os
38.Sh NAME
39.Nm lgamma ,
40.Nm lgammaf ,
41.Nm gamma ,
42.Nm gammaf
43.Nd log gamma functions, gamma functions
44.Sh LIBRARY
45.Lb libm
46.Sh SYNOPSIS
47.In math.h
48.Ft extern int
49.Fa signgam ;
50.sp
51.Ft double
52.Fn lgamma "double x"
53.Ft float
54.Fn lgammaf "float x"
55.Ft double
56.Fn gamma "double x"
57.Ft float
58.Fn gammaf "float x"
59.Sh DESCRIPTION
60.Fn lgamma x
61and
62.Fn lgammaf x
63.if t \{\
64return ln\||\(*G(x)| where
65.Bd -unfilled -offset indent
66\(*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
67.br
68\(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px))	for x < 1.
69.Ed
70.\}
71.if n \
72return ln\||\(*G(x)|.
73.Pp
74The external integer
75.Fa signgam
76returns the sign of \(*G(x).
77.Pp
78.Fn gamma x
79and
80.Fn gammaf x
81return ln\||\(*G(x)|, with no effect on
82.Fa signgam .
83.Sh IDIOSYNCRASIES
84Do not use the expression
85.Dq Li signgam\(**exp(lgamma(x))
86to compute g := \(*G(x).
87Instead use a program like this (in C):
88.Bd -literal -offset indent
89lg = lgamma(x); g = signgam\(**exp(lg);
90.Ed
91.Pp
92Only after
93.Fn lgamma
94or
95.Fn lgammaf
96has returned can signgam be correct.
97.\.Pp
98.\For arguments in its range,
99.\.Fn gamma
100.\and
101.\.Fn gammaf
102.\is preferred, as for positive arguments
103.\it is accurate to within one unit in the last place.
104.\Exponentiation of
105.\.Fn lgamma
106.\will lose up to 10 significant bits.
107.Sh RETURN VALUES
108.Fn gamma ,
109.Fn gammaf ,
110.Fn lgamma ,
111and
112.Fn lgammaf
113return appropriate values unless an argument is out of range.
114Overflow will occur for sufficiently large positive values, and
115non-positive integers.
116On the
117.Tn VAX ,
118the reserved operator is returned,
119and
120.Va errno
121is set to
122.Er ERANGE .
123For large non-integer negative values,
124.Fn gamma
125will underflow.
126.Sh SEE ALSO
127.Xr math 3
128.Sh HISTORY
129The
130.Fn lgamma
131function appeared in
132.Bx 4.3 .
133The
134.Fn gamma
135function appeared in
136.Bx 4.4
137as a function which computed  \(*G(x).
138In many older libraries the function
139.Fn gamma
140calculated the same value as
141.Fn lgamma .
142Now
143.Fn gamma
144computes ln\||\(*G(x)|,
145but it uses a different algorithm,
146and it does not set
147.Fa signgam .
148The
149.St -isoC-99
150standard specifies a function
151.Fn tgamma
152for computing \(*G(x).
153This function is currently unimplimented in this library.
154