ne*****@tokyo.c om (Mantorok Redgormor) wrote:
With what specifier do I use to print a variable of a complex type?
The man page for printf doesn't even say.
Unfortunately there is no printf format conversion specifier for
printing complex numbers directely, but ISO/IEC 9899:1999 says:
6.2.5 Types
[...]
13 Each complex type has the same representation and alignment
requirements as an array type containing exactly two elements of the
corresponding real type; the first element is equal to the real part,
and the second element to the imaginary part, of the complex number.
[...]
Thus you can printf the value of an object of complex type like an array
of 2 of the underlying real type, for example:
#include <stdio.h>
#include <complex.h>
int main( void )
{
double complex cmplvar = 5.0 + 3.0 * I;
printf ("cmplvar = %f+%fi\n", cmplvar[0], cmplvar[1] );
return 0;
}
Untested code; the implementation at hand doesn't support complex types.
HTH
Regards
--
Irrwahn
(ir*******@free net.de)