Class LogBinomialCoefficient
java.lang.Object
org.apache.commons.numbers.combinatorics.LogBinomialCoefficient
Natural logarithm of the
binomial coefficient.
It is "
n choose k", the number of k-element subsets that
can be selected from an n-element set.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intThe maximum m that can be computed without overflow of a double for any n.private static final intThe maximum n that can be computed without overflow of a double for an m.private static final intThe maximum n that can be computed without overflow of a long for any m. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublevalue(int n, int k) Computes the logarithm of the binomial coefficient.
-
Field Details
-
LIMIT_N_LONG
private static final int LIMIT_N_LONGThe maximum n that can be computed without overflow of a long for any m.C(66, 33) < 2^63.- See Also:
-
LIMIT_N_DOUBLE
private static final int LIMIT_N_DOUBLEThe maximum n that can be computed without overflow of a double for an m. C(1029, 514) ~ 1.43e308.- See Also:
-
LIMIT_M_DOUBLE
private static final int LIMIT_M_DOUBLEThe maximum m that can be computed without overflow of a double for any n. C(2147483647, 37) ~ 1.39e302.- See Also:
-
-
Constructor Details
-
LogBinomialCoefficient
private LogBinomialCoefficient()Private constructor.
-
-
Method Details
-
value
public static double value(int n, int k) Computes the logarithm of the binomial coefficient.This returns a finite result for any valid
n choose k.- Parameters:
n- Size of the set.k- Size of the subsets to be counted.- Returns:
log(n choose k).- Throws:
IllegalArgumentException- ifn < 0,k < 0ork > n.
-