xref: /openbsd/lib/libm/man/lgamma.3 (revision cca36db2)
1.\"	$OpenBSD: lgamma.3,v 1.18 2011/07/07 01:34:52 martynas Exp $
2.\" Copyright (c) 1985, 1991 Regents of the University of California.
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\" 3. Neither the name of the University nor the names of its contributors
14.\"    may be used to endorse or promote products derived from this software
15.\"    without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27.\" SUCH DAMAGE.
28.\"
29.\"     from: @(#)lgamma.3	6.6 (Berkeley) 12/3/92
30.\"
31.Dd $Mdocdate: July 7 2011 $
32.Dt LGAMMA 3
33.Os
34.Sh NAME
35.Nm lgamma ,
36.Nm lgammaf ,
37.Nm lgammal ,
38.Nm tgamma ,
39.Nm tgammaf ,
40.Nm tgammal
41.Nd log gamma functions
42.Sh SYNOPSIS
43.Fd #include <math.h>
44.Ft extern int
45.Fa signgam ;
46.sp
47.Ft double
48.Fn lgamma "double x"
49.Ft float
50.Fn lgammaf "float x"
51.Ft long double
52.Fn lgammal "long double x"
53.Ft double
54.Fn tgamma "double x"
55.Ft float
56.Fn tgammaf "float x"
57.Ft long double
58.Fn tgammal "long double x"
59.Sh DESCRIPTION
60.Fn lgamma x
61.if t \{\
62returns ln\||\(*G(x)| where
63.Bd -unfilled -offset indent
64\(*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
65.br
66\(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px))	for x < 1.
67.Ed
68.\}
69.if n \
70returns ln\||\(*G(x)|.
71.Pp
72The external integer
73.Fa signgam
74returns the sign of \(*G(x).
75The
76.Fn lgammaf
77function is a single precision version of
78.Fn lgamma .
79The
80.Fn lgammal
81function is an extended precision version of
82.Fn lgamma .
83.Pp
84The
85.Fn tgamma x ,
86.Fn tgammaf x
87and
88.Fn tgammal x
89functions return \(*G(x), with no effect on
90.Fa signgam .
91.Sh IDIOSYNCRASIES
92Do not use the expression
93.Sq Li signgam\(**exp(lgamma(x))
94to compute g := \(*G(x).
95Instead use a program like this (in C):
96.Bd -literal -offset indent
97lg = lgamma(x); g = signgam\(**exp(lg);
98.Ed
99.Pp
100Only after
101.Fn lgamma
102has returned can signgam be correct.
103.Pp
104For arguments in its range,
105.Fn tgamma
106is preferred, as for positive arguments
107it is accurate to within one unit in the last place.
108.Sh RETURN VALUES
109.Fn lgamma
110returns appropriate values unless an argument is out of range.
111Overflow will occur for sufficiently large positive values, and
112non-positive integers.
113For large non-integer negative values,
114.Fn tgamma
115will underflow.
116On the
117.Tn VAX ,
118the reserved operator is returned,
119and
120.Va errno
121is set to
122.Er ERANGE .
123.Sh SEE ALSO
124.Xr infnan 3
125.Sh STANDARDS
126The
127.Fn lgamma ,
128.Fn lgammaf ,
129.Fn lgammal ,
130.Fn tgamma ,
131.Fn tgammaf ,
132and
133.Fn tgammal
134functions are expected to conform to
135.St -isoC-99 .
136.Pp
137.Fn gamma
138and
139.Fn gammaf
140are deprecated aliases for
141.Fn lgamma
142and
143.Fn lgammaf ,
144respectively.
145.Sh HISTORY
146The
147.Fn lgamma
148function first appeared in
149.Bx 4.3 .
150The
151.Fn tgamma
152function first appeared in
153.Ox 4.4 ,
154and is based on the
155.Fn gamma
156function that appeared in
157.Bx 4.4
158as a function to compute \(*G(x).
159