Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A great doubt in Widening Numeric Conversions

 
Kalyana Sundaram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Abhishek Jain
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kalyana Sundaram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic