1.\" Copyright (c) 1985, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.roff%
5.\"
6.\"     @(#)lgamma.3	8.1 (Berkeley) 06/04/93
7.\"
8.Dd
9.Dt LGAMMA 3
10.Os BSD 4.3
11.Sh NAME
12.Nm lgamma
13.Nm gamma
14.Nd log gamma function, gamma function
15.Sh SYNOPSIS
16.Fd #include <math.h>
17.Ft extern int
18.Fa signgam ;
19.sp
20.Ft double
21.Fn lgamma "double x"
22.Ft double
23.Fn gamma "double x"
24.Sh DESCRIPTION
25.Fn Lgamma x
26.if t \{\
27returns ln\||\(*G(x)| where
28.Bd -unfilled -offset indent
29\(*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
30.br
31\(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px))	for x < 1.
32.Ed
33.\}
34.if n \
35returns ln\||\(*G(x)|.
36.Pp
37The external integer
38.Fa signgam
39returns the sign of \(*G(x).
40.Pp
41.Fn Gamma x
42returns \(*G(x), with no effect on
43.Fa signgam .
44.Sh IDIOSYNCRASIES
45Do not use the expression
46.Dq Li signgam\(**exp(lgamma(x))
47to compute g := \(*G(x).
48Instead use a program like this (in C):
49.Bd -literal -offset indent
50lg = lgamma(x); g = signgam\(**exp(lg);
51.Ed
52.Pp
53Only after
54.Fn lgamma
55has returned can signgam be correct.
56.Pp
57For arguments in its range,
58.Fn gamma
59is preferred, as for positive arguments
60it is accurate to within one unit in the last place.
61Exponentiation of
62.Fn lgamma
63will lose up to 10 significant bits.
64.Sh RETURN VALUES
65.Fn Gamma
66and
67.Fn lgamma
68return appropriate values unless an arguent is out of range.
69Overflow will occur for sufficiently large positive values, and
70non-positive integers.
71On the
72.Tn VAX,
73the reserved operator is returned,
74and
75.Va errno
76is set to
77.Er ERANGE
78For large non-integer negative values,
79.Fn gamma
80will underflow.
81.Sh SEE ALSO
82.Xr math 3 ,
83.Xr infnan 3
84.Sh HISTORY
85The
86.Nm lgamma
87function appeared in
88.Bx 4.3 .
89The
90.Nm gamma
91function appeared in
92.Bx 4.4 .
93The name
94.Fn gamma
95was originally dedicated to the
96.Fn lgamma
97function, so some old code may no longer be compatible.
98