Skip to content
Snippets Groups Projects
Commit dc83192e authored by SANTAGOSTINI Pierre's avatar SANTAGOSTINI Pierre
Browse files

logarithm of the factorial

parent ab3899ae
No related branches found
No related tags found
No related merge requests found
lnfactorial <- function(n) {
#' Logarithm of the factorial
#'
#' Computes the logarithm of the factorial of a positive integer.
#'
#' @aliases lnfactorial
#'
#' @usage lnfactorial(n)
#' @param n positive integer.
#' @return Numeric value. The logarithm of the factorial.
#' @author Pierre Santagostini, Nizar Bouhlel
#'
#' @export
if (n < 0) {
stop("n must be non negative")
}
if (n == 0) {
return(0)
}
if (n > 0) {
return(sum(log(1:n)))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment