🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.fortran
Article #6566

Re: Fastest code for Gamma function

#6566
From: Ming-Long Lam
Date: Wed, 10 May 2000 00:00
23 lines
2083 bytes
It is safer to compute the natural logarithm of the Gamma density first,
because the Gamma function T(a) can easily overflow for moderate large value
of a. Writing g(x;a,b) = (x/b)**(a-1) exp(-x/b) / b / T(a), the logarithm of
this is ln(g(x;a,b)) = (a-1) * ln(x/b) - x/b - ln(b) - lnT(a). This formula
can be further optimized depending on how frequent x, a, and b will take new
values. Anyway, there is a site in Japan
http://momonga.t.u-tokyo.ac.jp/~ooura/
which provides a Fortran 90 codes to compute the logarithm of T(a). This is
very fast (because it uses "classical" Chebyshev approximation) and the
routine offers up to 14 to 16 significant digits.

Leonard Howell wrote:

> Hi all --
>
> I need to compute the gamma probability density function  g(x;a,b)=C(a,b)
> x**(a-1) exp(-x/b) on the order of 10**10 calls (on many different
> occasions) and thus would like to use the FASTEST algorithm available.  It
> must also be double precision with 14 or 15 decimal places of accuracy.
> Advice/coded FORTRAN solutions greatly appreciated.  Other language
> solutions also welcome, if the speed and accuracy is achieved.
>
> Thanks, Leonard
Technical Details
Message-ID: <3919A861.D1E465A0@spss.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <fGNQ4.51301$WF.2761743@bgtnsc04-news.ops.worldnet.att.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d632,8bad7910b3fe0dc6
X-Google-Attributes: gid10d632,public
X-Google-Thread: 104500,8bad7910b3fe0dc6
X-Google-Attributes: gid104500,public
X-Google-Thread: 1094ba,8bad7910b3fe0dc6
X-Google-Attributes: gid1094ba,public
From: Ming-Long Lam <mlam@spss.com>
Subject: Re: Fastest code for Gamma function
Date: 2000/05/10
Message-ID: <3919A861.D1E465A0@spss.com>
X-Deja-AN: 621689395
Content-Transfer-Encoding: 7bit
References: <fGNQ4.51301$WF.2761743@bgtnsc04-news.ops.worldnet.att.net>
X-Accept-Language: ja,en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@spss.com
X-Trace: netsrv2.spss.com 957982248 2529 192.35.251.2 (10 May 2000 18:10:48 GMT)
Organization: SPSS Inc.
Mime-Version: 1.0
NNTP-Posting-Date: 10 May 2000 18:10:48 GMT
Newsgroups: comp.lang.fortran,computer42.statistik,sci.stat.math,comp.lang.fortran