Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Square root of a number to 100 decimal places

Tags:

r

How can I get the square root for a number to 100 decimal places in R?

I've looked into the gmp and the Rmpfr packages. I can't figure out how I would use them for square roots, (pow.bigz(2,0.5)=1) but even if I did, I'm not sure how accurate it would be, since I've found that after about 25 decimal places, the digits aren't reliable

eg

mpfr(1/3,400)
# 1 'mpfr' number of precision  400   bits 
# [1] 0.333333333333333314829616256247390992939472198486328125

and

as.bigz(1e50/3)
# Big Integer ('bigz') :
# [1] 33333333333333337607355566542238210608487100055552
like image 305
Bell Avatar asked Dec 07 '25 23:12

Bell


1 Answers

The question is computing one third prior to mpfr so it has already lost precision by the time mpfr sees it. Do it this way:

mpfr(1, 400)/3
like image 61
G. Grothendieck Avatar answered Dec 09 '25 15:12

G. Grothendieck