From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1105) id 3C59B3858D38; Mon, 3 Oct 2022 13:11:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C59B3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664802715; bh=Eti5/TNLyJb2DK8Unxt2ki1askhb/IUQNtQccxre+7U=; h=From:To:Subject:Date:From; b=ZsqrmLEBo/qWo3KiKDG8olH7HwjR8oqeskh1SjNL5ku5BC4JO69sqOgB0mcNHU4C+ 6D6ZQa4Sd/5LDtItq5AbvMnVCsZTUnj2/XcSnLvF5a1z8lO4aye+YoDmKpDKXhZTf4 TmY/lRqWP/s/vVLiOh5GG7cTa194t1U02ngJpNTk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Joseph Myers To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3029] c: Adjust LDBL_EPSILON for C2x for IBM long double X-Act-Checkin: gcc X-Git-Author: Joseph Myers X-Git-Refname: refs/heads/master X-Git-Oldrev: 866263a5fe0d657cb9ec06d01bbc100900159036 X-Git-Newrev: 53acc10ee81116536d4eb6fbba62a90f329b75ce Message-Id: <20221003131155.3C59B3858D38@sourceware.org> Date: Mon, 3 Oct 2022 13:11:55 +0000 (GMT) List-Id: https://gcc.gnu.org/g:53acc10ee81116536d4eb6fbba62a90f329b75ce commit r13-3029-g53acc10ee81116536d4eb6fbba62a90f329b75ce Author: Joseph Myers Date: Mon Oct 3 13:10:42 2022 +0000 c: Adjust LDBL_EPSILON for C2x for IBM long double 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: --- gcc/c-family/c-cppbuiltin.cc | 2 +- gcc/testsuite/gcc.dg/c11-float-7.c | 24 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/c2x-float-12.c | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) 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); +}