This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes comparing MAX Values of Wrapper class with float and double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "comparing MAX Values of Wrapper class with float and double" Watch "comparing MAX Values of Wrapper class with float and double" New topic
Author

comparing MAX Values of Wrapper class with float and double

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026



o/p ==> equal unequal equal equal equal

Question: Please explain the output


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
I found the answer.

http://www.coderanch.com/t/249321/java-programmer-SCJP/certification/does-work
Ritesh Raman
Ranch Hand

Joined: Jun 20, 2005
Posts: 34
hi
vishnu

are you find the answer of your question?
i am still confusing .

plz. explain me the answer--
equal unequal ----
especially with respect to long & int .

with respect
ritesh


Thanks,<br />--------<br />SCJP 1.4
Ritesh Raman
Ranch Hand

Joined: Jun 20, 2005
Posts: 34
hi
vishnu

are you find the answer of your question?
i am still confusing .

plz. explain me the answer--
equal unequal ----
especially with respect to long & int .

with respect
ritesh
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
The reason one equality test returns true and the other returns false is that comparing floating-point numbers often has results that are difficult to predict. In this case, you're comparing a float and a double, so the compiler promotes the float to a double in order to do the comparison, because the compiler needs the two values to be the same type before comparing them. Here's a program that illustrates how this is happening:


The output is:

true
true
9.223372036854776E18
9.223372036854776E18
false
false
2.147483648E9
2.147483647E9

When f1 is cast to a double, it happens to have the same exact value as d1, so f1==d1 returns true. However, when f2 is cast to a double, it does not have exactly the same value as d2, so f2==d2 returns false. I don't think there is any way to predict the output without using a compiler, unless you happen to be an expert on floating-point bit patterns.
Ritesh Raman
Ranch Hand

Joined: Jun 20, 2005
Posts: 34
hi
vishnu
i think u r right.

--------------------------------------------------------------------------
there is no any way to predict the output without using a compiler, unless you happen to be an expert on floating-point bit patterns.
---------------------------------------------------------------------------


ritesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: comparing MAX Values of Wrapper class with float and double