С использованием Apache Commons Math 3 :
import org.apache.commons.math3.special.Gamma;
/**
* Binomial coefficient for real numbers - the number of ways of picking y
* unordered outcomes from x possibilities
*
* @see http://mathworld.wolfram.com/BinomialCoefficient.html
*
* @param x
* @param y
* @return binomial coefficient to be generalized to noninteger arguments
*/
public double binomial(double x, double y) {
double res = Gamma.gamma(x + 1) / (Gamma.gamma(y + 1) * Gamma.gamma(x - y + 1));
if(Double.isNaN(res)){
return 0.0;
}
return res;
}
Так что для ввода binomial(0.5, 1.0)
вы должны получить 0.5
, как в Wolfram Alpha
binomial(2.5, 3) = 0.3125
binomial(2.0, 3) = 0.0
binomial(1.5, 3) = -0.0625