Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Malloc with Inline::C

by tall_man (Parson)
on Mar 27, 2005 at 06:07 UTC ( #442592=note: print w/replies, xml ) Need Help??

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";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://442592]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2017-10-24 06:16 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (286 votes). Check out past polls.