#include #include int main() { int i; // double x = 0.15 / 3. * (2.1 + 7.9), y = 1.0 / 3.0 * 1.5; // double x = 0.15 / 3. * 10.0, y = 1.0 / 3.0 * 1.5; double x = 0.4 * 1.2 / 1.1, y = 0.4 / 1.1 * 1.2; unsigned char *ptr; if (x - y) printf("not equal\n"); printf("%f (%.17f)\n", x, x); printf("%f (%.17f)\n", y, y); printf("This is IEEE 754 64bit double\n"); printf("Use online calculator to evaluate\n"); printf(" http://babbage.cs.qc.cuny.edu/IEEE-754.old/64bit.html\n"); ptr = (unsigned char *) &x; for (i=7; i>=0; i--) printf("%02x", ptr[i]); printf("\n"); ptr = (unsigned char *) &y; for (i=7; i>=0; i--) printf("%02x", ptr[i]); printf("\n"); system("pause"); return 0; } /* VC2010, 32bit XP, cl floatingComparison.cpp GCC 4.8.1, 32bit XP, g++ floatingComporison.cpp -o floatingComparison.exe not equal 0.500000 (0.49999999999999994) 0.500000 (0.50000000000000000) This is IEEE 754 64bit double Use online calculator to evaluate http://babbage.cs.qc.cuny.edu/IEEE-754.old/64bit.html 3fdfffffffffffff 3fe0000000000000 --------------------------------- */