/*************************************/ /* Computes the machine epsilon */ /*************************************/ #include #include int main() { float f1=1.0,f2,epsf; double d1=1.0,d2,epsd; printf( "\ncurrent single Epsilon, 1 + current single Epsilon\n" ); do { epsf=f1; f1/=2; f2=1.0+f1; printf( " %G\t%.20f\n", epsf, f2 ); /* If next epsilon yields <=1, then break, because current epsilon is the machine epsilon. */ } while (f2 > 1.0); printf( "\n\n Single Epsilon is %g\n", epsf ); printf( "\n\n FLT_EPSILON is %g\n", FLT_EPSILON); printf( "\ncurrent double Epsilon, 1 + current single Epsilon\n" ); do { epsd=d1; d1/=2; d2=1.0+d1; printf( " %G\t%.20f\n", epsd, d2 ); /* If next epsilon yields <=1, then break, because current epsilon is the machine epsilon. */ } while (d2 > 1.0); printf( "\n\n Double Epsilon is %g\n", epsd ); printf( "\n\n DBL_EPSILON is %g\n", DBL_EPSILON); return 0; }