From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 472753858D38 for ; Mon, 3 Oct 2022 13:12:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 472753858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.93,365,1654588800"; d="scan'208";a="84017439" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 03 Oct 2022 05:12:13 -0800 IronPort-SDR: nxP0lLfhfe20FHcQ6gFZmxeYbzjOB7zMaJmyL/kA1bxOwpkLlS27pSQw1nEFyc4Wi7G2womJkf gGxnl/7ntB52rTCP9+EMgJEC/DnMhUdwGi6rR7TTzYj0B1G8nNiwOA2unJ3yp4nvo8hT/HUJGc pNVlDVDM2IfSuEbz79GtNBnEr+3giG1Choc4vIAd0KtVfA/c3hjOvO73pYpJ3RsTHJZRkFcgn4 DgVpXFVQsahkomzP34XpWpd1CoNI+EGCLnbdewIzFDWS7hH45o4ZqjZmFjSwAJDcwCRVzIayYR Vrs= Date: Mon, 3 Oct 2022 13:12:04 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: [committed] c: Adjust LDBL_EPSILON for C2x for IBM long double Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3116.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,KAM_SHORT,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: C2x changes the definition of *_EPSILON to apply only to normalized numbers. The effect is that LDBL_EPSILON for IBM long double becomes 0x1p-105L instead of 0x1p-1074L. There is a reasonable case for considering this a defect fix - it originated from the issue reporting process (DR#467), though it ended up being resolved by a paper (N2326) for C2x rather than through the issue process, and code using *_EPSILON often needs to override the pre-C2x value of LDBL_EPSILON and use something on the order of magnitude of the C2x value instead. However, I've followed the conservative approach of only making the change for C2x and not for previous standard versions (and not for C++, which doesn't have the C2x changes in this area). The testcases added are intended to be valid for all long double formats. The C11 one is based on gcc.target/powerpc/rs6000-ldouble-2.c (and when we move to a C2x default, gcc.target/powerpc/rs6000-ldouble-2.c will need an appropriate option added to keep using an older language version). Tested with no regressions for cross to powerpc-linux-gnu. gcc/c-family/ * c-cppbuiltin.cc (builtin_define_float_constants): Do not special-case __*_EPSILON__ setting for IBM long double for C2x. gcc/testsuite/ * gcc.dg/c11-float-7.c, gcc.dg/c2x-float-12.c: New tests. diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc index d4de5a0dc57..4b8486c8879 100644 --- a/gcc/c-family/c-cppbuiltin.cc +++ b/gcc/c-family/c-cppbuiltin.cc @@ -279,7 +279,7 @@ builtin_define_float_constants (const char *name_prefix, /* The difference between 1 and the least value greater than 1 that is representable in the given floating point type, b**(1-p). */ sprintf (name, "__%s_EPSILON__", name_prefix); - if (fmt->pnan < fmt->p) + if (fmt->pnan < fmt->p && (c_dialect_cxx () || !flag_isoc2x)) /* This is an IBM extended double format, so 1.0 + any double is representable precisely. */ sprintf (buf, "0x1p%d", fmt->emin - fmt->p); diff --git a/gcc/testsuite/gcc.dg/c11-float-7.c b/gcc/testsuite/gcc.dg/c11-float-7.c new file mode 100644 index 00000000000..a8a7ef5bc33 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-float-7.c @@ -0,0 +1,24 @@ +/* Test C11 definition of LDBL_EPSILON. Based on + gcc.target/powerpc/rs6000-ldouble-2.c. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + volatile long double ee = 1.0; + long double eps = ee; + while (ee + 1.0 != 1.0) + { + eps = ee; + ee = eps / 2; + } + if (eps != LDBL_EPSILON) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/c2x-float-12.c b/gcc/testsuite/gcc.dg/c2x-float-12.c new file mode 100644 index 00000000000..40900bd918a --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-12.c @@ -0,0 +1,19 @@ +/* Test C2x definition of LDBL_EPSILON. */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +#include + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + volatile long double x = 1.0L; + for (int i = 0; i < LDBL_MANT_DIG - 1; i++) + x /= 2; + if (x != LDBL_EPSILON) + abort (); + exit (0); +} -- Joseph S. Myers joseph@codesourcery.com