/* This is another example meant to illustrate the loss of significant digits that may occur when subtracting nearly equal quantities. */ #include #include using namespace std; float f1( float x ) { return( sqrt( x + 1.0F ) - 1.0F ); } float f2( float x ) { return( x / ( sqrt( x + 1.0F ) + 1.0F ) ); } int main() { float x = 1.2345678e-5; cout.precision(8); // This sets the number of digits to be displayed cout << " x = " << x << "\n\n"; cout << "f1(x) = " << f1(x) << "\n"; cout << "f2(x) = " << f2(x) << endl; cout << "\n\n"; system( "PAUSE" ); // This line is system dependent return( 0 ); }