Search code examples
rlogarithmexponential

Exponentiate very large numbers in R


I have the logarithms of very large values, for example:

log_a = 1347 
log_b = 1351 

And I am trying to solve this expression:

exp(log_a) - (0.1 * exp(log_b))

Or equivalently this (same expression just in a different form):

exp( log_a ) - exp( log(0.1) + log_b ) 

But of course every time I try to compute exp(log_a) or exp(log_b) values I get Inf. Are there any tricks I can use to get a real result for exp(log_a) - (0.1 * exp(log_b)), either in logarithm or exponential form?

Thank you very much for the help!


Solution

  • library(Brobdingnag)
    a <- as.brob(exp(1))^1347
    a*(1-0.1*exp(4))
    #[1] -exp(1348.5)
    

    or calculated manually:

    -(exp(1347+log(0.1*exp(4)-1))=-exp(1347+1.4951...)=-exp(1348.4951...)