1

here a little test code:

float zeroF = 0.f;
float naNF = 0.f / zeroF;
float minimumF = std::min(1.0f, naNF);
std::cout << "MinimumF " << minimumF << std::endl;

double zeroD = 0.0;
double naND = 0.0 / zeroD;
double minimumD = std::min(1.0, naND);
std::cout << "MinimumD " << minimumD << std::endl;

I executed the code on VS2013.

On precise model (/fp:precise) the outputs are always "1";

On fast model (/fp:fast) the outputs will be "Nan" (-1.#IND) if optimization is enabled (/O2) and "1" if optimization is disabled (/Od).

First, what should be the right output according to IEEE754 ? (I read the docs and googled different articles like: What is the rationale for all comparisons returning false for IEEE754 NaN values?, and it seems that the right output should by Nan and not 1 but maybe I am wrong.

Secondly, how the fast model optimization here changes so drastically the output?

Community
  • 1
  • 1
  • I suspect that /fp:fast is similar to -ffast-math in GCC, right? If so, that option allows the compiler to use optimizations that violate the IEEE754 standard, resulting in the behaviour that you observe. An interesting read on that topic can be found here: http://pointclouds.org/news/2011/08/29/ffast-math/ (Not posting as an answer since I don't know the details of IEEE754...) – anderas Jun 11 '15 at 09:28
  • If I understood right the assembly output, it seems that on precise, the CMOVBE instruction is used and on fast the CMOVAE instruction is used for the floats... I do not know how they differ... – Mathieu Wolf Jun 11 '15 at 09:56

0 Answers0