numeric_limits 클래스
template <class Type>
class numeric_limits
epsilon
함수는 1과 데이터 형식에 대해 나타낼 수 있는 1보다 큰 가장 작은 값 사이의 차이를 반환
// numeric_limits_epsilon.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The difference between 1 and the smallest "
<< "value greater than 1" << endl
<< "for float objects is: "
<< numeric_limits<float>::epsilon( ) << endl;
cout << "The difference between 1 and the smallest "
<< "value greater than 1" << endl
<< "for double objects is: "
<< numeric_limits<double>::epsilon( ) << endl;
cout << "The difference between 1 and the smallest "
<< "value greater than 1" << endl
<< "for long double objects is: "
<< numeric_limits<long double>::epsilon( ) << endl;
}
결과
The difference between 1 and the smallest value greater than 1
for float objects is: 1.19209e-007
The difference between 1 and the smallest value greater than 1
for double objects is: 2.22045e-016
The difference between 1 and the smallest value greater than 1
for long double objects is: 2.22045e-016
사용 예시
float f_tmp;
if(fabsf(f_tmp) < std::numeric_limits<float>::epsilon()) return;
'프로그래밍 언어 > C++' 카테고리의 다른 글
[C] open, close, read 함수에 대하여 (0) | 2023.09.17 |
---|---|
[C] 이스케이프 문자(Escape Character) (0) | 2023.09.16 |
[C] 쓰레기값과 초기화 (0) | 2023.09.16 |
[C++] sort , stable_sort (0) | 2023.09.16 |
[C] gets 함수는 사용하지 말아야 한다. (0) | 2023.09.10 |