Why does NaN - NaN == 0.0 with the Intel C++ Compiler? -
it well-known nans propagate in arithmetic, couldn't find demonstrations, wrote small test:
#include <limits> #include <cstdio>  int main(int argc, char* argv[]) {     float qnan = std::numeric_limits<float>::quiet_nan();      float neg = -qnan;      float sub1 = 6.0f - qnan;     float sub2 = qnan - 6.0f;     float sub3 = qnan - qnan;      float add1 = 6.0f + qnan;     float add2 = qnan + qnan;      float div1 = 6.0f / qnan;     float div2 = qnan / 6.0f;     float div3 = qnan / qnan;      float mul1 = 6.0f * qnan;     float mul2 = qnan * qnan;      printf(         "neg: %f\nsub: %f %f %f\nadd: %f %f\ndiv: %f %f %f\nmul: %f %f\n",         neg, sub1,sub2,sub3, add1,add2, div1,div2,div3, mul1,mul2     );      return 0; } the example (running live here) produces expect (the negative little weird, kind of makes sense):
neg: -nan sub: nan nan nan add: nan nan div: nan nan nan mul: nan nan msvc 2015 produces similar. however, intel c++ 15 produces:
neg: -nan(ind) sub: nan nan 0.000000 add: nan nan div: nan nan nan mul: nan nan specifically, qnan - qnan == 0.0.
this... can't right, right? relevant standards (iso c, iso c++, ieee 754) this, , why there difference in behavior between compilers?
the default floating point handling in intel c++ compiler /fp:fast, handles nan's unsafely (which results in nan == nan being true example). try specifying /fp:strict or /fp:precise , see if helps.
Comments
Post a Comment