Class LogFactorial
java.lang.Object
org.apache.commons.numbers.combinatorics.LogFactorial
Class for computing the natural logarithm of the factorial of a number.
It allows to allocate a cache of precomputed values.
In case of cache miss, computation is performed by a call to
LogGamma.value(double).-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intSize of precomputed factorials.private final double[]Precomputed values of the function:logFactorials[i] = Math.log(i!). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateLogFactorial(int numValues, double[] cache) Creates an instance, reusing the already computed values if available. -
Method Summary
Modifier and TypeMethodDescriptionstatic LogFactorialcreate()Creates an instance with no precomputed values.doublevalue(int n) Computes \( log_e(n!) \).withCache(int cacheSize) Creates an instance with the specified cache size.
-
Field Details
-
FACTORIALS_CACHE_SIZE
private static final int FACTORIALS_CACHE_SIZESize of precomputed factorials.- See Also:
-
logFactorials
private final double[] logFactorialsPrecomputed values of the function:logFactorials[i] = Math.log(i!).
-
-
Constructor Details
-
LogFactorial
private LogFactorial(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- Cached values.- Throws:
IllegalArgumentException- ifn < 0.
-
-
Method Details
-
create
Creates an instance with no precomputed values.- Returns:
- instance with no precomputed values
-
withCache
Creates an instance with the specified cache size.- Parameters:
cacheSize- Number of precomputed values of the function.- Returns:
- a new instance where
cacheSizevalues have been precomputed. - Throws:
IllegalArgumentException- ifcacheSize < 0.
-
value
public double value(int n) Computes \( log_e(n!) \).- Parameters:
n- Argument.- Returns:
log(n!).- Throws:
IllegalArgumentException- ifn < 0.
-