http://www.perlmonks.org?node_id=442592


in reply to Malloc with Inline::C

typedef (malloc(2*sizeof(long double))) Big_Double; Big_Double factrl;

Malloc is a function to allocate memory dynamically. It has no business in a typedef. Even if you did allocate a big variable, that would not automatically give you extended precision arithmetic.

From your other postings, it looks like you want to calculate binomial coefficients. The binomial coefficients may not overflow even if the factorials do. Say you wanted 1000 choose 5 = 1000!/(1000-5)!(5!). Your gammln gives you logs, so you could compute:

exp(gammln(1001.0) - gammln(996.0) - gammln(6.0));

But if you really want to print the values of huge factorials for some reason, here's another trick you could use: convert your gammln to a decimal log, and truncate to get the exponent, like this:

my $n = gammln(1000 + 1.0)/log(10.0); my $exp = int($n); my $mantissa = 10.0 ** ($n - $exp); printf "${mantissa}e$exp\n";