##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# I

From cppreference.com
< c‎ | numeric‎ | complex

Defined in header `<complex.h>` |  |
#define I /* unspecified */ |  | (since C99)

The `I` macro expands to either Complex_I or Imaginary_I. If the implementation does not support imaginary types, then the macro always expands to Complex_I.

| This section is incomplete Reason: on what condition imaginary types are supported? The standard seems unclear. Maybe when __STDC_IEC_559_COMPLEX__ is defined?

A program may undefine and perhaps then redefine the imaginary macro.

### [edit] Example

Run this code

    #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("I = %.1f%+.1fi\n", creal(I), cimag(I));
        printf("sizeof(I) = %zu\n", sizeof(I));
        printf("sizeof(_Complex_I) = %zu\n", sizeof(_Complex_I));

        double complex z = 1.0 + 2.0*I;
        printf("z = %.1f%+.1fi\n", creal(z), cimag(z));

        return 0;
    }

Output:

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

### [edit] See also

Imaginary_I (C99) | the imaginary unit constant i (macro constant) [edit]
Complex_I (C99) | the complex unit constant i (macro constant) [edit]
CMPLX CMPLXF CMPLXL (C11)(C11)(C11) | constructs a complex number from real and imaginary parts (function macro) [edit]
C++ documentation for operator""i

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/numeric/complex/I&oldid=71234"
Category:

- Todo with reason