Invert GMLscripts.com

factorial

Computes and returns the factorial \(n!\) for a given number \(n\).

$$n! = n \times (n-1) \times \cdots \times 1$$

NOTE: \(18!\) is the largest factorial GameMaker can precisely compute. It may appear to produce correct results up to \(22!\) but computations using them are dubious and precision decreases as they get larger.

factorial(number)
Returns the factorial of a given number.
COPY/// @func   factorial(number)
///
/// @desc   Returns the factorial of a given number. Numbers
///         larger than 18 produce inaccruate results due to
///         floating-point precision limitations.
///
/// @param  {real}      number      non-negative integer
///
/// @return {real}      factorial of given number
///
/// GMLscripts.com/license

function factorial(number)
{
    if (number <= 1) return 1;
    return number * factorial(number - 1);
}

Contributors: xot

GitHub: View · Commits · Blame · Raw