Click or drag to resize

AdvancedIntegerMathFactorial Method

Computes the factorial of an integer.

Namespace:  Meta.Numerics.Functions
Assembly:  Meta.Numerics (in Meta.Numerics.dll) Version: 4.1.4
public static double Factorial(
	int n


Type: SystemInt32
The argument, which must be non-negative.

Return Value

Type: Double
The value of n!.
ArgumentOutOfRangeExceptionn is 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 interpretation 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 overflow an int, 21! would overflow a long, 171! overflows even a double.)

In order to deal with factorials of larger numbers, 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)).

See Also