xref: /freebsd/lib/msun/man/lgamma.3 (revision 737799dfd3a87cbbe1ff091c13a90c98e3ee21d3)
13a8617a8SJordan K. Hubbard.\" Copyright (c) 1985, 1991 Regents of the University of California.
23a8617a8SJordan K. Hubbard.\" All rights reserved.
33a8617a8SJordan K. Hubbard.\"
43a8617a8SJordan K. Hubbard.\" Redistribution and use in source and binary forms, with or without
53a8617a8SJordan K. Hubbard.\" modification, are permitted provided that the following conditions
63a8617a8SJordan K. Hubbard.\" are met:
73a8617a8SJordan K. Hubbard.\" 1. Redistributions of source code must retain the above copyright
83a8617a8SJordan K. Hubbard.\"    notice, this list of conditions and the following disclaimer.
93a8617a8SJordan K. Hubbard.\" 2. Redistributions in binary form must reproduce the above copyright
103a8617a8SJordan K. Hubbard.\"    notice, this list of conditions and the following disclaimer in the
113a8617a8SJordan K. Hubbard.\"    documentation and/or other materials provided with the distribution.
12fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
133a8617a8SJordan K. Hubbard.\"    may be used to endorse or promote products derived from this software
143a8617a8SJordan K. Hubbard.\"    without specific prior written permission.
153a8617a8SJordan K. Hubbard.\"
163a8617a8SJordan K. Hubbard.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
173a8617a8SJordan K. Hubbard.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
183a8617a8SJordan K. Hubbard.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
193a8617a8SJordan K. Hubbard.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
203a8617a8SJordan K. Hubbard.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
213a8617a8SJordan K. Hubbard.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
223a8617a8SJordan K. Hubbard.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
233a8617a8SJordan K. Hubbard.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
243a8617a8SJordan K. Hubbard.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
253a8617a8SJordan K. Hubbard.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
263a8617a8SJordan K. Hubbard.\" SUCH DAMAGE.
273a8617a8SJordan K. Hubbard.\"
28*737799dfSMark Murray.Dd April 12, 2024
293a8617a8SJordan K. Hubbard.Dt LGAMMA 3
30a307d598SRuslan Ermilov.Os
313a8617a8SJordan K. Hubbard.Sh NAME
323a8617a8SJordan K. Hubbard.Nm lgamma ,
33457f6cd2SWarner Losh.Nm lgamma_r ,
347a15a32aSJordan K. Hubbard.Nm lgammaf ,
35457f6cd2SWarner Losh.Nm lgammaf_r ,
36f7efd14dSSteve Kargl.Nm lgammal ,
37f7efd14dSSteve Kargl.Nm lgammal_r ,
387a15a32aSJordan K. Hubbard.Nm gamma ,
39457f6cd2SWarner Losh.Nm gamma_r ,
4046d7c297SBruce Evans.Nm gammaf ,
41457f6cd2SWarner Losh.Nm gammaf_r ,
4271c11dd5SDavid Schultz.Nm tgamma ,
43240076e5SDimitry Andric.Nm tgammaf ,
44240076e5SDimitry Andric.Nm tgammal ,
4546d7c297SBruce Evans.Nd log gamma functions, gamma function
4664890443SBruce Evans.Sh LIBRARY
4764890443SBruce Evans.Lb libm
483a8617a8SJordan K. Hubbard.Sh SYNOPSIS
4932eef9aeSRuslan Ermilov.In math.h
503a8617a8SJordan K. Hubbard.Ft extern int
513a8617a8SJordan K. Hubbard.Fa signgam ;
523a8617a8SJordan K. Hubbard.sp
533a8617a8SJordan K. Hubbard.Ft double
543a8617a8SJordan K. Hubbard.Fn lgamma "double x"
55457f6cd2SWarner Losh.Ft double
563892c300SRuslan Ermilov.Fn lgamma_r "double x" "int *signgamp"
577a15a32aSJordan K. Hubbard.Ft float
587a15a32aSJordan K. Hubbard.Fn lgammaf "float x"
59457f6cd2SWarner Losh.Ft float
603892c300SRuslan Ermilov.Fn lgammaf_r "float x" "int *signgamp"
61f7efd14dSSteve Kargl.Ft "long double"
62f7efd14dSSteve Kargl.Fn lgammal "long double x"
63f7efd14dSSteve Kargl.Ft "long double"
64f7efd14dSSteve Kargl.Fn lgammal_r "long double x" "int *signgamp"
653a8617a8SJordan K. Hubbard.Ft double
663a8617a8SJordan K. Hubbard.Fn gamma "double x"
67457f6cd2SWarner Losh.Ft double
683892c300SRuslan Ermilov.Fn gamma_r "double x" "int *signgamp"
697a15a32aSJordan K. Hubbard.Ft float
70354fb385SBruce Evans.Fn gammaf "float x"
71457f6cd2SWarner Losh.Ft float
723892c300SRuslan Ermilov.Fn gammaf_r "float x" "int *signgamp"
73f7efd14dSSteve Kargl.Ft "long double"
7446d7c297SBruce Evans.Fn tgamma "double x"
7571c11dd5SDavid Schultz.Ft float
7671c11dd5SDavid Schultz.Fn tgammaf "float x"
77240076e5SDimitry Andric.Ft "long double"
78240076e5SDimitry Andric.Fn tgammal "long double x"
793a8617a8SJordan K. Hubbard.Sh DESCRIPTION
80f7efd14dSSteve Kargl.Fn lgamma x ,
81f7efd14dSSteve Kargl.Fn lgammaf x ,
827a15a32aSJordan K. Hubbardand
83f7efd14dSSteve Kargl.Fn lgammal x
843a8617a8SJordan K. Hubbard.if t \{\
857a15a32aSJordan K. Hubbardreturn ln\||\(*G(x)| where
863a8617a8SJordan K. Hubbard.Bd -unfilled -offset indent
873a8617a8SJordan K. Hubbard\(*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
883a8617a8SJordan K. Hubbard\(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px))	for x < 1.
893a8617a8SJordan K. Hubbard.Ed
903a8617a8SJordan K. Hubbard.\}
913a8617a8SJordan K. Hubbard.if n \
92354fb385SBruce Evansreturn ln\||\(*G(x)|.
933a8617a8SJordan K. HubbardThe external integer
943a8617a8SJordan K. Hubbard.Fa signgam
953a8617a8SJordan K. Hubbardreturns the sign of \(*G(x).
963a8617a8SJordan K. Hubbard.Pp
97f7efd14dSSteve Kargl.Fn lgamma_r x signgamp ,
98f7efd14dSSteve Kargl.Fn lgammaf_r x signgamp ,
997a15a32aSJordan K. Hubbardand
100f7efd14dSSteve Kargl.Fn lgammal_r x signgamp
101457f6cd2SWarner Loshprovide the same functionality as
102f7efd14dSSteve Kargl.Fn lgamma x ,
103f7efd14dSSteve Kargl.Fn lgammaf x ,
104457f6cd2SWarner Loshand
105f7efd14dSSteve Kargl.Fn lgammal x ,
1063892c300SRuslan Ermilovbut the caller must provide an integer to store the sign of \(*G(x).
107457f6cd2SWarner Losh.Pp
10871c11dd5SDavid SchultzThe
109240076e5SDimitry Andric.Fn tgamma x ,
110240076e5SDimitry Andric.Fn tgammaf x ,
11171c11dd5SDavid Schultzand
112240076e5SDimitry Andric.Fn tgammal x
11371c11dd5SDavid Schultzfunctions return \(*G(x), with no effect on
11471c11dd5SDavid Schultz.Fa signgam .
11571c11dd5SDavid Schultz.Pp
116457f6cd2SWarner Losh.Fn gamma ,
117457f6cd2SWarner Losh.Fn gammaf ,
118457f6cd2SWarner Losh.Fn gamma_r ,
119457f6cd2SWarner Loshand
120457f6cd2SWarner Losh.Fn gammaf_r
121675902aaSBruce Evansare deprecated aliases for
122457f6cd2SWarner Losh.Fn lgamma ,
123675902aaSBruce Evans.Fn lgammaf ,
124457f6cd2SWarner Losh.Fn lgamma_r ,
125457f6cd2SWarner Loshand
126457f6cd2SWarner Losh.Fn lgammaf_r ,
127675902aaSBruce Evansrespectively.
1283a8617a8SJordan K. Hubbard.Sh IDIOSYNCRASIES
1293a8617a8SJordan K. HubbardDo not use the expression
1303a8617a8SJordan K. Hubbard.Dq Li signgam\(**exp(lgamma(x))
1313a8617a8SJordan K. Hubbardto compute g := \(*G(x).
1323a8617a8SJordan K. HubbardInstead use a program like this (in C):
1333a8617a8SJordan K. Hubbard.Bd -literal -offset indent
1343a8617a8SJordan K. Hubbardlg = lgamma(x); g = signgam\(**exp(lg);
1353a8617a8SJordan K. Hubbard.Ed
1363a8617a8SJordan K. Hubbard.Pp
1373a8617a8SJordan K. HubbardOnly after
1383a8617a8SJordan K. Hubbard.Fn lgamma
1397a15a32aSJordan K. Hubbardor
1407a15a32aSJordan K. Hubbard.Fn lgammaf
1413a8617a8SJordan K. Hubbardhas returned can signgam be correct.
14246d7c297SBruce Evans.Pp
14346d7c297SBruce EvansFor arguments in its range,
14446d7c297SBruce Evans.Fn tgamma
14546d7c297SBruce Evansis preferred, as for positive arguments
14646d7c297SBruce Evansit is accurate to within one unit in the last place.
14746d7c297SBruce EvansExponentiation of
14846d7c297SBruce Evans.Fn lgamma
14946d7c297SBruce Evanswill lose up to 10 significant bits.
1503a8617a8SJordan K. Hubbard.Sh RETURN VALUES
1517a15a32aSJordan K. Hubbard.Fn gamma ,
1527a15a32aSJordan K. Hubbard.Fn gammaf ,
153f7efd14dSSteve Kargl.Fn gammal ,
154f7efd14dSSteve Kargl.Fn gamma_r ,
155457f6cd2SWarner Losh.Fn gammaf_r ,
156f7efd14dSSteve Kargl.Fn gammal_r ,
1577a15a32aSJordan K. Hubbard.Fn lgamma ,
158457f6cd2SWarner Losh.Fn lgammaf ,
159f7efd14dSSteve Kargl.Fn lgammal ,
160f7efd14dSSteve Kargl.Fn lgamma_r ,
161f7efd14dSSteve Kargl.Fn lgammaf_r ,
1623a8617a8SJordan K. Hubbardand
163f7efd14dSSteve Kargl.Fn lgammal_r
1643a8617a8SJordan K. Hubbardreturn appropriate values unless an argument is out of range.
1653a8617a8SJordan K. HubbardOverflow will occur for sufficiently large positive values, and
1663a8617a8SJordan K. Hubbardnon-positive integers.
16746d7c297SBruce EvansFor large non-integer negative values,
16846d7c297SBruce Evans.Fn tgamma
16946d7c297SBruce Evanswill underflow.
1703a8617a8SJordan K. Hubbard.Sh SEE ALSO
1714bd9ba3cSMike Pritchard.Xr math 3
17246d7c297SBruce Evans.Sh STANDARDS
17346d7c297SBruce EvansThe
17471c11dd5SDavid Schultz.Fn lgamma ,
17571c11dd5SDavid Schultz.Fn lgammaf ,
176f7efd14dSSteve Kargl.Fn lgammal ,
17771c11dd5SDavid Schultz.Fn tgamma ,
178240076e5SDimitry Andric.Fn tgammaf ,
17946d7c297SBruce Evansand
180240076e5SDimitry Andric.Fn tgammal
18146d7c297SBruce Evansfunctions are expected to conform to
18246d7c297SBruce Evans.St -isoC-99 .
1833a8617a8SJordan K. Hubbard.Sh HISTORY
1843a8617a8SJordan K. HubbardThe
185563f6bdeSRuslan Ermilov.Fn lgamma
1863a8617a8SJordan K. Hubbardfunction appeared in
1873a8617a8SJordan K. Hubbard.Bx 4.3 .
1883a8617a8SJordan K. HubbardThe
189563f6bdeSRuslan Ermilov.Fn gamma
1903a8617a8SJordan K. Hubbardfunction appeared in
191a9dbc63dSDavid Malone.Bx 4.4
192a9dbc63dSDavid Maloneas a function which computed \(*G(x).
193675902aaSBruce EvansThis version was used in
194675902aaSBruce Evans.Fx 1.1 .
195675902aaSBruce EvansThe name
1963a8617a8SJordan K. Hubbard.Fn gamma
197675902aaSBruce Evanswas originally dedicated to the
198675902aaSBruce Evans.Fn lgamma
199675902aaSBruce Evansfunction,
200675902aaSBruce Evansand that usage was restored by switching to Sun's fdlibm in
201675902aaSBruce Evans.Fx 1.1.5 .
202a9dbc63dSDavid MaloneThe
203a9dbc63dSDavid Malone.Fn tgamma
20446d7c297SBruce Evansfunction appeared in
20546d7c297SBruce Evans.Fx 5.0 .
206e38f2308SMark MurrayThe 128-bit
207e38f2308SMark Murray.Ft long double
208e38f2308SMark Murrayversion of
209e38f2308SMark Murray.Fn tgammal
210e38f2308SMark Murrayreplaced the 80-bit stub version in
211e38f2308SMark Murrayversion in
212*737799dfSMark Murray.Fx 14.1 ,
213e38f2308SMark Murraythanks to an appropriate implementation from Arm.
214