xt_factorial(3)

NAME
xt_factorial() - Fast factorial function

LIBRARY
#include <inttypes.h>
#include <xtend/math.h>
-lxtend

SYNOPSIS
uint64_t    xt_factorial(unsigned n)

ARGUMENTS
n   Integer in the range [0,20] (inclusive) for which n! is returned.

DESCRIPTION
Instantaneous factorial for n in [0,20] using a lookup table. Note that 21! is beyond the range of uint64_t, so programs that need it should either use a multiple precision library or rearrange the computations to avoid repeated multiplication leading to overflow. xt_n_choose_k(3) uses the latter approach to avoid computing whole factorials before finally dividing.

RETURN VALUES
n! if n is an element of [0,20], 0 otherwise

EXAMPLES
#include <inttypes.h>
#include <xtend/math.h>
printf("20! = %" PRIu64 "n", factorial(20));

FILES
Environment

SEE ALSO