[英]Can someone explain to me why there is an inequality test with the same operands in the following code from LLVM?
我的同事向我展示了LLVM源代碼中的以下宏:
#define IMPLEMENT_UNORDERED(TY, X,Y) \
if (TY->isFloatTy()) { \
if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \
return Dest; \
} \
} else if (X.DoubleVal != X.DoubleVal || Y.DoubleVal != Y.DoubleVal) { \
Dest.IntVal = APInt(1,true); \
return Dest; \
}
以下是他們使用此宏的方式:
static GenericValue executeFCMP_UEQ(GenericValue Src1, GenericValue Src2,
Type *Ty) {
GenericValue Dest;
IMPLEMENT_UNORDERED(Ty, Src1, Src2)
return executeFCMP_OEQ(Src1, Src2, Ty);
}
您可以在下面看到GenericValue的定義:
struct GenericValue {
union {
double DoubleVal;
float FloatVal;
PointerTy PointerVal;
struct { unsigned int first; unsigned int second; } UIntPairVal;
unsigned char Untyped[8];
};
APInt IntVal; // also used for long doubles
GenericValue() : DoubleVal(0.0), IntVal(1,0) {}
explicit GenericValue(void *V) : PointerVal(V), IntVal(1,0) { }
};
我的問題是為什么宏內部存在以下不等式測試:
X.FloatVal != X.FloatVal
我猜他們測試NaN(不是數字):如果x
有NaN值, x != x
得到true
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.