n <= 170<="" code="">.
fact(n)
n
. If n < 0
the
value is NaN
, and for n > 170
it is Inf
.
Non-integers will be reduced to integers through floor(n)
.n >= 171
are not representable as `double' anymore.factorial
fact(c(-1, 0, 1, NA, 171)) #=> NaN 1 1 NA Inf
fact(100) #=> 9.332621544394410e+157
factorial(100) #=> 9.332621544394225e+157
# correct value: 9.332621544394415e+157
# Stirling's approximation: 9.324847625269420e+157
# n! ~ sqrt(2*pi*n) * (n/e)^n
Run the code above in your browser using DataLab