Namespaces
Variants
Views
Actions

Complex_I

From cppreference.com
< c‎ | numeric‎ | complex
Defined in header <complex.h>
#define _Complex_I /* unspecified */
(since C99)

The _Complex_I macro expands to a value of type const float _Complex with the value of the imaginary unit.

[edit] Example

#include <stdio.h>
#include <complex.h>
 
int main(void)
{
    #ifdef __STDC_NO_COMPLEX__
            printf("__STDC_NO_COMPLEX__ is defined.\n");
    #else
        printf("__STDC_NO_COMPLEX__ is undefined.\n");
    #endif
 
    #ifdef __STDC_IEC_559_COMPLEX__
        printf("__STDC_IEC_559_COMPLEX__ is defined.\n");
    #else
        printf("__STDC_IEC_559_COMPLEX__ is undefined.\n");
    #endif
 
    printf("_Complex_I = %.1f%+.1fi\n", creal(_Complex_I), cimag(_Complex_I));
    printf("sizeof(_Complex_I) = %zu\n", sizeof(_Complex_I));
 
    double complex z = 1.0 + 2.0*_Complex_I;
    printf("z = %.1f%+.1fi\n", creal(z), cimag(z));
 
    return 0;
}

Output:

__STDC_NO_COMPLEX__ is undefined.
__STDC_IEC_559_COMPLEX__ is defined.
_Complex_I = 0.0+1.0i
sizeof(_Complex_I) = 8
z = 1.0+2.0i

[edit] See also

the imaginary unit constant i
(macro constant) [edit]
(C99)
the complex or imaginary unit constant i
(macro constant) [edit]