# Sample 100 values
y = log(rexp(100,1))
# These will give the same value,
# since e^y is "small"
logMeanExpLogs(y)
log(mean(exp(y)))
# We can make e^x overflow by multiplying
# e^y by e^1000
largeVals = y + 1000
# This will return 1000 + log(mean(exp(y)))
logMeanExpLogs(largeVals)
# This will overflow
log(mean(exp(largeVals)))
Run the code above in your browser using DataLab