File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Strange result from double comparison" Watch "Strange result from double comparison" New topic

Strange result from double comparison

Siamak Saarmann
Ranch Hand

Joined: Aug 21, 2004
Posts: 78

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.

PhD Artificial Intelligence, OCJP1.6
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575


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

thanks & regards,
Siamak Saarmann
Ranch Hand

Joined: Aug 21, 2004
Posts: 78
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:
subject: Strange result from double comparison
jQuery in Action, 3rd edition