Class InternalGamma
java.lang.Object
org.apache.commons.rng.sampling.distribution.InternalGamma
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
FieldsModifier and TypeFieldDescriptionprivate static final double
Avoid repeated computation of log of 2 PI in logGamma.private static final double[]
Lanczos coefficients.static final double
Constant \( g = \frac{607}{128} \) in the Lanczos approximation. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
LANCZOS_G
public static final double LANCZOS_GConstant \( g = \frac{607}{128} \) in the Lanczos approximation.- See Also:
-
LANCZOS_COEFFICIENTS
private static final double[] LANCZOS_COEFFICIENTSLanczos coefficients. -
HALF_LOG_2_PI
private static final double HALF_LOG_2_PIAvoid repeated computation of log of 2 PI in logGamma.
-
-
Constructor Details
-
InternalGamma
private InternalGamma()Class contains only static methods.
-
-
Method Details
-
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:
-