/* prog1a.c -- Determine Machine Epsilon Written Feb 20, 2001 by Eric Olson for Mathematics 483 For more information see Step 3 in First Steps in Numerical Analysis, 2nd Edition, by Hosking, Joe, Joyce and Turner. */ #include #include #define REAL double #define Rfmt "%lg" static REAL x; REAL bisect1(REAL a,REAL b){ REAL delta,deold=a; for(;;){ REAL r1; delta=(a+b)/2.0; if(deold==delta) break; r1=x+delta; if((REAL)r1==(REAL)x) a=delta; else b=delta; deold=delta; } return a; } main(){ while(scanf(Rfmt,&x)==1){ REAL d1=bisect1((REAL)0.0,x>0.0?x:-x); printf("x=" Rfmt " d1=" Rfmt "\n",x,d1); } }