Class FactorialDouble

java.lang.Object
org.apache.commons.numbers.combinatorics.FactorialDouble

public class FactorialDouble
extends java.lang.Object
Class for computing the natural logarithm of the factorial of a number. It allows to allocate a cache of precomputed values.
  • Method Summary

    Modifier and Type Method Description
    static FactorialDouble create()
    Creates an instance with no precomputed values.
    double value​(int n)
    Computes the factorial of n.
    FactorialDouble withCache​(int cacheSize)
    Creates an instance with the specified cache size.

    Methods inherited from class java.lang.Object

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

    • create

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

      public FactorialDouble 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 cacheSize < 0.
    • value

      public double value​(int n)
      Computes the factorial of n. The result should be small enough to fit into a double: The largest n for which n! does not exceed Double.MAX_VALUE is 170. Double.POSITIVE_INFINITY is returned for n > 170.
      Parameters:
      n - Argument.
      Returns:
      n!
      Throws:
      java.lang.IllegalArgumentException - if n < 0.