• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 74
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..........
 
Saloon Keeper
Posts: 15524
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic