Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

Typing diary

Inf, Nan 본문

C, C++

Inf, Nan

Jcon 2022. 11. 16. 14:28

Inf

infinity, 무한대를 표현할 수 있다.

#define INFINITY   ((float)(_HUGE_ENUF * _HUGE_ENUF))

//#define _HUGE_ENUF  1e+300  // _HUGE_ENUF*_HUGE_ENUF must overflow

 

 

#include <iostream>

using namespace std;

int main()
{
	//#define ULLONG_MAX    0xffffffffffffffffui64
	cout << (ULLONG_MAX < INFINITY) << endl;  

       //#define DBL_MAX       1.7976931348623158e+308 
	cout << (DBL_MAX < INFINITY) << endl;
}

이와 같은 매우 큰 숫자와 비교해도 항상 INFINITY가 더 큰 숫자로 계산된다.

 

 

메모리에는 다음과 같이 저장된다.

#include <iostream>
#include <bitset>

using namespace std;

int main()
{
	float f = INFINITY;
	float* pf = &f;	
	
	cout << bitset<32>(*(int*)pf) << endl;
	cout << std::hex << (*(int*)pf);
}

 


Nan 

Nan(Not A Number), 수가 아님을 나타낸다 ( ∞-∞ , ∞+∞, 0*∞, 0/0 ...)

#define NAN        ((float)(INFINITY * 0.0F))

 

메모리에는 다음과 같이 저장된다.

#include <iostream>
#include <bitset>

using namespace std;

int main()
{
	float f = NAN;
	float* pf = &f;	
	
	cout << bitset<32>(*(int*)pf) << endl;
	cout << std::hex << (*(int*)pf);
}

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

에디안  (0) 2022.11.16
함수 포인터  (0) 2022.08.17
파일입출력 fwrite,fread  (0) 2022.08.17
상속, 가상함수, 순수가상함수  (0) 2022.08.17
조정자(Manipulator)  (0) 2022.08.17