# (teach) about type conversion

Encountered in learning "in-depth understanding of computer systems".
The following code:
#include<stdio.h>
main()
{
int i=1e10;
printf("%d\n",i);
}
The result is the TMIN, and it changed to i= (int) 1e10, the result is 1410065408
Is this why?

Started by Bartley at February 01, 2016 - 6:24 PM

The maximum range is more than one int data can be represented by 1e10-2147483648*4, the results.

Posted by Roger at February 06, 2016 - 6:47 PM

The maximum range of more than int.

Posted by Nelson at February 07, 2016 - 7:15 PM

Beyond the scope will be truncated, equivalent to 0x7fffffff

Posted by Tracy at February 17, 2016 - 8:02 PM

Decided by the specific compiler.

Don't write even oneself also can not predict the result code！

Posted by Camille at February 22, 2016 - 8:28 PM

Why is the compiler.?
The 1e10 has exceeded the maximum integer int can say ah, is theoretically can be analyzed. Not to do?
2147483648*a+b,a,B is a positive integer
The integer value in the range of 32 bit operating system is -2147483648~2147483647, I is a forced conversion to integer, so the I values in this range.

Posted by Newman at November 08, 2016 - 12:13 PM

You can change at least three different companies and two different hardware platform under the C compiler.

Posted by Camille at November 11, 2016 - 1:12 PM

If no such conditions, what analysis

Posted by Newman at November 26, 2016 - 2:05 PM

Despite the compiler, on
int i=1e10;
Use the following three methods:
The maximum integer of the assignment to the I int types can express
The I = 1e10 in memory corresponding byte
The compiler error
I personally think that each of the truth.

Posted by Camille at December 03, 2016 - 2:47 PM

++

Posted by Jamie at December 17, 2016 - 3:28 PM

1e10 = 0x2540BE400
Truncation
= 0x540BE400=1410065408

The compiler
1e10 does not exceed the scope of the said long integer data, but this is a floating-point type double number.
Can accurately represent integer between 2^54..+2^54
void print_int()
{
int ill =(int)(long long )1e10;
printf ("%d\n",ill); //VC6:(Long long is replaced by LONGLONG)1410065408, VC10 1410065408,mingw : 1410065408
int i =(int)1e10;
printf ("%d\n",i);//VC6: 1410065408,VC10 : 1410065408,mingw: 2147483647
}

The conversion between the floating point and integer,
Because of that range, more than int of that range, different compiler takes a different approach.
VC6, VC10 take the cutoff, MinGW is the largest integer.

This is implementation related, don't write this dependence compiler implementation code, unless you want to follow the new standard.
PS:
1e10 is a floating-point constant, not an integer constant.

10000000000, Is the integer constant.
But this number exceeds a int representation of the range, need to use long long int.

Posted by Jessee at December 19, 2016 - 3:55 PM

Conversion between integer data, but is extended (a symbolic extension, unsigned 0 expansion), and the truncated in two ways.
The conversion between floating point and integer, may be related to the different.

PS:

1e10 this is the scientific notation,
C, C++ seems to be the only floating point numbers, it said,
Integer data, if not, said this method of constant.

Posted by Jessee at December 31, 2016 - 4:12 PM

Then why doesn't i=1e10 truncation, i= (int) 1e10 truncation.?

Posted by Bartley at January 05, 2017 - 4:34 PM

I=1e10 is not truncated, i= (int) 1e10 truncation.?

Because of different types, so you want to convert
But the maximum integer rounding and truncation, in two ways.

Each of the truth

Truncated rounded, the data has not changed, just because, data length is not enough, said no, excess loss.

Maximum can represent integers, because the data is too large, the maximum can represent integers, representing the data is relatively large, which in some cases is also very convenient.
At least not the positive integer, a negative integer.

How real operation, see the compiler, and standard.

I=1e10 is not truncated, i=(int)1e10? ?
Your compiler more offbeat.,
This is the type conversion, should agree to.

Posted by Jessee at January 07, 2017 - 6:04 PM

Top！

Posted by Camille at January 09, 2017 - 5:29 PM