• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

A great doubt in Widening Numeric Conversions

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!!
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic