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 p_i=(q_i)/(sum_1^3q_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=log(q_i) and log(pi)=log(q_i)−log(q_1+q_2+q_3), at this moment, I know log(q_1)=−2012,log(q_2)=−2013,log(q_3)=−2014, but how to deal with log(q_1+q_2+q_3), any one could give me some idea?

ohgodamnitw0

ohgodamnitw0

Answered question

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 = 1 3 q i , p i = q i 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 = l o g ( q i ) and l o g ( p i ) = l o g ( q i ) l o g ( q 1 + q 2 + q 3 ), at this moment, I know l o g ( q 1 ) = 2012 , l o g ( q 2 ) = 2013 , l o g ( q 3 ) = 2014, but how to deal with l o g ( q 1 + q 2 + q 3 ), any one could give me some idea?
thanks

Answer & Explanation

goffaerothMotw1

goffaerothMotw1

Beginner2022-09-07Added 10 answers

Hint
Let me suppose q 1 > q 2 > q 3 . So,
p 1 = q 1 q 1 + q 2 + q 3 = 1 1 + q 2 q 1 + q 3 q 1
Now,
p 2 = p 1 q 2 q 1
p 3 = p 2 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?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?