## 30 digit precision
str(x <- mpfr(c(2:3, pi), prec = 30 * log2(10)))
x^2
x[1] / x[2] # 0.66666... ~ 30 digits
## indexing - as with numeric vectors
stopifnot(identical(x[2], x[[2]]),
## indexing "outside" gives NA (well: "mpfr-NaN" for now):
is.na(x[5]),
## whereas "[[" cannot index outside:
is(try(x[[5]]), "try-error"),
## and only select *one* element:
is(try(x[[2:3]]), "try-error"))
## factorial() & lfactorial would work automagically via [l]gamma(),
## but factorial() additionally has an "mpfr" method which rounds
f200 <- factorial(mpfr(200, prec = 1500)) # need high prec.!
f200
as.numeric(log2(f200))# 1245.38 -- need precBits >~ 1246 for full precision
##--> see factorialMpfr() for more such computations.
Run the code above in your browser using DataLab