# Can X == X be False?

• 10-16-2004, 05:47 PM
anony22222
Can X == X be False?
Hi,

A colleague of mine said he can prove that the var x can be false. Our development group said it'll always be true, and I agreed. I am wondering if Java has a bug/glitch that can't interpret a specail character. Therefore result in a false. He said you can't modify the statement.

if (x == x) {
istrue();
} else {
isfalse();
}

Thanks.
• 10-17-2004, 04:59 AM
Phaelax
well mathmatically you could prove it false I suppose.
• 10-17-2004, 08:23 AM
mikeBarr81
Quote:

well mathmatically you could prove it false I suppose.
You could? But that would mean X was X and !X at the same time. Is this problem restricted to Java only or does he say it's true in any programming language?
• 10-17-2004, 01:49 PM
Philwx
Quote:

A colleague of mine said he can prove that the var x can be false.

First we are not sure if you mean "can X be false" or "can the expression (X == X) ever be false."

X could be anything as a variable of course.

Assuming you have the second idea in mind:

Mathematically: Absolutely not. X = X meets the mathematical properties needed for equality.

In Java? Good question. I suppose a separate thread could modify X a nanosecond before it got compared to itself. But having never tried it I dont' know for certain.

That answer might even be dependent on the kind of CPU executing it. CPU's use temporary registers differently.
• 10-17-2004, 04:30 PM
mikeBarr81
We're being way too complicated. The expression X == X will evaluate to false if X is a double equal to NaN. I got the answer from another forum. To see it, click here
• 10-17-2004, 05:08 PM
Philwx
Hey I said in java it was a good question :D

Nice info, that's a gotcha if I've ever seen one.
• 10-17-2004, 07:08 PM
Phaelax
if you remember about "proofs" from geometry (why they teach it in geometry i dont know) you can prove 0=1 and i believe 1<>1 as well. The process of the proof is often argued over quite a bit whether or not its valid.
• 10-17-2004, 07:49 PM
mikeBarr81
I can vaguely remember the proof that 0 = 1. I remember seeing where it went wrong too, but can't quite remember what it was.
• 10-17-2004, 08:04 PM
Kram
i suppose you could say that if the X variable was an object, the using the "==" operator would evaluate to false, you would need to use the .equals() method of the object class
• 10-17-2004, 09:09 PM
mikeBarr81
no, if the X variable was an object using the == method would always evaluate to true. An object always is equal to itself. Only when comparing X to another object such as Y would the == method return false when the .equals() method may return true.
• 10-17-2004, 09:31 PM
Kram