• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tricky Question...?

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What makes the following code print false ?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15452
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what do you think? Do you have an idea yourself?
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One hint: <sometype> is a primitive.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Marshal
Pie
Posts: 21430
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i''m not having Idea
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also it is already discussed here and Rob answared this question ... search here
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Mercs wrote:Exactly what phrase do you want us to search with?


floating point equality
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nan. Interesting to say the least!!!
 
Campbell Ritchie
Sheriff
Pie
Posts: 49842
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49842
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, you have found it? Yes, beside my proof of 2=3. You could try proving 3=5!
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was a great question though. Posting one too in the Puzzles Forum
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic