The code is in
https://svn.r-project.org/R/trunk/src/nmath/choose.c

Basically, it ends up calling this code, where lbeta is the logarithm of
the incomplete beta function (which itself is a ratio of gamma functions).

double attribute_hidden lfastchoose(double n, double k)
{
    return -log(n + 1.) - lbeta(n - k + 1., k + 1.);
}


So, your main difficulty is going to be finding code for the gamma function
in your other language, or implementing one of the approximations -- it
depends on what level of accuracy you need.  For example, there's
relatively simple approximation on Wikipedia that claims 8-digit accuracy:
http://en.wikipedia.org/wiki/Stirling's_approximation#Versions_suitable_for_calculators
and there are more complicated and more accurate approximations inside R:
https://svn.r-project.org/R/trunk/src/nmath/lgammacor.c

   -thomas



On Tue, Jan 1, 2013 at 3:37 AM, binbin lu <lubinbin220@gmail.com> wrote:

> Hi all,
>
> Recently I am using the function "lchoose", but I have to rewrite it in
> other language. Can any one tell me exactly the formula or procedure for
> this function? Many thanks.
>
> Best regards,
>
> Binbin
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

	[[alternative HTML version deleted]]

