Class InternalUtils.FactorialLog

  • Enclosing class:
    InternalUtils

    public static final class InternalUtils.FactorialLog
    extends java.lang.Object
    Class for computing the natural logarithm of the factorial of n. It allows to allocate a cache of precomputed values. In case of cache miss, computation is performed by a call to InternalGamma.logGamma(double).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double[] logFactorials
      Precomputed values of the function: LOG_FACTORIALS[i] = log(i!).
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private FactorialLog​(int numValues, double[] cache)
      Creates an instance, reusing the already computed values if available.
    • Field Detail

      • logFactorials

        private final double[] logFactorials
        Precomputed values of the function: LOG_FACTORIALS[i] = log(i!).
    • Constructor Detail

      • FactorialLog

        private FactorialLog​(int numValues,
                             double[] cache)
        Creates an instance, reusing the already computed values if available.
        Parameters:
        numValues - Number of values of the function to compute.
        cache - Existing cache.
        Throws:
        java.lang.NegativeArraySizeException - if numValues < 0.
    • Method Detail

      • create

        public static InternalUtils.FactorialLog create()
        Creates an instance with no precomputed values.
        Returns:
        an instance with no precomputed values.
      • withCache

        public InternalUtils.FactorialLog withCache​(int cacheSize)
        Creates an instance with the specified cache size.
        Parameters:
        cacheSize - Number of precomputed values of the function.
        Returns:
        a new instance where cacheSize values have been precomputed.
        Throws:
        java.lang.IllegalArgumentException - if n < 0.
      • value

        public double value​(int n)
        Computes log(n!).
        Parameters:
        n - Argument.
        Returns:
        log(n!).
        Throws:
        java.lang.IndexOutOfBoundsException - if numValues < 0.