Hi, I am working on a project that does a lot of querying and the some mathematical modeling based on results from these queries, and finally some scoring (read: "execution time too long to test thoroughly").
Recently I have realized a rather new problem/bug in my code; some of the results get NaN
values for score! Here's how the scores are calculated:
Note that pfound
, psig
are double
s that are always positive or 0
Double score1 = (pfound!=0) ? (Math.log(factorial((int)psig + 1))/pfound) : 0;
score1 = score1 * alpha_coeff[0];
if (score1.isInfinite())
throw new RuntimeException(p.getName() + " score1 = Inf");
else if(score1.isNaN())
throw new RuntimeException(p.getName() + " score1 = NaN");
I have checked the possible causes triggering NaN
, but I believe it should be safe from most of those:
I am already checking for pfound == 0 (so no divide by zero)
Argument to Math.log() cannot have a negative value
What I suspect is whether or not factorial()
(a custom function which return the factorial as a long
) returns a long
so big that it can't be cast into a double
without loss of precision or something like that. I checked Long.doubleValue()
, and apparently it generates NaN
if it's argument results in NaN
.
Any comments? Am I missing something fundamental here?