Search code examples
rcomputation

Getting 0 in R instead of a precise result


How can I get the actual precise result instead of the rounded ones?

result = ((0.61)**(10435)*(0.39)**(6565))/((0.63)**(5023)*(0.60)**(5412)*(0.37)**(2977)*(0.40)**(3588))

out:

NaN

Because, denominator is 0


Solution

  • I think logarithm is a power tool to deal with exponential with large powers (see it properties in https://mathworld.wolfram.com/Logarithm.html)

    You can try to use log first over your math expression and then apply exp in turn, i.e.,

    result <- exp((10435*log(0.61)+6565*log(0.39)) - (5023*log(0.63)+5412*log(0.60)+ 2977*log(0.37)+3588*log(0.40)))
    

    which gives

    > result
    [1] 0.001219116