double and float comparison [duplicate]
问题 This question already has answers here : Comparing float and double (3 answers) Closed 4 years ago . According to this post, when comparing a float and a double, the float should be treated as double. The following program, does not seem to follow this statement. The behaviour looks quite unpredictable. Here is my program: void main(void) { double a = 1.1; // 1.5 float b = 1.1; // 1.5 printf("%X %X\n", a, b); if ( a == b) cout << "success " <<endl; else cout << "fail" <<endl; } When I run the