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