This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes comparing long and double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "comparing long and double" Watch "comparing long and double" New topic
Author

comparing long and double

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100


Why does this return true.
Doesn't long and double have different bit patterns?
Shilpi M Ag
Ranch Hand

Joined: May 07, 2004
Posts: 40
Comparision of primitives only compares values
Chris Allen
Ranch Hand

Joined: Feb 01, 2003
Posts: 127
In this case, the long value will be promoted to a double value before the equality expression is evaluated. Thus, the values are deemed to be equal. The widening rules are as follows:

1. If either expression is of type double, the other is converted to a double
2. If either expression is of type float, the other is converted to a float
3. If either exprssion is of type long, the other is converted to a long
4. Otherwise, both operands are converted to int
 
jQuery in Action, 2nd edition
 
subject: comparing long and double
 
Similar Threads
C++ class to Java
Value of hexadecimal 0xDeadCafe
Angles
0.1 + 0.2 is not equal 0.3
Problem in Generic Method Declaration