posted 23 years ago
Hi,
1) While promoting the float value 12.31 to double it actually becomes 12.3100004196167 (!!! well this is bcoz of the way these nos are represented ) which is slightly larger that 12.31.
so
double d = 12.31;
float f = 12.31F; // ( cast to double makes it 12.3100004196167 )
System.out.println(d%f);
gives 12.31 ( d < f ) .. so floating point remainder becomes 12.31
whereas
System.out.println(f%d); gives the extra .0000004196167 )
2. Guess thats bcoz simple assignment is done in three steps
a) The LHS is evaluated to ptoduce a variable ( already a variable in this case )
b) the value of the RHS is evaluated ( == 7 ) .. the Right hand expression also makes the value of a to be 8 ..
c) the value of the RHS( 7 ) is assigned to the LHS. ( thus we assign 7 to a again )
cheers,
vivek