i am preparing for
scjp 1.6 and while trying out some code experiments on primitive typcasting i found some unusual behaviour on floating point numbers.
can anyone help me explain whats happening here..
byte ca = (byte)128; // needs an explicit cast because 128 is 32 bit int.
ca = (byte) ca + 12; //explicit cast because evaluting exp is implicitly converted to 32 bit int.
the above code is understandable.
but in the following code
float m = (float) 23.6; // explicit cast because floating points are 64 bit doubles by default and works fine.
...........................................................................................................................................................................................................................
m = (float) m + 5.7; // error . .. why???
why does this line of code doesnt complile. i have given an explicit cast for converting the evaluated double to float. then too it shows an error.
may i know the reason for this behavoiur.
thanks.
regards.