In C99, there is a complex
type. Include complex.h
; you may need to link with -lm
on gcc. Note that Microsoft Visual C does not support complex
; if you need to use this compiler, maybe you can sprinkle in some C++ and use the complex
template.
I
is defined as the imaginary unit, and cexp
does exponentiation. Full code example:
#include <complex.h>
#include <stdio.h>
int main() {
complex x = cexp(-I);
printf("%lf + %lfi
", creal(x), cimag(x));
return 0;
}
See man 7 complex
for more information.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…