double variable with wrong decimal cases - page 2

 
Icham Aidibe: It's unaesthetic, but it's expeditive and it works :-/

Since the maximum of an int is 2147483647 (0x7FFFFFFF) your code will never work and I'm not sure what you are trying to do.

 
whroeder1:

Since the maximum of an int is 2147483647 (0x7FFFFFFF) your code will never work and I'm not sure what you are trying to do.


Indeed it's converted as a double, but with no more decimals. 

 
Icham Aidibe: Indeed it's converted as a double, but with no more decimals.
   int k=1000000000000000000000000000000000000000000000000000000000000000000;

No it's not.

 
whroeder1:

No it's not.


I tell you it is.

integer constant is too big, so it was converted into double    
0 error(s), 1 warning(s), compile time: 2117 msec               

 
Icham Aidibe: I tell you it is.

It is not, and here is why!

The constant value is converted into a "double", but then it is reconverted/cast into an "int" again in order to be saved in the variable "k".

There is in fact two warnings (not just one):

integer constant is too big, so it was converted into double
truncation of constant value

The end result, is that "k" will be left with the value of "-2147483648".

Had you printed your values, you would have seen that.