/** * Returns n!. Shorthand for <code>n</code> <a * href="http://mathworld.wolfram.com/Factorial.html"> Factorial</a>, the * product of the numbers <code>1,...,n</code> as a <code>double</code>. * <p> * <Strong>Preconditions</strong>: * <ul> * <li> <code>n >= 0</code> (otherwise * <code>IllegalArgumentException</code> is thrown)</li> * <li> The result is small enough to fit into a <code>double</code>. The * largest value of <code>n</code> for which <code>n!</code> < * Double.MAX_VALUE</code> is 170. If the computed value exceeds * Double.MAX_VALUE, Double.POSITIVE_INFINITY is returned</li> * </ul> * </p> * * @param n argument * @return <code>n!</code> * @throws IllegalArgumentException if n < 0 */ public static double factorialDouble(final int n) { if (n < 0) { throw new IllegalArgumentException("must have n >= 0 for n!"); } return Math.floor(Math.exp(factorialLog(n)) + 0.5); }
/** * Returns n!. Shorthand for <code>n</code> <a * href="http://mathworld.wolfram.com/Factorial.html"> Factorial</a>, the * product of the numbers <code>1,...,n</code> as a <code>double</code>. * <p> * <Strong>Preconditions</strong>: * <ul> * <li> <code>n >= 0</code> (otherwise * <code>IllegalArgumentException</code> is thrown)</li> * <li> The result is small enough to fit into a <code>double</code>. The * largest value of <code>n</code> for which <code>n!</code> < * Double.MAX_VALUE</code> is 170. If the computed value exceeds * Double.MAX_VALUE, Double.POSITIVE_INFINITY is returned</li> * </ul> * </p> * * @param n argument * @return <code>n!</code> * @throws IllegalArgumentException if n < 0 */ public static double factorialDouble(final int n) { if (n < 0) { throw new IllegalArgumentException("must have n >= 0 for n!"); } return Math.floor(Math.exp(factorialLog(n)) + 0.5); }
return factorial(n); return Math.floor(Math.exp(factorialLog(n)) + 0.5);
final double lambdaFractional = mean - lambda; final double logLambda = Math.log(lambda); final double logLambdaFactorial = MathUtils.factorialLog((int) lambda); final long y2 = lambdaFractional < Double.MIN_VALUE ? 0 : nextPoisson(lambdaFractional); final double delta = Math.sqrt(lambda * Math.log(32 * lambda / Math.PI + 1)); continue; if (v < y * logLambda - MathUtils.factorialLog((int) (y + lambda)) + logLambdaFactorial) { y = lambda + y; break;
return factorial(n); return FastMath.floor(FastMath.exp(factorialLog(n)) + 0.5);
final double lambdaFractional = mean - lambda; final double logLambda = FastMath.log(lambda); final double logLambdaFactorial = MathUtils.factorialLog((int) lambda); final long y2 = lambdaFractional < Double.MIN_VALUE ? 0 : nextPoisson(lambdaFractional); final double delta = FastMath.sqrt(lambda * FastMath.log(32 * lambda / FastMath.PI + 1)); continue; if (v < y * logLambda - MathUtils.factorialLog((int) (y + lambda)) + logLambdaFactorial) { y = lambda + y; break;