| Author |
Tricky Question...?
|
santhosh.R gowda
Ranch Hand
Joined: Apr 06, 2009
Posts: 296
|
|
What makes the following code print false ?
|
Creativity is nothing but Breaking Rules
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12953
|
|
|
Well, what do you think? Do you have an idea yourself?
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
One hint: <sometype> is a primitive.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Saifuddin Merchant
Ranch Hand
Joined: Feb 08, 2009
Posts: 576
|
|
Well I am assuming that in the question I am only allowed to fill in 'sometype' and 'somevalue' and not make any more changes.
Well in which case whatever answer you give me is going to shake my concepts on java. A '==' returning false that's pretty big!
@Rob - We'll with your hint I still don't work this out. If you meant boolean I don't see how it works.
I give up. Is this even really possible
|
Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
I give up. Is this even really possible
Of course, it's possible. It is a trick question, after all.
And like all trick questions, either you know it or you don't.... but as another hint.... It is related to floating points. And related to how IEEE defines how equality works with floating points.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
santhosh.R gowda
Ranch Hand
Joined: Apr 06, 2009
Posts: 296
|
|
i''m not having Idea
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
also it is already discussed here and Rob answared this question ... search here
|
 |
Saifuddin Merchant
Ranch Hand
Joined: Feb 08, 2009
Posts: 576
|
|
seetharaman venkatasamy wrote:also it is already discussed here and Rob answared this question ... search here
Exactly what phrase do you want us to search with?
Rob's answered almost every question out here so searching by his name is not a viable option!
@Henry - Point taken - Actually I did think about floating point numbers. I know them all too well.
But to say x == x gives a false -- I cannot think of any possible value of x where this happens? So what could the special value be.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Sam Mercs wrote:
Exactly what phrase do you want us to search with?
i simply search by "tricky question". Have a look Here
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
Sam Mercs wrote:Exactly what phrase do you want us to search with?
floating point equality
|
Joanne
|
 |
Saifuddin Merchant
Ranch Hand
Joined: Feb 08, 2009
Posts: 576
|
|
|
Nan. Interesting to say the least!!!
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
So you got it. Please don't use thread titles like "tricky question... ?" Look at this FAQ.
Now: I challenge you: prove that such behaviour of NaN is logically correct.
|
 |
Saifuddin Merchant
Ranch Hand
Joined: Feb 08, 2009
Posts: 576
|
|
Campbell Ritchie wrote:So you got it. Please don't use thread titles like "tricky question... ?" Look at this FAQ.
Now: I challenge you: prove that such behaviour of NaN is logically correct.
You mean besides your proof of 2=3?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
Oh, you have found it? Yes, beside my proof of 2=3. You could try proving 3=5!
|
 |
Saifuddin Merchant
Ranch Hand
Joined: Feb 08, 2009
Posts: 576
|
|
It was a great question though. Posting one too in the Puzzles Forum
|
 |
 |
|
|
subject: Tricky Question...?
|
|
|