Home > front end >  Large exponent values in R with 'Rmpfr'
Large exponent values in R with 'Rmpfr'

Time:09-30

I am trying to calculate the value of exp(1000) or more in R. I looked at the solution provided in Calculate the exponentials of big negative value and followed it to replicate the code for negative values first, but I have the following output.

a <- mpfr(exp(-1000),precBits = 64)
a
1 'mpfr' number of precision  64   bits 
[1] 0

I do not understand why my output would be different from the provided solution. I understand this particular solution is for negative values and that I am looking for positive exponents. Regardless, it should work for both ways.

CodePudding user response:

You need to convert to extended precision before you exponentiate, otherwise R will try to compute exp(-1000) with its usual precision and underflow will occur (as you found out).

> a <- exp(mpfr(-1000, precBits = 64))
> a
1 'mpfr' number of precision  64   bits 
[1] 5.07595889754945676548e-435
  • Related