| Author |
float to long typecasting
|
Sandeep Kumar.
Greenhorn
Joined: Jul 23, 2008
Posts: 9
|
|
Hi
i don't know how java stores floating point numbers in memory.(distribution of absolute and fraction digits)
a long takes 8 byte while a float takes 4 bytes only so why can't we typecast a float to a long implicitly. why widening isn't followed here in this case
and why a long can be type casted to a float implicitly while long takes 4 bytes more than float so there must be a loss of precision in this case; still it is allowed.
|
SCJP 6
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Whether casting can be done implicitedly depends on the range -- not on the size in bytes or the precision. And since the range of the float is larger than the range of the long, a long can be casted to a float implicitedly, even though you may lose precision by doing so.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
|
|
subject: float to long typecasting
|
|
|