From patchwork Thu Sep 30 20:09:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1535043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HL4DV6HKwz9s0r for ; Fri, 1 Oct 2021 06:12:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9CA8F385842D for ; Thu, 30 Sep 2021 20:12:55 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 8203C3857C52 for ; Thu, 30 Sep 2021 20:09:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8203C3857C52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: /xltGK5Z1CoJiyw63NCxM47+cYIGryWUOIA4vKYTh+4dACnlai7im9xU2HWixe87uIa5b+Z8UL 2HAmFd9gvm5Ca3G/zrEczbkbLV0zXFIKd9oZdB5WjIMBGKKtwn3JzdPNjm4//9fYS7EZ/QXqqu oOhJHLGrJMoLl1kFPRK5JVMAseQIMXEPd8hTJhj8RWjNxyyM3Jd4q7CIw9k5EZsPqW9ZnpcYwi AiYALHVKvLEy1fuHxrPtJyyKHN+A2n9L0q7UmEC5an/Ux+GnkBQTyIDpW56i9yPhj+pIq1BBda Ya9Q7cu7G1uPu3qMZX095pZL X-IronPort-AV: E=Sophos;i="5.85,336,1624348800"; d="scan'208";a="66581230" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 30 Sep 2021 12:09:20 -0800 IronPort-SDR: gslrUoq2fFiUvOGSKd51xT1lbR2oYXCemKWZhw7rbPRQM+OfBMm4OB9+TIP3OhmINZ+7CGaUn8 zA9imY+5AUKzY2yS3h4NgheBmTTKoFnfX+FdJv766hr00C6zUG4vfs877N4hRQh60nfEY8AIGp ATjI7Y4D/4+/6OW6fVjGH91gykHaCod4CRLOjg7Pu7SqPALPsgBpjiHvUab4XV1Fi9+E+f6Uw4 J0r6XBIApYZJ72bTVQ2HQ8qS4f4QrKQA9jg+ilaUJjBp/08/KfEc0LlHpFMRAPfa5Qj4HKMJPV N/U= Date: Thu, 30 Sep 2021 20:09:14 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: Add C2X _PRINTF_NAN_LEN_MAX Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3124.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" C2X adds a macro _PRINTF_NAN_LEN_MAX to , 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. --- Any comments on this patch, especially the choice of whether to define the macro only for C2X or unconditionally? diff --git a/NEWS b/NEWS index 6bc98873ab..da1e3a5cd3 100644 --- a/NEWS +++ b/NEWS @@ -42,6 +42,8 @@ Major new features: * The __STDC_IEC_60559_BFP__ and __STDC_IEC_60559_COMPLEX__ macros are predefined as specified in TS 18661-1:2014. +* The ISO C2X macro _PRINTF_NAN_LEN_MAX has been added to . + Deprecated and removed features, and other changes affecting compatibility: * The r_version update in the debugger interface makes the glibc binary diff --git a/libio/stdio.h b/libio/stdio.h index 497da016ff..0a5c76b552 100644 --- a/libio/stdio.h +++ b/libio/stdio.h @@ -133,6 +133,12 @@ typedef __fpos64_t fpos64_t; #include +#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. */ diff --git a/manual/stdio.texi b/manual/stdio.texi index fd7ed0cedc..1d235be68d 100644 --- a/manual/stdio.texi +++ b/manual/stdio.texi @@ -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: