posted 18 years ago
Firstly, I would like to point out that it should be bits instead of bytes. long are double are 64 bits, float 32 bits...
Secondly, I am sure that the range of double and long is different. for long, which is 64 bits signed integer. it represents integer values ranging from -2^63 to 2^63-1. However, for double, 64 bits are separated into 3 parts, a sign bit, 12 bit of exponent(with a hidden bit), and 52 bits for fractions. thus, it represents floating numbers in the form of (sign)(fraction)*2^(exponent). if you think long as a huge meter rule, then double would be a bigger rule, with more numbers concentrated near zero and less numbers at both ends.
Thirdly, for narrowing, i think there are two cases to consider. you shouldn't simply look at the number of bits of the primary types. converting from a long to a int represents one case, as the range is reduced. converting from float to int is another case, as int cannot represent float numbers exactly, say (int)12.56 would give you 12 as the fraction part is truncated.
[ August 11, 2005: Message edited by: Lucas Jiang ]