01: #include <iostream>
02: #include <algorithm>
03: 
04: using namespace std;
05: 
06: /**
07:    Tests whether two floating-point numbers are 
08:    approximately equal.
09:    @param x a floating-point number
10:    @param y another floating-point number
11:    @return true if x and y are approximately equal
12: */
13: bool approx_equal(double x, double y)
14: {  
15:    const double EPSILON = 1E-14;
16:    if (x == 0) return fabs(y) <= EPSILON;
17:    if (y == 0) return fabs(x) <= EPSILON;
18:    return fabs(x - y) / max(fabs(x), fabs(y)) <= EPSILON;
19: }
20: 
21: int main()
22: {  
23:    double x;
24:    cout << "Enter a number: ";
25:    cin >> x;
26: 
27:    double y;
28:    cout << "Enter another number: ";
29:    cin >> y;
30: 
31:    if (approx_equal(x, y))
32:       cout << "The numbers are approximately equal.\n";
33:    else
34:       cout << "The numbers are different.\n";
35: 
36:    return 0;
37: }