Microcebus has asked for the wisdom of the Perl Monks concerning the following question:
I found that useful script to calculate factorials of rational numbers:
But using it together with the bignum module returns the error message: Can't locate object method "_cartesian" via package "Math::BigInt". The Math::BigInt module is up to date. All I want to do is calculating factorials of rational numbers up to 999.9. Can someone help?# Pragmas. use strict; # Modules. use bignum; use Math::Complex; # Global variables. use vars qw($g $lanczos_coef); $g = 7; $lanczos_coef = [ 0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7 ]; sub gamma_lanczos { my $z = shift; $z = Math::Complex->make($z); if (Re($z) < 0.5) { return pi / (sin(pi * $z) * gamma(1 - $z)); } else { $z -= 1; my $x = $lanczos_coef->[0]; foreach my $i (1 .. $g + 2) { $x += $lanczos_coef->[$i] / ($z + $i); } my $t = $z + $g + 0.5; return sqrt(2 * pi) * $t ** ($z + 0.5) * exp(-$t) * $x +; } } print gamma_lanczos(25.78), "\n"; system("pause");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Factorials of rational numbers up to 999.9
by Corion (Patriarch) on May 16, 2011 at 08:08 UTC | |
by Microcebus (Beadle) on May 16, 2011 at 08:17 UTC | |
by Corion (Patriarch) on May 16, 2011 at 08:21 UTC | |
|
Re: Factorials of rational numbers up to 999.9
by anonymized user 468275 (Curate) on May 16, 2011 at 12:09 UTC |