Class Factorial
- java.lang.Object
-
- org.apache.commons.numbers.combinatorics.Factorial
-
public final class Factorial extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static double[]DOUBLE_FACTORIALSAll factorials that can be represented as a double (values up to 170!).(package private) static long[]FACTORIALSAll long-representable factorials.
-
Constructor Summary
Constructors Modifier Constructor Description privateFactorial()Private constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doubledoubleValue(int n)Computes the factorial ofn.(package private) static doubleuncheckedFactorial(int n)Return the factorial ofn.static longvalue(int n)Computes the factorial ofn.
-
-
-
Method Detail
-
value
public static long value(int n)
Computes the factorial ofn.- Parameters:
n- Argument.- Returns:
n!- Throws:
java.lang.IllegalArgumentException- ifn < 0.java.lang.IllegalArgumentException- ifn > 20(the factorial value is too large to fit in along).
-
doubleValue
public static double doubleValue(int n)
Computes the factorial ofn.The result should be small enough to fit into a
double: The largestnfor whichn!does not exceedDouble.MAX_VALUEis 170.Double.POSITIVE_INFINITYis returned forn > 170.- Parameters:
n- Argument.- Returns:
n!- Throws:
java.lang.IllegalArgumentException- ifn < 0.- Since:
- 1.1
-
uncheckedFactorial
static double uncheckedFactorial(int n)
Return the factorial ofn.Note: This is an internal method that exposes the tabulated factorials that can be represented as a double. No checks are performed on the argument.
- Parameters:
n- Argument (must be in [0, 170])- Returns:
- n!
-
-