jjw017 has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I've been trying to come up with a way to calculate factorials of very large numbers (example: of 2032597) and currently I'm stuck on the implementation of the Stirling's approximation. I tried using bignum but I keep getting an error stating: "Can't use an undefined value as an ARRAY reference at C:/Perl/../Calc.pm"
In this approximation, $exp evaluates to ~2.8e11938980. Is this number too large to be used in perl?
use Math::Trig; use bignum; sub factorial { my $n = @_; my $root = sqrt($n*2*pi); my $exp = ($n/exp(1))^$n; my $result =$root*$exp; return $result; } my $b = 2032597; my $r = Math::BigInt->new(factorial($b)); print "b is $b\n"; print "the calculated result is $r\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Operations with Extremely Large Numbers
by BrowserUk (Patriarch) on Nov 09, 2011 at 17:25 UTC | |
by BrowserUk (Patriarch) on Nov 09, 2011 at 18:14 UTC | |
by jjw017 (Initiate) on Nov 09, 2011 at 18:36 UTC | |
by jethro (Monsignor) on Nov 11, 2011 at 10:44 UTC | |
|
Re: Operations with Extremely Large Numbers (BigApprox)
by tye (Sage) on Nov 09, 2011 at 17:43 UTC | |
by jjw017 (Initiate) on Nov 09, 2011 at 18:29 UTC | |
by davido (Cardinal) on Nov 09, 2011 at 19:25 UTC | |
|
Re: Operations with Extremely Large Numbers
by mrstlee (Beadle) on Nov 09, 2011 at 17:39 UTC | |
|
Re: Operations with Extremely Large Numbers
by JavaFan (Canon) on Nov 09, 2011 at 17:27 UTC |