public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/30789]  New: complex folding inexact
@ 2007-02-13 18:31 jsm28 at gcc dot gnu dot org
  2008-06-01 21:55 ` [Bug middle-end/30789] " steven at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2007-02-13 18:31 UTC (permalink / raw)
  To: gcc-bugs

The constant folding of arithmetic on complex numbers is inexact and doesn't
support any of the C99 special cases and avoiding overflow done in libgcc.

Compile and run the following testcase with -std=c99.

#include <float.h>

int printf (const char *, ...);

#define C1 (DBL_MAX * 0.5 + DBL_MAX * 0.5i)
#define C2 (DBL_MAX * 0.25 + DBL_MAX * 0.25i)

_Complex double c1 = C1;
_Complex double c2 = C2;
_Complex double c = C1 / C2;

int
main (void)
{
  _Complex double cr = c1 / c2;
  printf ("%f %f\n%f %f\n", __real__ c, __imag__ c, __real__ cr, __imag__ cr);
  return 0;
}

It prints:

nan nan
2.000000 0.000000

That is, the libgcc code handled the division correctly, the folding allowed it
to overflow.

It should be reasonably straightforward to fold complex multiplication exactly
using MPFR: compute ac and bd with results in double the input precision, then
compute ac-bd with result in the original input precision (so rounding just
once to that precision) and similarly with the imaginary part.  Getting
division exact (correctly rounded) may be trickier, but doing better than at
present should be straightforward (simply by taking advantage of the greater
exponent range in MPFR).  The folding code also needs to handle the C99 Annex G
special cases like the libgcc code does.


-- 
           Summary: complex folding inexact
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jsm28 at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30789


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2009-12-06 16:11 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-13 18:31 [Bug middle-end/30789] New: complex folding inexact jsm28 at gcc dot gnu dot org
2008-06-01 21:55 ` [Bug middle-end/30789] " steven at gcc dot gnu dot org
2009-07-21 17:21 ` ghazi at gcc dot gnu dot org
2009-07-26 17:32 ` joseph at codesourcery dot com
2009-08-12 22:28 ` ghazi at gcc dot gnu dot org
2009-08-13  1:25 ` joseph at codesourcery dot com
2009-08-14  5:59 ` ghazi at gcc dot gnu dot org
2009-08-14 16:45 ` ghazi at gcc dot gnu dot org
2009-08-24 14:43 ` ghazi at gcc dot gnu dot org
2009-08-24 16:59 ` joseph at codesourcery dot com
2009-08-31  3:05 ` ghazi at gcc dot gnu dot org
2009-09-20 15:39 ` ghazi at gcc dot gnu dot org
2009-09-20 16:08 ` ghazi at gcc dot gnu dot org
2009-12-06 16:11 ` ghazi at gcc dot gnu dot org

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).