Class InternalGamma

java.lang.Object
org.apache.commons.rng.sampling.distribution.InternalGamma

final class InternalGamma extends 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 final double
    Avoid repeated computation of log(2*PI) / 2 in logGamma.
    private static final double[]
    Lanczos coefficients.
    static final double
    Constant \( g = \frac{607}{128} \) in the Lanczos approximation.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Class contains only static methods.
  • Method Summary

    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 \gt 0 \).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LANCZOS_G

      public static final double LANCZOS_G
      Constant \( g = \frac{607}{128} \) in the Lanczos approximation.
      See Also:
    • 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(2*PI) / 2 in logGamma.
      See Also:
  • 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 \gt 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

      Parameters:
      x - Argument.
      Returns:
      \( \ln \Gamma(x) \), or NaN if x <= 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: