[ERROR] -1.#IND
printf를 MSDN에서 찾아보면
If the argument corresponding to a floating-point specifier is infinite, indefinite, or NaN, printf gives the following output.
Value | Output |
---|---|
+ infinity | 1.#INFrandom-digits |
– infinity | –1.#INFrandom-digits |
Indefinite (same as quiet NaN) | digit.#INDrandom-digits |
NAN |
digit.#NANrandom-digits |
이렇게 되어 있네요
실수를 프린트에서 찍을때
+무한은 1.#INF
-무한은 -1.#INF
정의되어 있지않은 숫자는 #IND
NAN(Not a Number)는 #NAN이라고 표시된답니다.
무한(Infinity)은 말 그대로 컴퓨터의 double로 표시할 수 있는 범위를 넘어간 큰수흘 의미 합니다.
미정의 숫자(Indefinite)는 루트(-1)처럼 정의할 수 없는 숫자를 의미합니다.
이런 에러가 발생했는 지를 찾기 위해서는 float.h에 있는 _isnan이나 _finite 함수를 이용할 수 있습니다. 다음 예를 참고하십시요
#include < float.h>
#include < math.h>
#include < stdio.h>
void testnumber(double val)
{
if(_isnan(val))
{
printf("%e은 숫자가 아닙니다.\n",val);
}else if(!_finite(val))
{
printf("%e은 유한 범위의 숫자가 아닙니다.\n",val);
}
else
printf("%e은 정상적인 숫자입니다.\n",val);
}
void main()
{
double val=1;
// indefinite
testnumber(sqrt(-1));
// infinity
for(int i=0;i<10;i++)
{
val=val*1000000000000000000000000000000000.0;
testnumber(val);
}
}