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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -