Does casting a real number to complex number set the imaginary part to 0
in C? Here is what I am trying to do:
#include <complex.h>
#include <stdio.h>
int main(void){
float complex a;
double b = 1.0;
a = (float complex) b ; /* Does this convert to float and set
complex part of a to 0 (according to C standards) ?*/
a = (float) b ; /* If we also do this, does the compiler set the imaginary part to 0?
or we have to explicitly give b + 0.0f*I ?*/
printf("%f \n", cimagf(a));
return 0;
}
To be more specific, does it leave the imaginary part uninitialised (as a complex number is represented as two reals) ?
-0.0
. Interesting that C specifies for implementations with signed zero and the sign-less zero. – Unsuccessful