如何在R中使用mpfr包来检查数字是否是完美的正方形?

时间:2015-04-24 09:43:52

标签: r integer mpfr perfect-square

我有一个决定因素,我知道它是一个整数的平方,但因为它的值大于.Machine$integer.max我使用了mpfr包。

但我仍有问题。

以下是算法:

> a<- mpfr(sqrt(det(M)), precBits=512);a
1 'mpfr' number of precision  512   bits 
[1] 430080000000001.1875

你能帮我吗?

1 个答案:

答案 0 :(得分:2)

性能是一个问题吗?如果没有,则以下内容应该有效。

> x<-mpfr(31415926535897932384626433832795, 500)
> is.whole(sqrt(x))
[1] FALSE


> y<-mpfr(31415926535897932384626433832794, 500)^2
> y
1 'mpfr' number of precision  500   bits
[1] 986960440108935918772069008410384076085841574993068761741787136
> is.whole(sqrt(y))
[1] TRUE