I can't calculate the factorial of 365 by using factorial(365)
with the R logial, I think the capacity of this logicial don't allow it. How can I do with an other method?
You can use lgamma(x+1)
to get the natural log of factorial.
factorial(365)
# [1] Inf
# Warning message:
# In factorial(365) : value out of range in 'gammafn'
lgamma(366)
# 1792.332
# convince yourself that this works:
x <- 2:10
format(factorial(x), scientific = FALSE) == format(exp(lgamma(x + 1)), scientific = FALSE)
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
floating point math can get you into trouble at times, but lgamma(366)
is accurate for ln(factorial(365))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With