Given log(a) and log(b), return log(a+b)
double log_sum(double log_a, double log_b){
double v;
if(log_a < log_b){
v=log_b+log(1+exp(log_a-log_b));
}
else{
v=log_a+log(1+exp(log_b-log_a));
}
return v;
}
I want to know what are the benefits of the above function?
The primary (brute force) alternative looks like:
That has three transcendental function evaluations.
The computation shown uses just two transcendental functions – and should be quicker.
It may also be more stable numerically.