Consider following statement:
byte by = 5; //works fine
literal \'5\' is of type int and small enough to fit into a variable of type byt
In the integer version, the compiler knows that all the data in the number 5
can be stored in a byte
. No information is lost. That's not always true for floating point values. For example, 0.1f
isn't equal to 0.1d
.
Now for the example, you've given, the decimal value 5.5 is exactly represented in both float
and double
, so you could argue that in that case, no information is lost - but it would be pretty odd for the language specification to have to make this valid:
float f = 5.5;
but this invalid:
float f = 5.6;
The language specification is happy to talk about whether a number fits within the range of float
/double
(although even that isn't as simple as you might expect) but when it comes to whether a literal can be exactly represented, I don't think it ever goes into detail.