Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Malloc with Inline::C

by tall_man (Parson)
on Mar 27, 2005 at 06:07 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-25 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found