From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2F1BD385828F; Mon, 24 Oct 2022 20:50:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F1BD385828F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666644602; bh=/HI9M9t2RVHgGITCRnzxUlT+7WbqD9DuY+D49Pwx1NY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pe8yCcd9zbFSojaz/+pSJImIm1bkWb3Jz2bOKCluEZgrm3O/MCjQTEwJr6su3WHCi kJoDySs/0yOo/FHsDEVyUDKpXUvGI0MKTn6zriJT4jU7EfjmjMaRfpo3Ez2Wa4PLMN uz3bIemx2UW/C+o20DMSNKGnVTI+lOFdkEFSmark= From: "jacob at jacob dot remcomp.fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/107370] long double sqrtl constant folding is wrong Date: Mon, 24 Oct 2022 20:50:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jacob at jacob dot remcomp.fr X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107370 --- Comment #15 from jacob navia --- > Le 24 oct. 2022 =C3=A0 22:21, jakub at gcc dot gnu.org a =C3=A9crit : >=20 > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107370 >=20 > --- Comment #12 from Jakub Jelinek --- > I have to agree with Joseph (on x86_64-linux I get): > #define _GNU_SOURCE > #include > #include >=20 > int > main () > { > volatile _Float128 x =3D __builtin_sqrtf128(2.0f128); > char buf[256]; > strfromf128 (buf, 128, "%a", x); > strfromf128 (buf + 128, 128, "%.36f", x); > printf ("%s\t%s\n", buf, buf + 128); > x =3D x * x; > strfromf128 (buf, 128, "%a", x); > strfromf128 (buf + 128, 128, "%.36f", x); > printf ("%s\t%s\n", buf, buf + 128); > // The value you want to see > x =3D 0x1.6a09e667f3bcc908b2fb1366dc6dp+0f128; > strfromf128 (buf, 128, "%a", x); > strfromf128 (buf + 128, 128, "%.36f", x); > printf ("%s\t%s\n", buf, buf + 128); > x =3D x * x; places. > strfromf128 (buf, 128, "%a", x); > strfromf128 (buf + 128, 128, "%.36f", x); > printf ("%s\t%s\n", buf, buf + 128); > } >=20 > 0x1.6a09e667f3bcc908b2fb1366ea95p+0 1.4142135623730950488016887242096= 97984 > 0x1.ffffffffffffffffffffffffffffp+0 1.9999999999999999999999999999999= 99807 > 0x1.6a09e667f3bcc908b2fb1366dc6dp+0 1.4142135623730950488016887242090= 00027 > 0x1.ffffffffffffffffffffffffd7f4p+0 1.9999999999999999999999999999980= 25537 >=20 > Clearly the value GCC uses for sqrtf128(2.0f128) multiplied by itself is = 1ulp > smaller than 2.0, > while the value you want to see is 10252ulps smaller than 2.0. >=20 > --=20 > You are receiving this mail because: > You reported the bug. Sorry but the program I used was compiled with gcc. It suffers from lack of precision too. In ANY case, in decimal now, the square root of 2 is 1.414 213 562 373 095 048 801 688 724 209 698 078 GP PARI calculator 1.414 213 562 373 095 145 547 462 185 874 gcc: only the first 15 digits are= OK ^^^^^=20 In ANOTHER example: #include #include int main(void) { printf("%.30Lg \n",sqrtl(powl(2,225))); } This produces: 7.34301663720716943338259962711e+33 But bc produces=20 ~/lcc/book/test % bc bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'.=20 scale=3D32 sqrt(2^225) 7343016637207168931428032607349397.48923080385562326502615381523522 To make things clearer I put now the results side by side 7.34301663720716943338259962711e+33 gcc 734301663720716 8931428032607349397.48923080385562326502615381523522 bc As you can see, after the 15th digits all others are wrong!!! Jacob=