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:
v = log(exp(log_a) + exp(log_b));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With