double variable with wrong decimal cases - page 2

To add comments, please log in or register
whroeder1
17989
whroeder1  
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.

Icham Aidibe
11187
Icham Aidibe  
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. 

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

No it's not.

Icham Aidibe
11187
Icham Aidibe  
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               

Fernando Carreiro
3717
Fernando Carreiro  
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.

fxsaber
9305
fxsaber  
12
To add comments, please log in or register