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.