Nice, but neither @log nor $next are necessary, and the whole thing can be given a functional interface, while transparently memoizing the results:
{ my @ln_fact; BEGIN { $ln_fact[ 0 ] = 0; } sub ln_fact { # returns the natural log of the factorial my $n = shift; die "Invalid arg: $n" if $n < 0 or $n > int $n; $ln_fact[$_] = $ln_fact[$_-1] + log($_) for @ln_fact..$n; return $ln_fact[ $n ]; } }
the lowliest monk
In reply to Re^4: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
by tlm
in thread Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
by Commander Salamander
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |