-
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.
-
well mathmatically you could prove it false I suppose.
-
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?
-
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.
-
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
-
Hey I said in java it was a good question
Nice info, that's a gotcha if I've ever seen one.
-
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.
-
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.
-
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
A kram a day keeps the doctor......guessing
-
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.
-
oh yeah, my bad
A kram a day keeps the doctor......guessing
-
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.
-
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
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|