set.seed(12)
ly <- rnorm(100, sd= 50)
lx <- ly + abs(rnorm(100, sd=100)) # lx - ly must be positive for *.sub()
stopifnot(exprs = {
all.equal(logspace.add(lx,ly),
log(exp(lx) + exp(ly)), tol=1e-14)
all.equal(logspace.sub(lx,ly),
log(exp(lx) - exp(ly)), tol=1e-14)
})
Run the code above in your browser using DataLab