Not really an answer, but a possible clue.
Numbers kept in "log form" can be multiplied or divided by simply adding or subtracting the numbers. For example, exp(log(a) + log(b))
is the same as a * b
. Or, using a = 41, b = 101, this would be exp(3.71357 + 4.61512)
, which is exp(8.32869)
, or 4140.98930
. Obviously precision plays a part, and I truncated the numbers to 5 digits. 41 * 101
is 4141
.
I haven't worked through your example code, nor is it immediately obvious to me why your code does things the way it does, but hopefully the above will be able to help you piece it together.
EDIT: I ran some numbers through your example code. If a = 41 and b = 101, and log_a = 3.71357 and log_b = 4.61512, then your example code computes 4.95582
, and exp(4.95582)
is equal to 142.0
. The "simpler" way to get this same result is log(exp(log_a) + exp(log_b))
, but as others have pointed out, this way involves three expensive transcendental functions, whereas your example code requires only two (plus a trivial comparison).