I have a set of values a[i]
.
Then I compute
for(...){
b[i] = log(a[i]);
}
Then I sum up
for(...){
s += c[i] * b[i];
}
That's no problem so far.
BUT for some i
my a[i]
may be zero and lead to b[i] = log(0) = -Inf
. For these i
, c[i]
is also zero - those are some invalid data points. But zero*-Inf
seems to give NaN
, and my sum is messed up...
Is there a way to always have c[i] * b[i]
= 0 when c[i]
is = 0?
The only way I see is to set all zero a[i]
to a small non-zero value or to check for zero, but there might be better solutions.
I use C++ and std
math functions, but I'm looking for a method which works as generally as possible.