Have a look at this snippet in Java:
double alpha = alphaFactors.get(0, q);
double beta = betaFactors.get(0, q);
if ((alpha + beta) > Double.NEGATIVE_INFINITY) {
initialDistributionStripe.put(new IntWritable(q),
new DoubleWritable(alpha + beta));
}
To avoid garbage values, I want to add to the initialDistributionStripe map the sum (alpha + beta) if and only if it is larger than Double.NEGATIVE_INFINITY, and is not equal to NaN.
I believe what I am doing is correct and I don’t need to explicitly check for ‘NaN’ because according to the IEEE 754 and Java spec, any comparisons against NaN result in false. So if alpha + beta is NaN, then ((alpha + beta) > Double.NEGATIVE_INFINITY) will be false.
Is my reasoning correct?
That’s correct.
If you want to be explicit about it, you could add
&& !Double.isNaN(alpha + beta)(Keep in mind thatalpha + beta != Double.NaNistrueeven thoughalpha + betais indeedDouble.NaN).