permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A great doubt in Widening Numeric Conversions 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A great doubt in Widening Numeric Conversions" Watch "A great doubt in Widening Numeric Conversions" New topic
Author

A great doubt in Widening Numeric Conversions

Kalyana Sundaram
Ranch Hand

Joined: Mar 18, 2005
Posts: 94
Hey Guys,
I follow the “A Programmers guide to Java Certification” by Khalid Mughal.
It was stated that the Widening conversion takes place in the trasitive order given below

byte -> short-> int -> long -> float -> double
char -> int -> long -> float -> double

From the above stated rule, I presume that the following is a widening conversion.

long bigInteger = 987654321123456789L;
float realNo = bigInteger;

I had No doubt till this point.

Guys, Now just stop here for a while and I would ask you to roll back your memories to the size of data types.
The size of long is 64 bits and the float is just 32 bits.

I don’t think that the “long” number would be able to fit comfortably within a float variable which is obviously less than the size of long datatype.

How can this be regarded as a widening conversion?

I don’t know, if I am asking so silly. Anyway a doubt is a doubt. Somebody please throw light on this
[ September 02, 2005: Message edited by: Kalyana Sundaram ]

Only those who will risk going too far can possibly find out how far one can go !!!
Abhishek Jain
Greenhorn

Joined: Sep 02, 2005
Posts: 26
Hi Kalyana

Float is supporting Floating point representation i.e some part of memory assigned to float is used to store mantisaa and other for exponent.Taking an example not according to exact represntation but would give u an idea:

2500 = 0.25 * 10 power 4
i will store it as 25 in one part and 4 in some other part

so using 32 bit no we can store a wide range of no.
But we do have a problem here i.e Loss of Precesion ..
Yaa I agree loss of precision is there because mantisaa part is of fixed size.

I think this would have cleared ur doubt ........
else i am always there to help u out we can discuss more

Regards
Abhishek


SCJP <br />SCWCD <br />SCBCD <br />SCEA Preparing
Kalyana Sundaram
Ranch Hand

Joined: Mar 18, 2005
Posts: 94
Thanks for your answer.
Well, I do think that there are much behind this.
However this enough for just having an idea.

Come on, Lets explore JAVA !!!
sameer inamdar
Ranch Hand

Joined: Jul 04, 2005
Posts: 40

Come on, Lets explore JAVA !!!
--------------------
Only those who will risk going too far can possibly find out how far one can go !!!



Kalyana & Abhishek... I would love to be part of exploring java to maximum extend. But stuck with Microsoft and involved in analysis and design work. even delayed my exam.


Dream!!! Set Vision !! Transform Vision to Mission by Actions on Deadlines!.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A great doubt in Widening Numeric Conversions
 
Similar Threads
primitive type casting problem.........
Why does primitive conversion involving "char" always require explicit cast?
Widening conversion
Not able to retrieve files name s from a folder
primitive widening doubt