This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]