3 ms·
"So it’s not clear which version is better..." In general, it's application-dependent. But often, in applications, the factorial enters multiplicatively, and
by mturmon 13y ago
"So it’s not clear which version is better..."
In general, it's application-dependent. But often, in applications, the factorial enters multiplicatively, and they are in products with other stuff; the whole thing can easily underflow or overflow.
So what you often really want is the log of the factorial. (If someone gave you the exact integer factorial for free, the first thing you'd do is take its log.) That's why they implemented lgamma(). The error guarantees it gives are in the log domain, which is (often, not always) what you want, anyway.