float 変数に実数が含まれているかどうかを C++ で確認する方法は?
例: -1.#IND000私の値
実数なのか上記のような数値なのかを判断する方法。
float 変数に実数が含まれているかどうかを C++ で確認する方法は?
例: -1.#IND000私の値
実数なのか上記のような数値なのかを判断する方法。
std::isnan
headerのような関数があります<cmath>
。
Visual Studio で '_isnan' を使用できます (float.h に含まれています)。
float T;
T=std::numeric_limits<double>::quiet_NaN(); //YOUR CALCS HERE!!
if (_isnan(T)) {
printf("error\n");
}
とても簡単な方法..
float a=3.9;
long b;
b=a;
if ((float)b==a)
cout<<"Non-real, i.e. integer";
else
cout<<"REAL";