In the C programming language, the floating-point constant is a double type by default
therefore 3.1415 is a double type unless the suffix 'f' or 'F' is used to indicate a float type.
I assume that const float pi = 3.1415 will raise a warning, but not really.
when I try to use them under gcc using -Wall:
float f = 3.1415926; double d = 3.1415926; printf("f: %f\n", f); printf("d: %f\n", d); f = 3.1415926f; printf("f: %f\n", f); int i = 3.1415926; printf("i: %d\n", i);
result:
f: 3.141593 d: 3.141593 f: 3.141593 i: 3
the result (including the double variable) obviously loses accuracy, but compiles without warning.
so what did the compiler do with this? or didn’t I understand something?
source share