![]() |
![]()
| ![]() |
![]()
NAMExt_factorial() - Fast factorial function LIBRARY#include <inttypes.h> #include <xtend/math.h> -lxtend SYNOPSISuint64_t xt_factorial(unsigned n) ARGUMENTSn Integer in the range [0,20] (inclusive) for which n! is returned. DESCRIPTIONInstantaneous 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 VALUESn! if n is an element of [0,20], 0 otherwise EXAMPLES#include <inttypes.h> #include <xtend/math.h> printf("20! = %" PRIu64 "n", factorial(20)); FILESEnvironment SEE ALSO
|