This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/48874] New: Sign of zeros sometimes lost in literals
- From: "jb at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 4 May 2011 15:58:11 +0000
- Subject: [Bug c/48874] New: Sign of zeros sometimes lost in literals
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48874
Summary: Sign of zeros sometimes lost in literals
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: jb@gcc.gnu.org
Consider
#include <stdio.h>
#include <complex.h>
int main()
{
double _Complex a = 0.0 + I*0.0;
double _Complex b = 0.0 - I*0.0;
double _Complex c = -0.0 + I*0.0;
double _Complex d = -0.0 - I*0.0;
printf("a= (%g,%g)\n", creal(a), cimag(a));
printf("b= (%g,%g)\n", creal(b), cimag(b));
printf("c= (%g,%g)\n", creal(c), cimag(c));
printf("d= (%g,%g)\n", creal(d), cimag(d));
}
This program, compiled with "gcc zero1.c -O2 -pedantic -Wall -std=c99" (or
-std=gnu99) prints
a= (0,0)
b= (0,-0)
c= (0,0)
d= (-0,-0)
That is, the sign of the real part of "c" is lost. Add -fdump-tree-original to
the compile flags shows the dump as
;; Function main (null)
;; enabled by -tree-original
{
complex double a = __complex__ (0.0, 0.0);
complex double b = __complex__ (0.0, -0.0);
complex double c = __complex__ (0.0, 0.0);
complex double d = __complex__ (-0.0, -0.0);
complex double a = __complex__ (0.0, 0.0);
complex double b = __complex__ (0.0, -0.0);
complex double c = __complex__ (0.0, 0.0);
complex double d = __complex__ (-0.0, -0.0);
printf ((const char * restrict) "a= (%g,%g)\n", REALPART_EXPR <a>,
IMAGPART_EXPR <a>);
printf ((const char * restrict) "b= (%g,%g)\n", REALPART_EXPR <b>,
IMAGPART_EXPR <b>);
printf ((const char * restrict) "c= (%g,%g)\n", REALPART_EXPR <c>,
IMAGPART_EXPR <c>);
printf ((const char * restrict) "d= (%g,%g)\n", REALPART_EXPR <d>,
IMAGPART_EXPR <d>);
}
return 0;
so it seems the negative sign of the real part of c is lost already in the
frontend.
Version of the compiler:
gcc version 4.7.0 20110504 (experimental) (GCC)
Target: x86_64-unknown-linux-gnu