1*49230Scael.\" Copyright (c) 1985, 1991 Regents of the University of California. 248378Scael.\" All rights reserved. 324694Smckusick.\" 4*49230Scael.\" %sccs.include.redist.roff% 524694Smckusick.\" 6*49230Scael.\" @(#)lgamma.3 6.4 (Berkeley) 05/06/91 748378Scael.\" 8*49230Scael.Dd 9*49230Scael.Dt LGAMMA 3 10*49230Scael.Os BSD 4.3 11*49230Scael.Sh NAME 12*49230Scael.Nm lgamma 13*49230Scael.Nd log gamma function 14*49230Scael.Sh SYNOPSIS 15*49230Scael.Fd #include <math.h> 16*49230Scael.Ft double 17*49230Scael.Fn lgamma "double x" 18*49230Scael.Sh DESCRIPTION 1924694Smckusick.ta \w'Lgamma returns ln\||\(*G(x)| where'u+1n +1.7i 2024694Smckusick.if t \{\ 21*49230ScaelLgamma returns ln\||\(*G(x)| where 22*49230Scael.Bd -unfilled -offset indent 23*49230Scael\(*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 2424694Smckusick.br 25*49230Scael\(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px)) for x < 1. \} 26*49230Scael.Ed 2724694Smckusick.if n \ 2824694SmckusickLgamma returns ln\||\(*G(x)|. 2924694Smckusick.ta 30*49230Scael.Pp 31*49230ScaelThe external integer 32*49230Scael.Fa signgam 33*49230Scaelreturns the sign of 3424694Smckusick\(*G(x) . 35*49230Scael.Sh IDIOSYNCRASIES 36*49230ScaelDo 37*49230Scael.Em not 38*49230Scaeluse the expression 39*49230Scael.Dq Li signgam\(**exp(lgamma(x)) 4024694Smckusickto compute g := \(*G(x). Instead use a program like this (in C): 41*49230Scael.Bd -literal -offset indent 4224694Smckusicklg = lgamma(x); g = signgam\(**exp(lg); 43*49230Scael.Ed 44*49230Scael.Pp 45*49230ScaelOnly after 46*49230Scael.Fn lgamma 47*49230Scaelhas returned can signgam be correct. 4824694SmckusickNote too that \(*G(x) must overflow when x is large enough, 4924694Smckusickunderflow when \-x is large enough, and spawn a division by zero 5024694Smckusickwhen x is a nonpositive integer. 51*49230Scael.Pp 52*49230ScaelOnly in the 53*49230Scael.Tn UNIX 54*49230Scaelmath library for C was the name gamma ever attached 55*49230Scaelto ln\(*G. Elsewhere, for instance in 56*49230Scael.Tn IBM Ns 's 57*49230Scael.Tn FORTRAN 58*49230Scaellibrary, the name 59*49230Scael.Tn GAMMA 60*49230Scaelbelongs to \(*G and the name 61*49230Scael.Tn ALGAMA 62*49230Scaelto ln\(*G in single precision; 63*49230Scaelin double the names are 64*49230Scael.Tn DGAMMA 65*49230Scaeland 66*49230Scael.Tn DLGAMA . 67*49230ScaelWhy should C be different? 68*49230Scael.Pp 69*49230ScaelArchaeological records suggest that C's 70*49230Scael.Em gamma 71*49230Scaeloriginally delivered 7224694Smckusickln(\(*G(|x|)). Later, the program gamma was changed to 7324694Smckusickcope with negative arguments x in a more conventional way, but 7424694Smckusickthe documentation did not reflect that change correctly. The most 7524694Smckusickrecent change corrects inaccurate values when x is almost a 7624694Smckusicknegative integer, and lets \(*G(x) be computed without 7724694Smckusickconditional expressions. Programmers should not assume that 78*49230Scael.Fn lgamma 79*49230Scaelhas settled down. 80*49230Scael.Pp 81*49230ScaelAt some time in the future, the name 82*49230Scael.Em gamma 83*49230Scaelwill be rehabilitated 84*49230Scaeland used for the gamma function, just as is done in 85*49230Scael.Tn FORTRAN . 86*49230ScaelThe reason for this is not so much compatibility with 87*49230Scael.Tn FORTRAN 88*49230Scaelas a 8924694Smckusickdesire to achieve greater speed for smaller values of |x| and greater 9024694Smckusickaccuracy for larger values. 91*49230Scael.Pp 92*49230ScaelMeanwhile, programmers who have to use the name 93*49230Scael.Em gamma 94*49230Scaelin its former 95*49230Scaelsense, for what is now 96*49230Scael.Fn lgamma , 97*49230Scaelhave two choices: 98*49230Scael.Bl -enum -width indent 99*49230Scael.It 100*49230ScaelUse the old math library, 101*49230Scael.Pa libom . 102*49230Scael.It 10324694SmckusickAdd the following program to your others: 104*49230Scael.Bd -literal -offset indent 105*49230Scael#include <math.h> 10624694Smckusickdouble gamma(x) 10724694Smckusickdouble x; 10824694Smckusick{ 109*49230Scael return (lgamma(x)); 110*49230Scael} 111*49230Scael.Ed 112*49230Scael.Sh DIAGNOSTICS 113*49230ScaelThe reserved operand is returned on a 114*49230Scael.Tn VAX 115*49230Scaelfor negative integer arguments, 116*49230Scael.Va errno 117*49230Scaelis set to 118*49230Scael.Er ERANGE ; 119*49230Scaelfor very large arguments over/underflows will 120*49230Scaeloccur inside the 121*49230Scael.Fn lgamma 122*49230Scaelroutine. 123*49230Scael.Sh SEE ALSO 124*49230Scael.Xr math 3 , 125*49230Scael.Xr infnan 3 126*49230Scael.Sh HISTORY 127*49230ScaelThe 128*49230Scael.Nm 129*49230Scaelfunction appeared in 130*49230Scael.Bx 4.3 . 131