Namespaces
Variants

_Complex_I

From cppreference.net
Definiert in Header <complex.h>
#define _Complex_I /* unspecified */
(seit C99)

Das _Complex_I Makro expandiert zu einem Wert vom Typ const float _Complex mit dem Wert der imaginären Einheit.

Inhaltsverzeichnis

Hinweise

Dieses Makro kann verwendet werden, wenn I nicht verfügbar ist, beispielsweise wenn es durch die Anwendung undefiniert wurde.

Im Gegensatz zu _Imaginary_I und CMPLX kann die Verwendung dieses Makros zur Konstruktion einer komplexen Zahl das Vorzeichen der Null im Imaginärteil verlieren.

Beispiel

#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 number
    double complex 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 preserved
    double complex z2 = 0.0 + -0.0 * _Complex_I;
    printf("0.0 + -0.0 * _Complex_I = %.1f%+.1fi\n", creal(z2), cimag(z2));
}

Mögliche Ausgabe:

1.0 + 2.0 * _Complex_I = 1.0+2.0i
0.0 + -0.0 * _Complex_I = 0.0+0.0i

Referenzen

  • C23-Standard (ISO/IEC 9899:2024):
  • 7.3.1/4 _Complex_I (S.: TBD)
  • C17-Standard (ISO/IEC 9899:2018):
  • 7.3.1/4 _Complex_I (S: 136)
  • C11-Standard (ISO/IEC 9899:2011):
  • 7.3.1/4 _Complex_I (S: 188)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.3.1/2 _Complex_I (S: 170)

Siehe auch

die imaginäre Einheitskonstante i
(Makrokonstante)
(C99)
die komplexe oder imaginäre Einheitskonstante i
(Makrokonstante)