Search code examples
cfloating-pointnanieee-754c11

Why quiet NaN is not always quiet and may lead to raising of floating-point exceptions?


Context: the quiet NaN is not always quiet and may lead to raising of floating-point exceptions.

Code sample & invocations: see QNAN passed into C standard library functions (ex. llrintf): not clear whether FP exceptions are raised or not.

Details: the quiet NaN is quiet only in some cases:

  • arithmetic operations (C11, 5.2.4.2.2, p3)
  • unordered-quiet predicates in Table 5.3 (IEEE 754, 5.11, p4)
  • etc. (you may precise in comments)

Question: Why the creators of C standard have made quiet NaN not always quiet?


Solution

  • Why the creators of C standard have made quiet NaN not always quiet?

    As far as I can determine, the C standard does not anywhere specify, directly or indirectly, that there is a circumstance where usage of a quiet NaN must cause a FP exception to be raised. Thus, the standard committee has not made quiet NaN fail to always be quiet.

    The committee also has not required that usage of quiet NaNs must never cause a FP exception to be raised, of course, and that allows for (but does not require) cases wherein quiet NaNs do cause FP exceptions. But that does not contradict the previous paragraph.

    The standard is designed to support implementation on a wide variety of hardware, and to that end, many details of FP behavior are left unspecified. This allows C to be implemented naturally, in terms of the native FP behavior of the host machine (where that exists). Among other things, C does not specify FP representation, so what the standard means when it talks about NaNs, quiet or otherwise, is more general than what IEEE 754 means by the same terms.