Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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


Comment on Re: Malloc with Inline::C
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://442592]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-08-30 00:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls