Proposal for C2x
WG14 N2290

Title:

Addition of NANQ, NANS as NaN string representations

Author:

Rajan Bhakta

Date:

2018/08/02

Abstract: The *printf, strtod functions currently specify outputting NaN’s in forms such as NAN(S) or NAN(Q). This paper proposes a new allowable form, NANS, or NANQ to represent each value respectively.

Prior art: AIX XL Fortran and C/C++ as well as GCC on AIX emits NANS and NANQ.


 

 

NaN string output in the C standard specifies a form of case-insensitive NAN or NAN(…

This is a proposal to extend the permitted string representations of NaNs to include NANQ for quiet NaN’s and NANS for signaling NaN’s.

The motivation behind the change is to extend the formats allowed by the C standard to allow the AIX GCC and XL libraries to be conformant. Due to existing code using the existing formats on AIX, it is unlikely that implementation will change.

The benefits include allowing a wider number of possible string outputs for NaNs. This can also be a drawback however as it can complicate reading in or using those same strings as inputs since there is more variation. However, since floating point values as strings being read in do not have NAN as a prefix for any other type of value, this seems like it would not be a real drawback in practice. The other possible drawback is an extension of the previous one: If existing code relies on the “NAN(“ form (and hence already not fully portable since an implementation is allowed to have the “NAN” without an immediately following “(“ form), that code may need to change if the source of the input were to take advantage of the new leeway and emit NANQ/NANS.

If the committee agrees or wants to go ahead with this proposal, specific changes to the text of the standard (possibly incorporating expected C2X text from inclusion of Parts 1 and 2 of the floating point technical specification) will be provided in a future version of this proposal.

 

Expected changes:

nan*: 7.12.11.2

*printf format specifiers: 7.21.6.1#8

strtod: 7.22.1.3

wcstod: 7.29.4.1.1#3

Annex F: Disallow NANQ.

Optional: Annex F: Disallow NANS.