2017-06-20 25 views
1

我试图在小数点后打印更多数字。所以用了“mpfr”功能。但是,为什么我会得到这个结果呢?来自Rmpfr包的mpfr函数

> mpfr(1/5, 120) 
1 'mpfr' number of precision 120 bits 
[1] 0.20000000000000001110223024625156540424 

为什么打印“1110223024625156540424”后的结果为0?

回答

1

因为你给了它一个不是你认为的数字。该部门首先作为双精度操作完成。

1/Rmpfr::mpfr(5, 80) 
1 'mpfr' number of precision 80 bits 
[1] 2.0000000000000000000000004e-1 

> 1/Rmpfr::mpfr(5, 120) 
1 'mpfr' number of precision 120 bits 
[1] 2.0000000000000000000000000000000000004e-1 

我的另一种方法由5更高的精度版本,然后将其通过的/的MPFR版本(除法函数)来处理。

看你得到了什么:

methods(`/`) 
+0

谢谢。你知道为什么最后打印4吗? – Mac

+0

不,我不知道。也许马丁Maechler会徘徊。 ISTR是他的包裹。 –