ohgodamnitw0

2022-09-06

Best way to handle the ratio which cannot be represented as floating point numbers.
I need to calculate the ratio of the form:
$s=\sum _{1}^{3}{q}_{i}$, $\phantom{\rule{1em}{0ex}}$${p}_{i}=\frac{{q}_{i}}{\sum _{1}^{3}{q}_{i}}$
where ${q}_{i}>0$. One problem is that ${q}_{i}$ are too small that they can not represented as floating point numbers, then I can try logarithms ${z}_{i}=\mathrm{l}\mathrm{o}\mathrm{g}\left({q}_{i}\right)$ and $\mathrm{l}\mathrm{o}\mathrm{g}\left({p}_{i}\right)=\mathrm{l}\mathrm{o}\mathrm{g}\left({q}_{i}\right)-\mathrm{l}\mathrm{o}\mathrm{g}\left({q}_{1}+{q}_{2}+{q}_{3}\right)$, at this moment, I know $\mathrm{l}\mathrm{o}\mathrm{g}\left({q}_{1}\right)=-2012,\mathrm{l}\mathrm{o}\mathrm{g}\left({q}_{2}\right)=-2013,\mathrm{l}\mathrm{o}\mathrm{g}\left({q}_{3}\right)=-2014$, but how to deal with $\mathrm{l}\mathrm{o}\mathrm{g}\left({q}_{1}+{q}_{2}+{q}_{3}\right)$, any one could give me some idea?
thanks

goffaerothMotw1

Hint
Let me suppose ${q}_{1}>{q}_{2}>{q}_{3}$. So,
${p}_{1}=\frac{{q}_{1}}{{q}_{1}+{q}_{2}+{q}_{3}}=\frac{1}{1+\frac{{q}_{2}}{{q}_{1}}+\frac{{q}_{3}}{{q}_{1}}}$
Now,
${p}_{2}={p}_{1}\frac{{q}_{2}}{{q}_{1}}$
${p}_{3}={p}_{2}\frac{{q}_{3}}{{q}_{2}}$
I suppose that this will give you your number for almost any accuracy (computing the required ratios from the logarithms).

Do you have a similar question?