update for ANSI C from Alex Zliu and John Gilmore
[unix-history] / usr / src / lib / libm / common_source / lgamma.3
CommitLineData
f9628029
KM
1.\" Copyright (c) 1985 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
8220ec5a 5.\" @(#)lgamma.3 6.2 (Berkeley) %G%
f9628029
KM
6.\"
7.TH LGAMMA 3M ""
8.UC 6
d96ea8d5 9.SH NAME
f9628029 10lgamma \- log gamma function
d96ea8d5
MAN
11.SH SYNOPSIS
12.nf
13.B #include <math.h>
14.PP
f9628029 15.B double lgamma(x)
d96ea8d5
MAN
16.B double x;
17.fi
18.SH DESCRIPTION
f9628029
KM
19.nf
20.ta \w'Lgamma returns ln\||\(*G(x)| where'u+1n +1.7i
21.if t \{\
22Lgamma returns ln\||\(*G(x)| where \(*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
23.br
24 \(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px)) for x < 1. \}
25.if n \
26Lgamma returns ln\||\(*G(x)|.
27.ta
28.fi
29.PP
30The external integer signgam returns the sign of
31\(*G(x) .
32.SH IDIOSYNCRASIES
33Do \fBnot\fR use the expression signgam\(**exp(lgamma(x))
34to compute g := \(*G(x). Instead use a program like this (in C):
35.RS
36lg = lgamma(x); g = signgam\(**exp(lg);
37.RE
38.PP
39Only after lgamma has returned can signgam be correct.
40Note too that \(*G(x) must overflow when x is large enough,
41underflow when \-x is large enough, and spawn a division by zero
42when x is a nonpositive integer.
43.PP
44Only in the UNIX math library for C was the name gamma ever attached
45to ln\(*G. Elsewhere, for instance in IBM's FORTRAN library, the name
46GAMMA belongs to \(*G and the name ALGAMA to ln\(*G in single precision;
47in double the names are DGAMMA and DLGAMA. Why should C be different?
48.PP
49Archaeological records suggest that C's gamma originally delivered
50ln(\(*G(|x|)). Later, the program gamma was changed to
51cope with negative arguments x in a more conventional way, but
52the documentation did not reflect that change correctly. The most
53recent change corrects inaccurate values when x is almost a
54negative integer, and lets \(*G(x) be computed without
55conditional expressions. Programmers should not assume that
56lgamma has settled down.
57.PP
58At some time in the future, the name \fIgamma\fR will be rehabilitated
59and used for the gamma function, just as is done in FORTRAN.
60The reason for this is not so much compatibility with FORTRAN as a
61desire to achieve greater speed for smaller values of |x| and greater
62accuracy for larger values.
d96ea8d5 63.PP
f9628029
KM
64Meanwhile, programmers who have to use the name \fIgamma\fR in its former
65sense, for what is now \fIlgamma\fR, have two choices:
66.IP 1) \w'1)\0'u
67Use the old math library, \fIlibom\fR.
68.IP 2) \w'1)\0'u
69Add the following program to your others:
70.RS
d96ea8d5 71.nf
f9628029
KM
72\fB#include <math.h>
73double gamma(x)
74double x;
75{
76.RS
77\fBreturn (lgamma(x));
78.RE
79}\fR
80.RE
d96ea8d5
MAN
81.fi
82.SH DIAGNOSTICS
f9628029
KM
83The reserved operand is returned on a VAX for negative integer arguments,
84\fIerrno\fR is set to ERANGE; for very large arguments over/underflows will
8220ec5a
MK
85occur inside the \fIlgamma\fP routine.
86.SH SEE ALSO
87math(3M), infnan(3M)