Android Binomial Coefficient checkBinomial(final int n, final int k)

Here you can find the source of checkBinomial(final int n, final int k)

Description

Check binomial preconditions.

License

Apache License

Parameter

Parameter Description
n Size of the set.
k Size of the subsets to be counted.

Exception

Parameter Description
NotPositiveException if n < 0.
NumberIsTooLargeException if k > n.

Declaration

private static void checkBinomial(final int n, final int k)
        throws NumberIsTooLargeException, NotPositiveException 

Method Source Code

/*//w ww .j a  v  a  2 s  .  c  o  m
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.math.BigInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.math3.exception.MathArithmeticException;
import org.apache.commons.math3.exception.NotPositiveException;
import org.apache.commons.math3.exception.NumberIsTooLargeException;
import org.apache.commons.math3.exception.util.Localizable;
import org.apache.commons.math3.exception.util.LocalizedFormats;

public class Main{
    /**
     * Check binomial preconditions.
     *
     * @param n Size of the set.
     * @param k Size of the subsets to be counted.
     * @throws NotPositiveException if {@code n < 0}.
     * @throws NumberIsTooLargeException if {@code k > n}.
     */
    private static void checkBinomial(final int n, final int k)
            throws NumberIsTooLargeException, NotPositiveException {
        if (n < k) {
            throw new NumberIsTooLargeException(
                    LocalizedFormats.BINOMIAL_INVALID_PARAMETERS_ORDER, k,
                    n, true);
        }
        if (n < 0) {
            throw new NotPositiveException(
                    LocalizedFormats.BINOMIAL_NEGATIVE_PARAMETER, n);
        }
    }
}

Related

  1. binomialCoefficient(final int n, final int k)
  2. binomialCoefficientDouble(final int n, final int k)
  3. binomialCoefficientLog(final int n, final int k)