I have a C++ cross-compiler. It produces some floating point code that, at runtime, may generate NaN. On my host platform I want to prepare target-aware "gold" testing results. These will be compared against printf output generated on the target platform, notably involving those floating results.
On any x86 platform, printf("%g\n", 0.0 / 0.0);
produces -nan
.
On just about any other platform it produces nan
. This is because IEEE 754 does not specify the sign bit for NaN. Intel chose to set the sign bit to one, every other architecture of which I am aware sets it to zero.
std::quiet_NaN
is not useful. It always returns a bit pattern with a zero sign bit on all platforms.
I was hoping that GCC's "Target Description Macros and Functions" would have something appropriate, but, so far, I have found nothing.