Recent MSVC versions don't seem to treat NAN as a constant anymore. The new definition appears to be (__ucrt_int_to_float(0x7FC00000)). The old one was (-(float)(((float)(1e+300 * 1e+300)) * 0.0F)).
This causes code like the following to fail to compile with error C2099: initializer is not a constant:
#include <math.h>
double x[] = { 1.0, NAN };
Unfortunately, I don't have direct access to MSVC and I am dealing with this through GitHub CI.
Questions:
- Is this a bug in MSVC or valid behaviour?
- What is a robust workaround that won't break the code with other compilers?
Apparently, MSVC also doesn't accept 0.0 / 0.0. The code double f() { return 0.0 / 0.0; } fails with error C2124: divide or mod by zero
NANmust be a constant expression. If it isn't, then that's a compiler/library bug.