Consider the following code:
#include <iostream>
int main()
{
double zero = 0;
const double ZERO = 0.;
std::cout << 0/zero << "\n"; // -nan
std::cout << 0/0. << "\n"; // nan
std::cout << 0/ZERO << "\n"; // nan
}
Why does 0/zero
produces -nan
, why it differs from 0/0.
and what is the meaning of -nan
?
Live demo here for clang. GCC gives -nan
for all these cases. Trying to compile with MSVC leads to complile error for const values and -nan
for variable.
Which compiler is the more correct by Standard in this case?