Perl-Sensitive Sunglasses | |
PerlMonks |
Re^2: Operations with Extremely Large Numbersby BrowserUk (Patriarch) |
on Nov 09, 2011 at 18:14 UTC ( [id://937171]=note: print w/replies, xml ) | Need Help?? |
A further thought. If these calculations are in anyway time-critical. In almost every formula I've ever encountered that uses huge factorials -- usually probability calculations of one form or another -- there are usually (at least) two factorial (or factorial derived) terms that eventually are divided one by the other so bringing the silly numbers back into the realms of rationality. So you tend to have formulae something like:
Ostensibly, the calculation goes like this:
Which using arbitrary precision can take long time (and a large amount of memory) to calculate. But with cursory inspection it is easy to see that the result is just 1/ ( 1* 2 * 3 * 4 ) == 1/24 == 0.041666666666666666666666666666667 . If your application requires the calculation of large numbers of these types of formulae, and timeliness is of any consideration, it makes sense to avoid the huge numbers by deferring the actual math until you've performed some "cancelling out". In most cases, the avoidance of arbitrary precision more than compensates for the extra effort and care required.
In Section
Seekers of Perl Wisdom
|
|