Class Factorial
java.lang.Object
org.apache.commons.numbers.combinatorics.Factorial
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double[]
All factorials that can be represented as a double (values up to 170!).(package private) static final long[]
All long-representable factorials. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double
doubleValue
(int n) Computes the factorial ofn
.(package private) static double
uncheckedFactorial
(int n) Return the factorial ofn
.static long
value
(int n) Computes the factorial ofn
.
-
Field Details
-
FACTORIALS
static final long[] FACTORIALSAll long-representable factorials. -
DOUBLE_FACTORIALS
private static final double[] DOUBLE_FACTORIALSAll factorials that can be represented as a double (values up to 170!).
-
-
Constructor Details
-
Factorial
private Factorial()Private constructor.
-
-
Method Details
-
value
public static long value(int n) Computes the factorial ofn
.- Parameters:
n
- Argument.- Returns:
n!
- Throws:
IllegalArgumentException
- ifn < 0
.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 largestn
for whichn!
does not exceedDouble.MAX_VALUE
is 170.Double.POSITIVE_INFINITY
is returned forn > 170
.- Parameters:
n
- Argument.- Returns:
n!
- Throws:
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!
-