One: Cause
(1) Recently contacted type conversion, such as signed number to unsigned number----int converted to unsigned int type, MO to take for granted conversion;
(2) to make up for your first learning computer composition principle, the original code, anti-code, the complement is more easily confused concept;
(3) Double type of how to determine whether a parameter is zero, direct = = 0.0, it seems that can be----indeed sometimes, but sometimes not, this is why.
(4) Knowledge Supplement: in int signed number: 0x80000000 (except the sign bit is 1, all the rest is 0)----the smallest number ( -2147483648 i.e. -2^32);
0x80000001----Times minimum number (-2147483647 i.e. -2^32-1);
0xFFFFFFFE ( -2); 0xFFFFFFFF (together with the sign bit is all 1)-----The largest negative integer (-1);
0x7ffffff (except that the sign bit is 0, all the rest is 1)----The maximum number (2147483647 is 2^32-1)
(5) The question is how much is 0x80000000-1. (Maximum number of 0x7ffffff); 0X7FFFFFF + 1 How much is it? (Minimum number of 0x80000000);
How is the 0x80000000-1 calculated? (0x80000000 + 0xFFFFFFFF, first to change the subtraction to addition, that is, positive 1 change to negative 1, overflow bit out)
Two: See the Truth
(1) Code
[CPP] View Plain copy print? int min_int = 0x80000000; int int_fu1 = 0xFFFFFFFF; int max_int = 0x7fffffff; cout << "min _int= "<< min_int <<" \tmin_int-1= "<< min_int-1 << " \ t (UN Signed) Min_int = "<< (unsigned int) min_int << endl; cout <<" Int_ fu1= "<< int_fu1 <<" \tint_fu1-1= "<< int_fu1-1 << " \ t (uns igned) int_fu1 = "<< (unsigned int) int_fu1 << endl; cout <<" 0x7ff fffff= "<< 0x7FFFFFFF <<" \t0x7fffffff-1= "<< 0x7FFFFFFF +1 << endl; &nb sp; double Test_zero = 1.333333; cout << (test_zero-1.3333334) < < endl; if (0 = = (test_zero-1.3333334)) cout << "(test_zero-1.3333334) =" << (test_zero-1.3333334) << "\t0 = = (test_zero-1.3333334)" << endl; else if (test_ zero-1.3333334) >-1e-6 && (test_zero-1.3333334) < 1e-6) cout << "(test_zero-1.3333334) =" << (test_zero-1.3333334) << & nbsp; "\ t (test_zero-1.3333334) >-1e-6 && (test_zero-1.3333334) < 1e-6" << endl;
int min_int = 0x80000000;
int int_fu1 = 0xFFFFFFFF;
int max_int = 0x7FFFFFFF; cout << "min_int=" << min_int << "\tmin_int-1=" << min_int-1 << "\ t (unsigned) Min_int
= "<< (unsigned int) min_int << Endl; cout << "int_fu1=" << int_fu1 << "\tint_fu1-1=" << int_fu1-1 << "\ t (unsigned) INT_FU1
= "<< (unsigned int) int_fu1 << Endl;
cout << "0x7fffffff=" << 0x7FFFFFFF << "\t0x7fffffff-1=" << 0x7FFFFFFF +1 << Endl;
Double Test_zero = 1.333333;
cout << (test_zero-1.3333334) << Endl;
if (0 = = (test_zero-1.3333334)) cout << "(test_zero-1.3333334) =" << (test_zero-1.3333334) <<
"\t0 = = (test_zero-1.3333334)" << Endl; else if ((test_zero-1.3333334) >-1e-6 && (test_zero-1.3333334) < 1e-6) cout << "(test_zero-1.333 3334) = "<< (test_zero-1.3333334) << "\ t (test_zero-1.3333334) >-1e-6 && (test_zero-1.3333334) < 1e-6" << en dl
(2) Result diagram
(3) Analysis of results
floating-point numbers (double) cannot be used = = and! = because floating-point numbers are stored in memory by precision (with the maximum precision bit number, you can also set the precision bit number), so you see the 3.12 may have been 3.123456 to take the decimal point after 2 bit accuracy, so when with Another 3.12 comparisons may occur in a number of cases, if the other 3.12 is actually 3.121111 take the decimal point after the 2 bit precision, then two number you look equal, actually is unequal.
So you do it. When comparing floating-point numbers, they are generally subtracted and then compared to a precision. But sometimes, comparisons can really pass, because that's a fluke.
you can see the minimum and maximum numbers followed by a step away.
the knowledge supplement of the inverse code complement of the original code
(4) Related learning C + + floating pointer and field pointer two level pointer I'm not a qualified programmer once again feel his ignorance
C + + deep copy and shallow copy Interview Frequently asked C-language variables in memory distribution (VC6.0)