jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Strange result from double comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Strange result from double comparison" Watch "Strange result from double comparison" New topic
Author

Strange result from double comparison

Siamak Saarmann
Ranch Hand

Joined: Aug 21, 2004
Posts: 77
Hello,

I have a simple comparison of two double numbers. The same comparison when put in println function gives the correct response (see in the output) but the same comparison if assigned to a boolean value gives a wrong response;

I tried to compare numbers inside if condition, in a boolean variable, in reverse for (i.e: gone > MAX_MOVE) but every time it fails.

Could someone please tell me what is wrong?

I have narrowed down a bug in 20,000 lines of code to this and I can not figure out the reason.

Thank you.
Mac



PhD Candidate: Distributed and Parallel Systems, Simulation and Modeling
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi,

i tried it is working...i do not find any issue..please can you explain clearly?

thanks & regards,
seetharaman
Siamak Saarmann
Ranch Hand

Joined: Aug 21, 2004
Posts: 77
I am not sure what is the problem. It works on my home PC, but as you see the output (printout of the variables) it did not work on my PC in university.

(gone<= MAX_MOVE) has given a different value in 2nd output line than the one coming from boolean variable.

I really don't know... This has happened for the first time in several years.
[ May 05, 2008: Message edited by: Siamak Saarmann ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange result from double comparison
 
Similar Threads
Regarding Assignment
Class and Object Problem
comparing MAX Values of Wrapper class with float and double
== & equals()
doubt regarding basic primitives