관계 연산자 3_5
- 부동 소수점의 경우 계산할때 오차가 발생할 수 있다.
- 회사에서 프로젝트를 진행할 때 이런 문제가 발생 한적이 있었다. 앱실론을 쓰는 방법을 생각 하였다면 더 좋을텐데 하는 아쉬움이 남는다. 좋은 강의였다.
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
int x, y;
cin >> x >> y;
cout << "your input Values ard : " << x << " " << y << endl;
if (x == y)
cout << "equal" << endl;
if (x != y)
cout << " NOT equal" << endl;
if (x > y)
cout << "x is greater than y" << endl;
if (x < y)
cout << "x is greater than y or eqqual to y" << endl;
if (x >= y)
cout << "x is less than or equal y" << endl;
double d1(100 - 99.99);
double d2(10 - 9.99);
const double epsilon = 1e-10;
cout << std::abs(d1 - d2) << endl;
if (std::abs(d1 - d2) < epsilon)
{
cout << "equal" << endl;
}
else
cout << "not equal" << endl;
return 0;
}