/* This program illustrates the loss of significant digits that can occur when nearly equal quantities are subtracted. The results of this program are terribly inaccurate. */ #include #include using namespace std; float f( float x ) { return( (1.0F - cos(x)) / (x*x) ); } int main() { float x = 0.1; cout << x << ", " << f(x) << endl; x = 0.01; cout << x << ", " << f(x) << endl; x = 0.001; cout << x << ", " << f(x) << endl; x = 0.0001; cout << x << ", " << f(x) << endl; x = 0.00001; cout << x << ", " << f(x) << endl; cout << "\n\n"; system( "PAUSE" ); // This line is system dependent return( 0 ); }