Class BinomialCoefficientDouble


  • public final class BinomialCoefficientDouble
    extends java.lang.Object
    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

      Fields 
      Modifier and Type Field Description
      private static int LIMIT_N_LONG
      The maximum n that can be computed without overflow of a long for any m.
      private static int MAX_FACTORIAL
      The maximum factorial that can be represented as a double.
      private static int MAX_M
      The maximum m that can be computed without overflow of a double.
      private static int SMALL_M
      The maximum m that can be computed without intermediate overflow for any n.
      private static int SMALL_N
      The maximum n that can be computed without intermediate overflow for any m.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double value​(int n, int k)
      Computes the binomial coefficient.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAX_FACTORIAL

        private static final int MAX_FACTORIAL
        The maximum factorial that can be represented as a double.
        See Also:
        Constant Field Values
      • LIMIT_N_LONG

        private static final int LIMIT_N_LONG
        The maximum n that can be computed without overflow of a long for any m. C(66, 33) < 2^63.
        See Also:
        Constant Field Values
      • MAX_M

        private static final int MAX_M
        The maximum m that can be computed without overflow of a double. C(1030, 515) ~ 2.85e308.
        See Also:
        Constant Field Values
      • SMALL_N

        private static final int SMALL_N
        The maximum n that can be computed without intermediate overflow for any m. C(1020, 510) * 510 ~ 1.43e308.
        See Also:
        Constant Field Values
      • SMALL_M

        private static final int SMALL_M
        The maximum m that can be computed without intermediate overflow for any n. C(2147483647, 37) * 37 ~ 5.13e303.
        See Also:
        Constant Field Values
    • Constructor Detail

      • BinomialCoefficientDouble

        private BinomialCoefficientDouble()
        Private constructor.
    • Method Detail

      • 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 a double is 1029. Larger n may result in infinity depending on the value of k.

        Any min(k, n - k) >= 515 cannot fit into a double and will result in infinity.

        Parameters:
        n - Size of the set.
        k - Size of the subsets to be counted.
        Returns:
        n choose k.
        Throws:
        java.lang.IllegalArgumentException - if n < 0, k < 0 or k > n.