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

Reply via email to