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

Long -> float

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
According the exam guide I am using, it is possible to covert an long value to a float value. They explain the other conversion saying 'widening' which means a 32 bit data type hold a 16 bit data type and so on. But the explanation for my question is not given.
So could you please explain how this is possible. Don't you need a cast to convert a 64 bit long to a 32 but float?
Thank you....
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason this is considered a widening conversion is that the range of possible float values is larger than the range of possible long values. Yes, you can lose precision in converting from long to float, but you don't lose "magnitude," so they decided to allow this conversion without a cast.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic