DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Can X == X be False?

1. Registered User
Join Date
Oct 2004
Posts
1

## 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();
}

I have been thinking about this for couple of days and am about to giveup.

Thanks.

2. Senior Member
Join Date
Mar 2004
Posts
635
well mathmatically you could prove it false I suppose.

3. Senior Member
Join Date
Feb 2004
Posts
541
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?

4. Registered User
Join Date
Sep 2004
Posts
150
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.

5. Senior Member
Join Date
Feb 2004
Posts
541
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

6. Registered User
Join Date
Sep 2004
Posts
150
Hey I said in java it was a good question

Nice info, that's a gotcha if I've ever seen one.

7. Senior Member
Join Date
Mar 2004
Posts
635
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.

8. Senior Member
Join Date
Feb 2004
Posts
541
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.

9. Registered User
Join Date
Sep 2004
Posts
223
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. Senior Member
Join Date
Feb 2004
Posts
541
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.

11. Registered User
Join Date
Sep 2004
Posts
223
oh yeah, my bad

12. Registered User
Join Date
Sep 2004
Posts
150
Here's an article from Mathworld on the subject.

http://mathworld.wolfram.com/Fallacy.html

You cannot prove that 0=1 unless your argument is flawed. They probably showed you how easy it was to get into a flawed argument, though.

The "loose" proofs laid out in some Geometry classes are infamous for being easy to mess up and prove things incorrectly. But they are valid as long as mathematical rules are carefully followed.

13. Senior Member
Join Date
Feb 2004
Posts
541
Yes, that 'proof' is exactly the same one that I remember being shown. I see it is just as false as ever :P

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise
 Questions? Contact us. C++ Web Development Wireless Latest Tips Open Source

×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.