Can someone explain how does it possible that primitive double
type equals to NaN
after following computations. Can you tell me some cases when double
could end up as Nan
? Thanks!
double averagePrecisionExisting = 0;
for (int i = 0; i < x; i++)
averagePrecisionExisting += logicWhichReturnsPrimitiveDouble();
double meanAveragePrecisionExisting = averagePrecisionExisting / x.size();
System.out.println("Mean average precision of existing algorithm = " + meanAveragePrecisionExisting);
Output: Mean average precision of existing algorithm = NaN
Assuming your loop is meant to use x.size()
, then it's pretty simple - if x.size()
is 0, you'll be computing 0/0, which is NaN.
Otherwise, it could be that logicWhichReturnsPrimitiveDouble()
returns a NaN
for whatever reason. It's not clear why you've emphasized the "primitive" part in various places in your post - a primitive double
is just as capable of representing NaN as Double
. Indeed, the type of Double.NaN
is double
...
See more on this question at Stackoverflow