"
long int fac(unsigned long int n) {
return lround(exp(lgamma(n+1)));
}
"
Sounds great! What's the factorial of 40? Let's use some python:
>>> int(math.exp(math.lgamma(41)))
815915283247882431423526575245034982027017846784L
Huh, weird. I would've thought the factorial of 40 would be divisible by ten. Let's try it another way:
Prelude> let fac n = foldr1 (*) [1..n]
Prelude> fac 40
815915283247897734345611269596115894272000000000
The author's disdain for the lambda calculus, as if it is somehow not real math (because it doesn't involve numbers in the familiar sense?), is bizarre.
is just about the worst way to use lgamma. If long ints are signed 64 bit integers, then the largest factorial you can store is 20!. You might as well look it up in an array. But you frequently need ratios of factorials (and values of the gamma function more generally) when doing statistical computing and lgamma is invaluable.
Sounds great! What's the factorial of 40? Let's use some python:
>>> int(math.exp(math.lgamma(41)))
815915283247882431423526575245034982027017846784L
Huh, weird. I would've thought the factorial of 40 would be divisible by ten. Let's try it another way:
Prelude> let fac n = foldr1 (*) [1..n]
Prelude> fac 40
815915283247897734345611269596115894272000000000
The author's disdain for the lambda calculus, as if it is somehow not real math (because it doesn't involve numbers in the familiar sense?), is bizarre.