Package com.irurueta.numerical
Class LongFactorialEstimator
java.lang.Object
com.irurueta.numerical.LongFactorialEstimator
Estimates factorial values as long integer values.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final long[]
Cache of values.static final int
Cache size for factorial values that can be represented without overflowing with long precision. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with default cache size.LongFactorialEstimator
(int cacheSize) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionlong
factorial
(int value) Gets factorial of provided value represented with double precision.int
Gets current cache size.
-
Field Details
-
CACHE_SIZE
public static final int CACHE_SIZECache 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[] cacheCache 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.
-