This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
complex arithmetic and signed zero?
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 12 Oct 2005 10:49:44 -0700
- Subject: complex arithmetic and signed zero?
How does one set z = 0 - I 0 in a portable manner with gcc?
My obvious attempts give surprising results.
#include <complex.h>
#include <math.h>
#include <stdio.h>
int main(void) {
double complex z;
double x, y;
x = 0.;
y = copysign(0, -1);
printf("%e %e\n", x, y);
/* __real__ and __imag__ aren't required by n1124.pdf. Not portable. */
__real__ z = x;
__imag__ z = y;
printf("%e %e\n", creal(z), cimag(z));
z = x + I * y;
printf("%e %e\n", creal(z), cimag(z));
z = I * y;
printf("%e %e\n", creal(z), cimag(z));
}
Using gcc 3.4.4
troutmask:kargl[219] ./z
0.000000e+00 -0.000000e+00
0.000000e+00 -0.000000e+00
0.000000e+00 0.000000e+00
-0.000000e+00 0.000000e+00
--
Steve