]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add C2X _PRINTF_NAN_LEN_MAX
authorJoseph Myers <joseph@codesourcery.com>
Thu, 30 Sep 2021 20:53:34 +0000 (20:53 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Thu, 30 Sep 2021 20:53:34 +0000 (20:53 +0000)
C2X adds a macro _PRINTF_NAN_LEN_MAX to <stdio.h>, giving the maximum
length of printf output for a NaN.  glibc never includes an
n-char-sequence in its printf output for NaNs, so the correct value
for glibc is 4 ("-nan" or "-NAN"); define the macro accordingly.

This patch makes the macro definition conditional on __GLIBC_USE
(ISOC2X), as is generally done with features from new standard
versions.  The name is in the implementation namespace for older
standards, so it would also be possible to define it unconditionally.

Tested for x86_64.

NEWS
libio/stdio.h
manual/stdio.texi

diff --git a/NEWS b/NEWS
index a923bd644d470bbf3973b6342cde7234de30b557..614b21e471067de2e09ded4cccdcf2274c93f1de 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,8 @@ Major new features:
 * The exp10 functions in <math.h> now have a corresponding type-generic
   macro in <tgmath.h>.
 
+* The ISO C2X macro _PRINTF_NAN_LEN_MAX has been added to <stdio.h>.
+
 Deprecated and removed features, and other changes affecting compatibility:
 
 * The r_version update in the debugger interface makes the glibc binary
index 497da016ffa2e2302982fe33a251be9a609c843d..0a5c76b552b8f0698f8ea30ac29cd9dd33c34ffc 100644 (file)
@@ -133,6 +133,12 @@ typedef __fpos64_t fpos64_t;
 #include <bits/stdio_lim.h>
 
 
+#if __GLIBC_USE (ISOC2X)
+/* Maximum length of printf output for a NaN.  */
+# define _PRINTF_NAN_LEN_MAX 4
+#endif
+
+
 /* Standard streams.  */
 extern FILE *stdin;            /* Standard input stream.  */
 extern FILE *stdout;           /* Standard output stream.  */
index fd7ed0cedc7c1a5950b0fdc5c09c5f5c4f702d7e..1d235be68dbc7d4f7ad3a13c3f725f3c8cee2bc9 100644 (file)
@@ -2108,7 +2108,10 @@ If the value to be printed represents infinity or a NaN, the output is
 @w{[@code{-}]@code{inf}} or @code{nan} respectively if the conversion
 specifier is @samp{%a}, @samp{%e}, @samp{%f}, or @samp{%g} and it is
 @w{[@code{-}]@code{INF}} or @code{NAN} respectively if the conversion is
-@samp{%A}, @samp{%E}, or @samp{%G}.
+@samp{%A}, @samp{%E}, or @samp{%G}.  On some implementations, a NaN
+may result in longer output with information about the payload of the
+NaN; ISO C2X defines a macro @code{_PRINTF_NAN_LEN_MAX} giving the
+maximum length of such output.
 
 The following flags can be used to modify the behavior: