| Types and the imaginary constant | ||||||||||||||||
| ||||||||||||||||
| Manipulation | ||||||||||||||||
| Power and exponential functions | ||||||||||||||||
| Trigonometric functions | ||||||||||||||||
| Hyperbolic functions | ||||||||||||||||
Defined in header <complex.h> | ||
#define _Complex_I /* unspecified */ | (since C99) | |
The_Complex_I macro expands to a value of typeconstfloat _Complex with the value of the imaginary unit.
Contents |
This macro may be used whenI is not available, such as when it has been undefined by the application.
Unlike_Imaginary_I andCMPLX, use of this macro to construct a complex number may lose the sign of zero on the imaginary part.
#include <stdio.h>#include <complex.h> #undef I#define J _Complex_I // can be used to redefine I int main(void){// can be used to construct a complex numberdoublecomplex z=1.0+2.0* _Complex_I;printf("1.0 + 2.0 * _Complex_I = %.1f%+.1fi\n",creal(z),cimag(z)); // sign of zero may not be preserveddoublecomplex z2=0.0+-0.0* _Complex_I;printf("0.0 + -0.0 * _Complex_I = %.1f%+.1fi\n",creal(z2),cimag(z2));}
Possible output:
1.0 + 2.0 * _Complex_I = 1.0+2.0i0.0 + -0.0 * _Complex_I = 0.0+0.0i
(C99) | the imaginary unit constant i (macro constant)[edit] |
(C99) | the complex or imaginary unit constant i (macro constant)[edit] |