in commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/InternalUtils.java [289:312]
private FactorialLog(int numValues,
double[] cache) {
logFactorials = new double[numValues];
final int endCopy;
if (cache != null && cache.length > BEGIN_LOG_FACTORIALS) {
// Copy available values.
endCopy = Math.min(cache.length, numValues);
System.arraycopy(cache, BEGIN_LOG_FACTORIALS, logFactorials, BEGIN_LOG_FACTORIALS,
endCopy - BEGIN_LOG_FACTORIALS);
} else {
// All values to be computed
endCopy = BEGIN_LOG_FACTORIALS;
}
// Compute remaining values.
for (int i = endCopy; i < numValues; i++) {
if (i < LOG_FACTORIALS.length) {
logFactorials[i] = LOG_FACTORIALS[i];
} else {
logFactorials[i] = logFactorials[i - 1] + Math.log(i);
}
}
}