Defined in header <complex.h> | ||||
---|---|---|---|---|
| (since C99) |
The _Imaginary_I
macro expands to a value of type const float _Imaginary
with the value of the imaginary unit.
As with any pure imaginary number support in C, this macro is only defined if the imaginary numbers are supported.
A compiler that defines | (since C99) (until C11) |
Imaginary numbers are supported if | (since C11) |
Notes
This macro allows for the precise way to assemble a complex number from its real and imaginary components, e.g. with (double complex)((double)x + _Imaginary_I * (double)y)
. This pattern was standardized in C11 as the macro CMPLX
. Note that if _Complex_I
is used instead, this expression is allowed to convert negative zero to positive zero in the imaginary position.
Example
1 2 3 4 5 6 7 8 | #include <stdio.h> #include <complex.h> int main( void ) { double complex z = 0.0 + -0.0 * _Imaginary_I; printf ( "z = %.1f%+.1fi\n" , creal(z), cimag(z)); } |
Output:
1 | z = 0.0-0.0i |
References
- C11 standard (ISO/IEC 9899:2011):
- 7.3.1/5 _Imaginary_I (p: 188)
- G.6/1 _Imaginary_I (p: 537)
- C99 standard (ISO/IEC 9899:1999):
- 7.3.1/3 _Imaginary_I (p: 170)
- G.6/1 _Imaginary_I (p: 472)
See also
(C99) | the complex unit constant i (macro constant) |
(C99) | the complex or imaginary unit constant i (macro constant) |
Please login to continue.