Class InternalGamma
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.InternalGamma
-
final class InternalGamma extends java.lang.Object
Adapted and stripped down copy of class
"org.apache.commons.math4.special.Gamma"
.This is a utility class that provides computation methods related to the Γ (Gamma) family of functions.
-
-
Field Summary
Fields Modifier and Type Field Description private static double
HALF_LOG_2_PI
Avoid repeated computation of log of 2 PI in logGamma.private static double[]
LANCZOS_COEFFICIENTS
Lanczos coefficients.static double
LANCZOS_G
Constant \( g = \frac{607}{128} \) in the Lanczos approximation.
-
Constructor Summary
Constructors Modifier Constructor Description private
InternalGamma()
Class contains only static methods.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static double
lanczos(double x)
Computes the Lanczos approximation used to compute the gamma function.static double
logGamma(double x)
Computes the function \( \ln \Gamma(x) \) for \( x > 0 \).
-
-
-
Field Detail
-
LANCZOS_G
public static final double LANCZOS_G
Constant \( g = \frac{607}{128} \) in the Lanczos approximation.- See Also:
- Constant Field Values
-
LANCZOS_COEFFICIENTS
private static final double[] LANCZOS_COEFFICIENTS
Lanczos coefficients.
-
HALF_LOG_2_PI
private static final double HALF_LOG_2_PI
Avoid repeated computation of log of 2 PI in logGamma.
-
-
Method Detail
-
logGamma
public static double logGamma(double x)
Computes the function \( \ln \Gamma(x) \) for \( x > 0 \).For \( x \leq 8 \), the implementation is based on the double precision implementation in the NSWC Library of Mathematics Subroutines,
DGAMLN
. For \( x \geq 8 \), the implementation is based on- Gamma Function, equation (28).
- Lanczos Approximation, equations (1) through (5).
- Paul Godfrey, A note on the computation of the convergent Lanczos complex Gamma approximation
- Parameters:
x
- Argument.- Returns:
- \( \ln \Gamma(x) \), or
NaN
ifx <= 0
.
-
lanczos
private static double lanczos(double x)
Computes the Lanczos approximation used to compute the gamma function.The Lanczos approximation is related to the Gamma function by the following equation \[ \Gamma(x) = \sqrt{2\pi} \, \frac{(g + x + \frac{1}{2})^{x + \frac{1}{2}} \, e^{-(g + x + \frac{1}{2})} \, \mathrm{lanczos}(x)} {x} \] where \(g\) is the Lanczos constant.
- Parameters:
x
- Argument.- Returns:
- The Lanczos approximation.
- See Also:
- Lanczos Approximation equations (1) through (5), and Paul Godfrey's Note on the computation of the convergent Lanczos complex Gamma approximation
-
-