Java – -Infinity values in Java

java

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

-7.314254939475686
-7.656004233197743
-4.816276208120333
-8.426112454893817
-4.771824445549499
-9.34240318676797  

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

-2668.179647264475
-2674.7747795369874
-2679.18920466334
-2683.9724816026214
-2690.3342661536453
-Infinity
-Infinity  

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.