Class BinomialCoefficientDouble
java.lang.Object
org.apache.commons.numbers.combinatorics.BinomialCoefficientDouble
Representation of the
binomial coefficient, as a
double
.
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 int
The maximum n that can be computed without overflow of a long for any m.private static final int
The maximum factorial that can be represented as a double.private static final int
The maximum m that can be computed without overflow of a double.private static final int
The maximum m that can be computed without intermediate overflow for any n.private static final int
The maximum n that can be computed without intermediate overflow for any m. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double
value
(int n, int k) Computes the binomial coefficient.
-
Field Details
-
MAX_FACTORIAL
private static final int MAX_FACTORIALThe maximum factorial that can be represented as a double.- See Also:
-
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:
-
MAX_M
private static final int MAX_MThe maximum m that can be computed without overflow of a double. C(1030, 515) ~ 2.85e308.- See Also:
-
SMALL_N
private static final int SMALL_NThe maximum n that can be computed without intermediate overflow for any m. C(1020, 510) * 510 ~ 1.43e308.- See Also:
-
SMALL_M
private static final int SMALL_MThe maximum m that can be computed without intermediate overflow for any n. C(2147483647, 37) * 37 ~ 5.13e303.- See Also:
-
-
Constructor Details
-
BinomialCoefficientDouble
private BinomialCoefficientDouble()Private constructor.
-
-
Method Details
-
value
public static double value(int n, int k) Computes the binomial coefficient.The largest value of
n
for which all coefficients can fit into adouble
is 1029. Largern
may result in infinity depending on the value ofk
.Any
min(k, n - k) >= 515
cannot fit into adouble
and will result in infinity.- Parameters:
n
- Size of the set.k
- Size of the subsets to be counted.- Returns:
n choose k
.- Throws:
IllegalArgumentException
- ifn < 0
,k < 0
ork > n
.
-