// Andrew Taylor - andrewt@unsw.edu.au // 6/3/2017 // Demonstrate approximate representation of reals // producing error. // sometimes if we subtract two approximations which are very close together // we can canb get a large relative error // // correct answer if x == 0.000000011 (1 - cos(x)) / (x * x) is very close to 0.5 // code prints 0.917540 which is wrong by a factor of almost two #include #include int main(void) { double x, y; x = 0.000000011; y = (1 - cos(x)) / (x * x); printf("correct answer = ~0.5 but y = %lf\n", y); return 0; }