public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "carlos at redhat dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/95450] [10/11 regression] Wrong long double folding
Date: Tue, 11 Aug 2020 16:14:22 +0000	[thread overview]
Message-ID: <bug-95450-4-taTrOOPsNg@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-95450-4@http.gcc.gnu.org/bugzilla/>

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

Carlos O'Donell <carlos at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |carlos at redhat dot com

--- Comment #4 from Carlos O'Donell <carlos at redhat dot com> ---
(In reply to Andreas Schwab from comment #0)
> $ cat test-float.c
> #include <float.h>
> #include <assert.h>
> 
> union gl_long_double_union
>   {
>     struct { double hi; double lo; } dd;
>     long double ld;
>   };
> 
> const union gl_long_double_union gl_LDBL_MAX =
>   { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } };
> # undef LDBL_MAX
> # define LDBL_MAX (gl_LDBL_MAX.ld)
> 
> int
> main ()
> {
>   volatile long double m = LDBL_MAX;
> 
>   assert (m + m > m);
> }
> $ gcc -O2 test-float.c
> $ ./a.out
> a.out: test-float.c:20: main: Assertion `m + m > m' failed.
> Aborted
> 
> test-float.c.234t.optimized contains:
> 
>   m ={v} 1.79769313486231580793728971405302307166001572487e+308;
> 
> but that evaluates to Inf.  DBL_MAX is
> 1.79769313486231570814527423731704e+308L.

This comes from gnulib's use of lib/float.h.

My question is why is gnulib using float.h on power? What makes the system
float.h unsuable?

Even if you fix this for your package including gnulib, the next failure you
run into is this one:

test-float.c:324: assertion 'x + x == x' failed
Aborted (core dumped)

Extracting from the test case:

#include <stdio.h>
#include <assert.h>
#include <float.h>
#include <math.h>

int
main (void)
{
  int n = 107;
  volatile long double m = LDBL_MAX;
  volatile long double pow2_n = powl (2, n);
  volatile long double x = m + (m / pow2_n);

  printf ("n = %d\n", n);
  printf ("m = %Lf (%La)\n", m, m);
  printf ("pow2_n = %Lf (%La)\n", pow2_n, pow2_n);
  printf ("m / pow2_n = %Lf (%La)\n", (m / pow2_n), (m / pow2_n));
  printf ("x = %Lf (%La)\n", x, x);

  if (x > m)
    assert (x + x == x);
  return 0;
}

gcc -o ~/test-ldbl-max ~/test-ldbl-max.c -lm

~/test-ldbl-max
n = 107
m =
179769313486231580793728971405301199252069012264752390332004544495176179865349768338004270583473493681874097135387894924752516923758125018237039690323659469736010689648748751591634331824498526377862231967249520608291850653495428451067676993116107021027413767397958053860876625383538022115414866471826801819648.000000
(0x1.fffffffffffff7ffffffffffff8p+1023)
pow2_n = 162259276829213363391578010288128.000000 (0x1p+107)
m / pow2_n =
1107913932560222581216724223049124694376931327937918798971295069363205703164244740389102844506567402654244799528342026118673562844811584683014545030137100678976901567468093855075985516353544747282849589098225960074532039651619564827101237983225846137075291097947344654582153216.000000
(0x1.fffffffffffff7ffffffffffff8p+916)
x =
179769313486231580793728971405301199252069012264752390332004544495176179865349768338004270583473493681874097135387894924752516923758125018237039690323659469736010689648748751591634331824498526377862231967249520608291850653495428451067676993116107021027413767397958053860876625383538022115414866471826801819648.000000
(0x1.fffffffffffff7ffffffffffffcp+1023)
test-ldbl-max: /root/test-ldbl-max.c:21: main: Assertion `x + x == x' failed.
Aborted (core dumped)

Is this just a function of double double?

That there is something representable that is larger than LDBL_MAX, but isn't
valid given the double-double rules?

  parent reply	other threads:[~2020-08-11 16:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-31 12:51 [Bug target/95450] New: [10 " schwab@linux-m68k.org
2020-06-02  7:32 ` [Bug target/95450] [10/11 " rguenth at gcc dot gnu.org
2020-06-02  8:34 ` schwab@linux-m68k.org
2020-07-23  6:51 ` rguenth at gcc dot gnu.org
2020-08-11 16:14 ` carlos at redhat dot com [this message]
2020-08-11 16:17 ` mpolacek at gcc dot gnu.org
2020-08-11 16:19 ` jakub at gcc dot gnu.org
2020-08-11 16:46 ` jakub at gcc dot gnu.org
2020-08-11 16:54 ` jakub at gcc dot gnu.org
2020-08-11 17:26 ` jakub at gcc dot gnu.org
2020-08-25  5:18 ` cvs-commit at gcc dot gnu.org
2020-08-25 17:45 ` cvs-commit at gcc dot gnu.org
2020-08-25 18:25 ` jakub 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-95450-4-taTrOOPsNg@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).