본문 바로가기
C++

floating point overflow 검사

by leo21c 2014. 8. 28.
SMALL

참고: http://www.cplusplusdevelop.com/47_23295818/


DBL_MAX, DBL_MIN은 C++은 <cfloat>에 define 되어 있고 C는 <float.h>에 define 되어 있다.

이것을 이용하면 된다.

C++의 <limits>에 정의된 std::numeric_limits를 이용해도 된다.

#include <iostream>
#include <cfloat>
#include <limits>

int main() 
{
    std::cout << DBL_MAX << std::endl;
    std::cout << std::numeric_limits<double>::max() << std::endl;

    return 0;
}


 1.79769e+308
 1.79769e+308


나는 아래와 같은 define을 하나 만들어서 사용을 했다.
#define CheckFloatingPoint(value) (value > DBL_MAX ||value < DBL_MIN ? true : false)


LIST

'C++' 카테고리의 다른 글

Visual Studio "he optimize pragma" 처리  (0) 2015.12.22
IME 선택된 언어 확인하기  (0) 2014.09.05
JSON Spirit: A C++ JSON Parser/Generator Implemented with Boost Spirit  (0) 2014.05.13
C++ Json Parser  (0) 2014.05.07
GetCurrentProcess function  (0) 2014.03.04