The following question from dan's single topic exam:
class D {
static boolean m(double v) {
return(v != v == Double.isNaN(v));
}
public static void main (
String args[]) {
double d1 = Double.NaN;
double d2 = Double.POSITIVE_INFINITY;
double d3 = Double.MAX_VALUE;
System.out.print(m(d1) + "," + m(d2) + "," + m(d3));
}
}
the ans is true, true true. I expected it to be false , true, true, because, in first case, v==Double.isNaN(v)is true and therefore, v!=v is flase.
Pls clarify