Double.NaN == Double.NaN is false

This code segment:
if (Double.NaN == Double.NaN) {
System.out.print("True");
}
else {
System.out.println("False");
}

will print "False".
But IntelliJ warns about the expression being always true:
"Condition Double.NaN == Double.NaN is always true."
This is wrong.

5 comments

What's the use of this code ?

BoD


Amir Eliaz wrote:

This code segment:
if (Double.NaN == Double.NaN) {
System.out.print("True");
}
else {
System.out.println("False");
}

will print "False".
But IntelliJ warns about the expression being always true:
"Condition Double.NaN == Double.NaN is always true."
This is wrong.

0

It's from a test I am giving to students :)

0

Please sign in to leave a comment.