This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes why long data type is type cast into float first while long takes 8 byte and float takes 4 byte?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why long data type is type cast into float first while long takes 8 byte and float takes 4 byte??" Watch "why long data type is type cast into float first while long takes 8 byte and float takes 4 byte??" New topic
Author

why long data type is type cast into float first while long takes 8 byte and float takes 4 byte??

viki Bhardwaj
Ranch Hand

Joined: Nov 07, 2011
Posts: 74

Hi Everybody!
I am a bit confused that a long type takes 8 byte of space and float type takes 4 byte then how it is possible to type cast a long type into float first..
as i know that if i have two method like-
void show(float f)
void show(double d)
and if i try to call show() method by passing a long type value then it look for exact match if not found then it implicit type cast into float and give the result as float value...

please explain it......i am confused..........
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3615
    
  14

A numeric primitive type is wider than another not if it can store more information, but if its range is bigger than the other type's range.

long has values up to 2^63 -1
float has values up to about: 3.4 * 10^38

Float is about 74,000,000 trillion times wider than long is. It's just not really good at representing values exactly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why long data type is type cast into float first while long takes 8 byte and float takes 4 byte??