http://www.perlmonks.org?node_id=974274


in reply to Add numbers in log domain [solved]

well, suppose that x >= y, and that we are using the natural base:
log(x + y) = log(x * (1 + y/x)) = log(x) + log(1 + y/x) y/x = exp(log(y/x)) = exp(log(y) - log(x)) log(x + y) = log(x) + log(1 + exp(log(y) - log(x)))

And that formula can be easily calculated using regular perl scalars because log(y) - log(x) is in [-log(x), 0] and exp(log(y) - log(x)) is in (0, 1].