Name | Description | Notes | Source | Availability | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
_Imaginary |
Type specifier for imaginary types | L | ? | Q | Keyword | C99 | C11 | ||||
_Imaginary_I |
Square root of −1 | ? | M | <complex.h> |
C99 | C11 | |||||
imaginary |
Modifier for imaginary types | ? | M | Q | <complex.h> |
C99 | C11 |
An imaginary number is the product of a real number and √−1. A C implementation may support imaginary types, and you can test for them with:
#if __STDC_VERSION__ >= 199901L && !defined __STDC_NO_ #includeCOMPLEX__ <complex.h>
#ifdef imaginary /* Imaginary types supported */ #endif #endif
Also note that, if __STDC_
is defined, imaginary types must also be available.
Imaginary types are identified by the type specifier
_Imaginary
:
float _Imaginary
, whose corresponding real type isfloat
,double _Imaginary
, whose corresponding real type isdouble
,long double _Imaginary
, whose corresponding real type islong double
,
If imaginary types are supported, the header <complex.h>
defines
the following:
#define imaginary _Imaginary
…allowing the use of the following names:
float imaginary
as an alias forfloat _Imaginary
double imaginary
as an alias fordouble _Imaginary
long double imaginary
as an alias forlong double _Imaginary
The macro _Imaginary_I
is defined to be a constant expression of type float imaginary
with the value
√−1. An imaginary constant (or a complex constant with an
imaginary value) is created just by multiplying a real
constant by _Imaginary
:
float imaginary var = _Imaginary * 4.0;
It's also possible to use I
, which might yield a complex
constant, but with a zero real part, so an imaginary type can
still represent it:
float imaginary var = I * 4.0;
That's my understanding of Annex G, which says
There are three imaginary types…
and An
implementation that defines
.__STDC_
shall conform to the specifications in this
annex
The sum of an imaginary number plus a real number is a complex number. Complex numbers can be represented by complex types, and they can represent all real values of a floating-point type, as well as all imaginary values of an imaginary type.