Tushar Goel wrote:
Yeah right Armitage but why it is working for int case? By default integer literal are int and of 4 byte and i am assigning it to the byte which is 1 byte and it works well. It should also give same error as float is giving..
Are you getting my point??
Values of the integral types byte, short, int, and long can be created from int literals.
Tushar Goel wrote:
Can you please throw some light on this:
Values of the integral types byte, short, int, and long can be created from int literals? << I am unable to get this statement..
Do you mean that we use int literals in byte,short.. ? If that your mean that i have tried to assigned int value to the byte it give precision loss error..
Tushar Goel wrote:but as you already mentioned "compiler is smart enough to figure out that a downcast definitely won't lose precision" is there any particular condition in which compiler think like tis way.
Stuart A. Burkett wrote:
Are you asking why the compiler is clever enough to know that 10 will fit into a byte variable, but not clever enough to know that 10.0 can be represented accurately in a float variable ?
If so, then it is probably because the values that will fit into a byte are finite and contiguous (-127 to 128) and so easy to verify.
But the values that will fit into a float are not contiguous - 10.0, 10.5 and 11.0 can be accurately represented by a float or double, but the representation of 10.1 (for example) will be less accurate in a float than it is in a double.
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|