The reason the expression is applied to double precision is because the specified literals are double precision values ββby default. If you specify the literals used in the equation as a float, the expression will return a float. Consider the following code (Mac OS X using gcc 4.01).
#include <stdio.h> int main() { float celsius; float fahr = 212; printf("sizeof(celsius) ---------------------> %d\n", sizeof(celsius)); printf("sizeof(fahr) ------------------------> %d\n", sizeof(fahr)); printf("sizeof(double) ----------------------> %d\n", sizeof(double)); celsius = (5.0f/9.0f) * (fahr-32.0f); printf("sizeof((5.0f/9.0f) * (fahr-32.0f)) --> %d\n", sizeof((5.0f/9.0f) * (fahr-32.0f))); printf("sizeof((5.0/9.0) * (fahr-32.0)) -----> %d\n", sizeof((5.0/9.0) * (fahr-32.0))); printf("celsius -----------------------------> %f\n", celsius); }
Output:
sizeof(celsius) ---------------------> 4 sizeof(fahr) ------------------------> 4 sizeof(double) ----------------------> 8 sizeof((5.0f/9.0f) * (fahr-32.0f)) --> 4 sizeof((5.0/9.0) * (fahr-32.0)) -----> 8 celsius -----------------------------> 100.000008
source share