Class LongFactorialEstimator

java.lang.Object
com.irurueta.numerical.LongFactorialEstimator

public class LongFactorialEstimator extends Object
Estimates factorial values as long integer values.
  • Field Details

    • CACHE_SIZE

      public static final int CACHE_SIZE
      Cache size for factorial values that can be represented without overflowing with long precision. Values up to 20! are representable, 21! overflows.
      See Also:
    • cache

      private final long[] cache
      Cache of values.
  • Constructor Details

    • LongFactorialEstimator

      public LongFactorialEstimator()
      Constructor with default cache size.
    • LongFactorialEstimator

      public LongFactorialEstimator(int cacheSize)
      Constructor.
      Parameters:
      cacheSize - size of cache.
      Throws:
      IllegalArgumentException - if provided value is less than 1 or exceeds 21.
  • Method Details

    • getCacheSize

      public int getCacheSize()
      Gets current cache size.
      Returns:
      cache size.
    • factorial

      public long factorial(int value)
      Gets factorial of provided value represented with double precision.
      Parameters:
      value - value to compute factorial for.
      Returns:
      computed factorial value.
      Throws:
      IllegalArgumentException - if provided value exceeds cache size.