Research FLT_EVAL_METHOD
. This reports the intermediate floating-point math allowed.
printf("%d\n", FLT_EVAL_METHOD);
When this is non-zero, the 2 codes may have different output as printf("%f", (far-32)*5/9);
can print the result of (far-32)*5/9
using double
or float
math.
In the 2nd case, (far-32)*5/9);
is performed user float
or double
and then saved as a float
and then printed. Its promotion to a double
as part of a printf()
... argument does not affect the value.
For deeper understanding, print far, cel, (far-32)*5/9
with "%a"
and "%.17g"
for greater detail.
In both cases, far
is the float
value 0x1.8a6666p+6
or 98.599998474121094...
As I see it the first used double
math in printf("%f", (far-32)*5/9);
and the second used double
math too, yet rounded to a float
result from cel = (far-32)*5/9;
. To be certain we need to see the intermediate results as suggested above.
Avoid double
constants with float
objects. It sometimes makes a difference.
// float far = 98.6;
float far = 98.6f;
Use double
objects as a default. Save float
for select speed/space cases. @Some programmer dude.