s14ab returns the value of the logarithm of the gamma function, lnΓx.

Syntax

C#
public static double s14ab(
	double x,
	out int ifail
)
Visual Basic
Public Shared Function s14ab ( _
	x As Double, _
	<OutAttribute> ByRef ifail As Integer _
) As Double
Visual C++
public:
static double s14ab(
	double x, 
	[OutAttribute] int% ifail
)
F#
static member s14ab : 
        x : float * 
        ifail : int byref -> float 

Parameters

x
Type: System..::..Double
On entry: the argument x of the function.
Constraint: x>0.0.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Return Value

s14ab returns the value of the logarithm of the gamma function, lnΓx.

Description

s14ab calculates an approximate value for lnΓx. It is based on rational Chebyshev expansions.
Denote by Rn,mix=Pnix/Qmix a ratio of polynomials of degree n in the numerator and m in the denominator. Then:
  • for 0<x1/2,
    lnΓx-lnx+xRn,m1x+1;
  • for 1/2<x3/2,
    lnΓxx-1Rn,m1x;
  • for 3/2<x4,
    lnΓxx-2Rn,m2x;
  • for 4<x12,
    lnΓxRn,m3x;
  • and for 12<x,
    lnΓxx-12lnx-x+ln2π+1xRn,m41/x2. (1)
For each expansion, the specific values of n and m are selected to be minimal such that the maximum relative error in the expansion is of the order 10-d, where d is the maximum number of decimal digits that can be accurately represented for the particular implementation (see x02be).
Let ε denote machine precision and let xhuge denote the largest positive model number (see x02al). For x<0.0 the value lnΓx is not defined; s14ab returns zero and exits with ifail=1. It also exits with ifail=1 when x=0.0, and in this case the value xhuge is returned. For x in the interval 0.0,ε, the function lnΓx=-lnx to machine accuracy.
Now denote by xbig the largest allowable argument for lnΓx on the machine. For xbig1/4<xxbig the Rn,m41/x2 term in Equation (1) is negligible. For x>xbig there is a danger of setting overflow, and so s14ab exits with ifail=2 and returns xhuge. The value of xbig is given in the Users' Note for your implementation.

References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Cody W J and Hillstrom K E (1967) Chebyshev approximations for the natural logarithm of the gamma function Math.Comp. 21 198–203

Error Indicators and Warnings

Errors or warnings detected by the method:
ifail=1
On entry, x0.0. If x<0.0 the function is undefined; on failure, the function value returned is zero. If x=0.0 and failure is selected, the function value returned is the largest machine number (see x02al).
ifail=2
On entry, x>xbig (see [Description]). On failure, the function value returned is the largest machine number (see x02al).
ifail=-9000
An error occured, see message report.

Accuracy

Let δ and ε be the relative errors in the argument and result respectively, and E be the absolute error in the result.
If δ is somewhat larger than machine precision, then
Ex×Ψxδ  and  εx×ΨxlnΓxδ
where Ψx is the digamma function ΓxΓx. Figure 1 and Figure 2 show the behaviour of these error amplification factors.
Figure 1
Figure 1
Figure 2
Figure 2
These show that relative error can be controlled, since except near x=1​ or ​2 relative error is attenuated by the function or at least is not greatly amplified.
For large x, ε1+1lnxδ and for small x, ε1lnxδ.
The function lnΓx has zeros at x=1 and 2 and hence relative accuracy is not maintainable near those points. However absolute accuracy can still be provided near those zeros as is shown above.
If however, δ is of the order of machine precision, then rounding errors in the method's internal arithmetic may result in errors which are slightly larger than those predicted by the equalities. It should be noted that even in areas where strong attenuation of errors is predicted the relative precision is bounded by the effective machine precision.

Parallelism and Performance

None.

Further Comments

None.

Example

This example reads values of the argument x from a file, evaluates the function at each value of x and prints the results.

Example program (C#): s14abe.cs

Example program data: s14abe.d

Example program results: s14abe.r

See Also