Java – -Infinity values in Java


I'm trying to sum 561 logs.
They look like these:


So they're not big numbers. However, when I proceed with summing them I get this:


The code that does it is:

double probspam=0;

for(int j=0;j<words.size();j++)
    probspam+= Math.log(spam.getClassProbability(words.get(j)));


Do you have any idea of how to get around the -Infinity issue and why it happens? Thank you

Best Solution

For some values, spam.getClassProbability() returns 0.0: see the docs:

If the argument is positive zero or negative zero, then the result is negative infinity.