Apply package mpfr for a function in R
Pregunta
I want to apply package mpfr for a function as follows:
f1 =function(x) exp(x)
if for example x = c(-1500, -2000, -6400, -7200)
> x = c(-1500, -2000, -6400, -7200)
> mpfr(f1(x), precBits=64)
4 'mpfr' numbers of precision 64 bits
[1] 0 0 0 0
I would like to get the values of function f1 even if its so small, how can I get it in R?
Solución
64 bits is not a whole lot. But primarily, you've made a mistake many of us did: the value of f1(x)
is already zero because it's calculated before being converted into a bignum.
Try it this way:
> exp(mpfr(c(-1000,-5000),200))
2 'mpfr' numbers of precision 200 bits
[1] 5.0759588975494567652918094795743369193055992828928373618323948e-435
[2] 3.3696941483089175144500323238132201679550979027292655581078801e-2172
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow