プロが教えるわが家の防犯対策術!

質問です。
C++でプログラムを実行したところ,
ごく希に-1.#IND00 という値が入っている変数がありました.
デバッグのため,値が-1.#IND00 となったらデバッグプリントを表示したいのですが、
どのようにやればよいでしょうか?
環境は.net 2003です。
ちなみに、
float fx = 0.0;
float r;
・・・・rに計算結果を格納
if(r == -2.0f/fx || r == 2.0f/fx || r == fx/fx || r == -fx/fx){
}としてみたところダメでした。
どなたかよろしくお願いします。

A 回答 (2件)

INDっては初めて見たので調べてみたのですが、infともNaNとも違うものなんでしょうか?



> if(r == -2.0f/fx || r == 2.0f/fx || r == fx/fx || r == -fx/fx){

if (_isnan(r) || _isinf(r))

ではダメですか?
あと、調べていてみつかったのですが vc++の場合
fpclassifyはありませんが _fpclassという関数があって、
これが同じような判定をしてくれるようです。

/* IEEE recommended functions */

_CRTIMP double __cdecl _copysign (double, double);
_CRTIMP double __cdecl _chgsign (double);
_CRTIMP double __cdecl _scalb(double, long);
_CRTIMP double __cdecl _logb(double);
_CRTIMP double __cdecl _nextafter(double, double);
_CRTIMP int __cdecl _finite(double);
_CRTIMP int __cdecl _isnan(double);
_CRTIMP int __cdecl _fpclass(double);

#define _FPCLASS_SNAN 0x0001 /* signaling NaN */
#define _FPCLASS_QNAN 0x0002 /* quiet NaN */
#define _FPCLASS_NINF 0x0004 /* negative infinity */
#define _FPCLASS_NN 0x0008 /* negative normal */
#define _FPCLASS_ND 0x0010 /* negative denormal */
#define _FPCLASS_NZ 0x0020 /* -0 */
#define _FPCLASS_PZ 0x0040 /* +0 */
#define _FPCLASS_PD 0x0080 /* positive denormal */
#define _FPCLASS_PN 0x0100 /* positive normal */
#define _FPCLASS_PINF 0x0200 /* positive infinity */

positive normal でも negative normal でも±0でもないのを
引っ掛ければよい?

参考URL:http://msdn2.microsoft.com/ja-jp/library/39s1cck …
    • good
    • 0

C だったら fpclassify とか isfinite みたいなマクロで処理できそうなんですけど, C++ で使えるかなぁ?

    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!