Log probabilities trick
It is often the case in calculating likelihoods, that the probabilities can be too small for computational stability. Then it makes sense to work with the log of probabilities. However here one will immediately encounter another problem: how to get log(p + q) from log(p) and log(q)?
Richard Durbin et al. explain a trick for this in Biological sequence analysis: Probabilistic models of proteins and nucleic acids (1998), section 3.6.
Then if p is chosen as the larger of p and q, Durbin et al. argue that using a table of interpolations for calculating log(1 + exp(x)) gives very close estimates for log(p + q).
https://facwiki.cs.byu.edu/nlp/index.php/Log_Domain_Computations
I just noticed there is a function logspace_add in the R API, which probably uses this trick, as they say “without causing overflows or throwing away too much accuracy”