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

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]
[LanX]: thanks for the tip
[LanX]: org had problems, but never thought about switching domain
LanX can't connect to net
[LanX]: now net is back again

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2017-01-22 20:32 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (190 votes). Check out past polls.