4

Do the c++ standards define the behavior of casting a NaN from float to double or vice-versa, or such outcome is implementation-defined or undefined?

The architecture I'm pragmatically concerned with is x86-64 with GCC, but I'd appreciate a broader theoretical understanding.

davide
  • 2,082
  • 3
  • 21
  • 30

1 Answers1

4

There's nothing explicit in the C++ standard that addresses conversions of NaNs, so you have to rely on the standard conversions. In particular, floats can be promoted to double and the value is unchanged, and doubles converted to floats will have the same value if it can be represented in the smaller type. Since both types support a NaN, the value should stay a NaN.

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56