- n (Int32)
- The argument, which must be non-negative.
The factorial of an integer n is the product of all integers from 1 to n. For example, 4! = 4 * 3 * 2 * 1 = 24.
n! also has a combinatorial intrepretation as the number of permutations of n objects. For example, a set of 3 objects (abc) has 3! = 6 permutations: (abc), (bac), (cba), (acb), (cab), (bca).
Because n! grows extremely quickly with increasing n, we return the result as a double, even though the value is always an integer. (13! would overlow an int. 21! would overflow a long. 171! overflows even a double.)
In order to deal with factorials of larger runbers, you can use the LogFactorial(Int32) method, which returns accurate values of ln(n!) even for values of n for which n! would overflow a double.
The factorial is generalized to non-integer arguments by the Γ function (Gamma(Double)).
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | n is negative. |