public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jacob at jacob dot remcomp.fr" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-107370-4-KYaKotfzXz@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107370-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107370

--- Comment #15 from jacob navia <jacob at jacob dot remcomp.fr> ---
> Le 24 oct. 2022 à 22:21, jakub at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org> a écrit :
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107370
> 
> --- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> I have to agree with Joseph (on x86_64-linux I get):
> #define _GNU_SOURCE
> #include <stdlib.h>
> #include <stdio.h>
> 
> int
> main ()
> {
>  volatile _Float128 x = __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 = 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 = 0x1.6a09e667f3bcc908b2fb1366dc6dp+0f128;
>  strfromf128 (buf, 128, "%a", x);
>  strfromf128 (buf + 128, 128, "%.36f", x);
>  printf ("%s\t%s\n", buf, buf + 128);
>  x = x * x; places.

>  strfromf128 (buf, 128, "%a", x);
>  strfromf128 (buf + 128, 128, "%.36f", x);
>  printf ("%s\t%s\n", buf, buf + 128);
> }
> 
> 0x1.6a09e667f3bcc908b2fb1366ea95p+0     1.414213562373095048801688724209697984
> 0x1.ffffffffffffffffffffffffffffp+0     1.999999999999999999999999999999999807
> 0x1.6a09e667f3bcc908b2fb1366dc6dp+0     1.414213562373095048801688724209000027
> 0x1.ffffffffffffffffffffffffd7f4p+0     1.999999999999999999999999999998025537
> 
> 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.
> 
> -- 
> 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
                      ^^^^^ 
In ANOTHER example:
#include <stdio.h>
#include <math.h>

int main(void) { printf("%.30Lg \n",sqrtl(powl(2,225))); }

This produces:
7.34301663720716943338259962711e+33
But bc produces 
~/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'. 
scale=32
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

  parent reply	other threads:[~2022-10-24 20:50 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-24  6:11 [Bug c/107370] New: long double precision is wrong in ARM 64 jacob at jacob dot remcomp.fr
2022-10-24  6:22 ` [Bug c/107370] " jacob at jacob dot remcomp.fr
2022-10-24 15:19 ` [Bug target/107370] " pinskia at gcc dot gnu.org
2022-10-24 18:33 ` jacob at jacob dot remcomp.fr
2022-10-24 18:40 ` [Bug middle-end/107370] long double sqrtl constant folding is wrong pinskia at gcc dot gnu.org
2022-10-24 19:27 ` jakub at gcc dot gnu.org
2022-10-24 19:53 ` jacob at jacob dot remcomp.fr
2022-10-24 19:56 ` jacob at jacob dot remcomp.fr
2022-10-24 20:00 ` joseph at codesourcery dot com
2022-10-24 20:01 ` jacob at jacob dot remcomp.fr
2022-10-24 20:08 ` jacob at jacob dot remcomp.fr
2022-10-24 20:09 ` jacob at jacob dot remcomp.fr
2022-10-24 20:21 ` jakub at gcc dot gnu.org
2022-10-24 20:25 ` jakub at gcc dot gnu.org
2022-10-24 20:32 ` jakub at gcc dot gnu.org
2022-10-24 20:50 ` jacob at jacob dot remcomp.fr [this message]
2022-10-24 20:51 ` jacob at jacob dot remcomp.fr
2022-10-24 20:56 ` jacob at jacob dot remcomp.fr
2022-10-24 20:59 ` jacob at jacob dot remcomp.fr
2022-10-24 21:01 ` jacob at jacob dot remcomp.fr
2022-10-24 21:02 ` jakub at gcc dot gnu.org
2022-10-24 21:03 ` jacob at jacob dot remcomp.fr
2022-10-24 21:06 ` jacob at jacob dot remcomp.fr
2022-10-24 21:09 ` jakub at gcc dot gnu.org
2022-10-24 21:26 ` jacob at jacob dot remcomp.fr
2022-10-24 21:29 ` pinskia at gcc dot gnu.org
2022-10-24 21:31 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107370-4-KYaKotfzXz@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).