本文介绍了是否有用于计算R中的大阶乘的软件包或技术?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我计算factorial(100)
,那么我得到[1] 9.332622e+157
的答案,但是当我尝试计算更大的阶乘时,说factorial(1000)
我得到的答案是[1] Inf
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
在计算阶乘时是否可以使用任意精度,这样我就可以计算出factorial(1000000)
?
Is there a way to use arbitrary precision when calculating factorials such that I can calculate say factorial(1000000)
?
推荐答案
对于任意精度,可以使用gmp
或Rmpfr
.对于专门的阶乘gmp
,提供factorialZ
,而Rmpfr
具有factorialMpfr
.因此,您可以运行以下内容
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
这篇关于是否有用于计算R中的大阶乘的软件包或技术?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!