c - Why do two calculations give different answers? -


#include<stdio.h>  #define pi1 3.141  const float pi = 3.141;  int main()     {         printf("%f %f",4*10*pi, 4*10*pi1);   } 

output (on machine) 125.639999 125.640000

pi1 preprocessor symbol , replaced textually double.

pi float constant initialized double, , lose precision bits (see ieee754 specs).

for more details, pi float in fact stored 0x40490625 3.1410000324249267578125. pi1 stored 0x400920c49ba5e354, 3.1410000000000000142108547152


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -