- C++相談室 part150
40 :デフォルトの名無しさん[sage]:2020/03/29(日) 11:22:58.32 ID:sawiSEmu - >>35
std::numeric_limits<T>::is_iec559 (IEEE 754) の場合は NaN!=NaN に定まる模様。 https://stackoverflow.com/questions/38798791/nan-comparison-rule-in-c-c > I read the IEEE-754 rules on NaN, which states: >> The comparisons EQ, GT, GE, LT, and LE, when either or both operands is NaN returns FALSE. >> The comparison NE, when either or both operands is NaN returns TRUE. C++の規定はこう。 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/n4849.pdf [expr.eq] (C++14でも同じ https://timsong-cpp.github.io/cppwp/n4140/expr.eq#5 ) > If two operands compare equal, the result is true for the == operator > and false for the != operator. If two operands compare unequal, > the result is false for the == operator and true for the != operator. > Otherwise, the result of each of the operators is unspecified. これだけなら「equalでもunequalでもない」として結果を不定とする実装もあり得る。 ただしCの規定には以下のものがある。 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2454.pdf Equality operators > The == (equal to) and != (not equal to) operators are ... > For any pair of operands, exactly one of the relations is true. これによれば NaN==NaN, NaN!=NaN を両方 false とするCの実装は許されない。 わざわざこれに反するようなC++の実装が作られる理由は無さそうだし、受け入れられることも無さそう。
|