If I calculate factorial(100)
then I get an answer of [1] 9.332622e+157
but when I try to calculate a larger factorial, say factorial(1000)
I get an answer of [1] Inf
Is there a way to use arbitrary precision when calculating factorials such that I can calculate say factorial(1000000)
?
For arbitrary precision you can use either gmp
or Rmpfr
. For specifically factorial gmp
offers factorialZ
and Rmpfr
has factorialMpfr
. So you can run something like below
> Rmpfr::factorialMpfr(200)
1 'mpfr' number of precision 1246 bits
[1] 788657867364790503552363213932185062295135977687173263294742533244359449963403342920304284011984623904177212138919638830257642790242637105061926624952829931113462857270763317237396988943922445621451664240254033291864131227428294853277524242407573903240321257405579568660226031904170324062351700858796178922222789623703897374720000000000000000000000000000000000000000000000000
> gmp::factorialZ(200)
Big Integer ('bigz') :
[1] 788657867364790503552363213932185062295135977687173263294742533244359449963403342920304284011984623904177212138919638830257642790242637105061926624952829931113462857270763317237396988943922445621451664240254033291864131227428294853277524242407573903240321257405579568660226031904170324062351700858796178922222789623703897374720000000000000000000000000000000000000000000000000
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With