float x = 226.0; if( ABS(x-226.0)>0.00000001 ){ printf("ajaja\n"); } #### perl -V:nvsize -V:nvtype nvsize='8'; nvtype='double'; #### /* gcc a.c */ #include #define ABS(A) ((A)>0?(A):(-(A))) int main(void){ float version = 2.26; float newversion = version + 0.01; printf("version=%f, newversion=%f\n", version, newversion); /* bliako's "check" */ printf("2.26*100=%.8f\n", 2.26*100); float x = 226.0; if( ABS(x-226.0)>0.00000001 ){ printf("bliako's check has ABS error\n"); } else {printf("bliako's check OK\n");} /* closer check: check the multiplied value against the hardcoded 226.0 */ /* as a 32bit float, the ULP(226.0) is (2**7)*(2**-23) = 2**-16 = 15.259e-6 = 1.5259e-5, so a 1 ULP error would be >1.525e-5, so also greater than 0.00000001 */ x = 2.26 * 100.0; printf("2.26*100=%.16f\n", x); if( ABS(x-226.0)>0.00000001 ){ printf("float-ULP check has ABS error\n"); } else {printf("float-ULP check OK\n");} /* but perl with nvtype=double requires a check against a c double, where the ULP(226.0) = 2.842e-14 */ double d = 2.26 * 100.0; printf("2.26*100=%.16lf\n", d); if( ABS(d-226.0)>=2.842e-14 ){ printf("double-ULP check has ABS error\n"); } else {printf("double-ULP check OK\n");} } #### version=2.260000, newversion=2.270000 2.26*100=226.00000000 bliako's check OK 2.26*100=226.0000000000000000 float-ULP check OK 2.26*100=225.9999999999999700 double-ULP check has ABS error