On Sat, 7 Aug 2021, Stefan Kanthak wrote: > Joseph Myers <jos...@codesourcery.com> wrote: > > You should be looking at TS 18661-3 / C2x Annex F for sNaN handling; > > I'll do so as soon as GCC drops support for all C dialects before C2x! > > Unless you use a time machine and fix the POSIX and ISO C standards > written in the past you CAN'T neglect all software written before C2x > modified sNaN handling that relies on the documented behaviour at the > time it was written.
Pre-C2x versions of C don't cover signaling NaNs at all; they use "NaN" to mean "quiet NaN" (so signaling NaNs are trap representations). Software written before C2x thus can't rely on any particular sNaN handling. The POSIX description of signaling NaNs ("On implementations that support the IEC 60559:1989 standard floating point, functions with signaling NaN argument(s) shall be treated as if the function were called with an argument that is a required domain error and shall return a quiet NaN result, except where stated otherwise.") is consistent with C2x as regards trunc (sNaN) needing to return a quiet NaN with INVALID raised. The problems are (a) POSIX fails to "state otherwise" for the cases (e.g. fabs, copysign) where a signaling NaN argument should not result in a quiet NaN with INVALID raised (as per IEEE semantics for those operations) and (b) the POSIX rule about setting errno to EDOM when (math_errhandling & MATH_ERRNO) is nonzero is inappropriate for sNaN arguments (incompatible with the normal approach of generating INVALID and a quiet NaN by passing NaN arguments through arithmetic) and the C2x approach of being implementation-defined whether an sNaN input is a domain error is more appropriate. -- Joseph S. Myers jos...@codesourcery.com