NetBSD/lib/libm/common_source/lgamma.3
1993-03-21 09:45:37 +00:00

157 lines
4.5 KiB
Groff

.\" Copyright (c) 1985, 1991 Regents of the University of California.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)lgamma.3 6.4 (Berkeley) 5/6/91
.\"
.Dd May 6, 1991
.Dt LGAMMA 3
.Os BSD 4.3
.Sh NAME
.Nm lgamma
.Nd log gamma function
.Sh SYNOPSIS
.Fd #include <math.h>
.Ft double
.Fn lgamma "double x"
.Sh DESCRIPTION
.ta \w'Lgamma returns ln\||\(*G(x)| where'u+1n +1.7i
.if t \{\
Lgamma returns ln\||\(*G(x)| where
.Bd -unfilled -offset indent
\(*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
.br
\(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px)) for x < 1. \}
.Ed
.if n \
Lgamma returns ln\||\(*G(x)|.
.ta
.Pp
The external integer
.Fa signgam
returns the sign of
\(*G(x) .
.Sh IDIOSYNCRASIES
Do
.Em not
use the expression
.Dq Li signgam\(**exp(lgamma(x))
to compute g := \(*G(x). Instead use a program like this (in C):
.Bd -literal -offset indent
lg = lgamma(x); g = signgam\(**exp(lg);
.Ed
.Pp
Only after
.Fn lgamma
has returned can signgam be correct.
Note too that \(*G(x) must overflow when x is large enough,
underflow when \-x is large enough, and spawn a division by zero
when x is a nonpositive integer.
.Pp
Only in the
.Tn UNIX
math library for C was the name gamma ever attached
to ln\(*G. Elsewhere, for instance in
.Tn IBM Ns 's
.Tn FORTRAN
library, the name
.Tn GAMMA
belongs to \(*G and the name
.Tn ALGAMA
to ln\(*G in single precision;
in double the names are
.Tn DGAMMA
and
.Tn DLGAMA .
Why should C be different?
.Pp
Archaeological records suggest that C's
.Em gamma
originally delivered
ln(\(*G(|x|)). Later, the program gamma was changed to
cope with negative arguments x in a more conventional way, but
the documentation did not reflect that change correctly. The most
recent change corrects inaccurate values when x is almost a
negative integer, and lets \(*G(x) be computed without
conditional expressions. Programmers should not assume that
.Fn lgamma
has settled down.
.Pp
At some time in the future, the name
.Em gamma
will be rehabilitated
and used for the gamma function, just as is done in
.Tn FORTRAN .
The reason for this is not so much compatibility with
.Tn FORTRAN
as a
desire to achieve greater speed for smaller values of |x| and greater
accuracy for larger values.
.Pp
Meanwhile, programmers who have to use the name
.Em gamma
in its former
sense, for what is now
.Fn lgamma ,
have two choices:
.Bl -enum -width indent
.It
Use the old math library,
.Pa libom .
.It
Add the following program to your others:
.Bd -literal -offset indent
#include <math.h>
double gamma(x)
double x;
{
return (lgamma(x));
}
.Ed
.Sh DIAGNOSTICS
The reserved operand is returned on a
.Tn VAX
for negative integer arguments,
.Va errno
is set to
.Er ERANGE ;
for very large arguments over/underflows will
occur inside the
.Fn lgamma
routine.
.Sh SEE ALSO
.Xr math 3 ,
.Xr infnan 3
.Sh HISTORY
The
.Nm
function appeared in
.Bx 4.3 .