Re: [R] The gamma function and infinity

From: Martin Maechler <>
Date: Tue 06 Dec 2005 - 03:51:56 EST

>>>>> "PD" == Peter Dalgaard <> >>>>> on 05 Dec 2005 17:14:47 +0100 writes:

    PD> Florent Bresson <> writes:
>> I have to calculate some formula like:
>> gamma(x)/(gamma(x+y)
>> and I observed that for relatively big values of x, R
>> returns infinity and so cannot compute the formula. Is it
>> possible to force R to give the real value of gamma(x)
>> instead of Inf ?

    PD> No, it is overflowing the floating point representation.

    PD> How about using lgamma? That's basically what it is for.

Indeed. Note however that in the case of really large x and moderate y, even in the lgamma() formulation, there will be loss of precision due to cancellation. There are "famous" asymptotic (non-convergent series) formulae, you can use in that case, the most simple one being

    Gamma(a + y) / Gamma(a) ~ a^y (for a -> Inf, y << a) and hence

    log(Gamma(a + y)) - log(Gamma(a)) ~ y*ln(a)

Martin Maechler, ETH Zurich

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Tue Dec 06 04:12:39 2005

This archive was generated by hypermail 2.1.8 : Tue 06 Dec 2005 - 09:26:20 EST