Namespaces
Variants

csqrtf, csqrt, csqrtl

From cppreference.net
Definiert im Header <complex.h>
float complex csqrtf ( float complex z ) ;
(1) (seit C99)
double complex csqrt ( double complex z ) ;
(2) (seit C99)
long double complex csqrtl ( long double complex z ) ;
(3) (seit C99)
Definiert im Header <tgmath.h>
#define sqrt( z )
(4) (seit C99)
1-3) Berechnet die komplexe Quadratwurzel von z mit dem Verzweigungsschnitt entlang der negativen reellen Achse.
4) Typgenerisches Makro: Wenn z den Typ long double complex hat, wird csqrtl aufgerufen. Wenn z den Typ double complex hat, wird csqrt aufgerufen. Wenn z den Typ float complex hat, wird csqrtf aufgerufen. Wenn z reell oder ganzzahlig ist, ruft das Makro die entsprechende reelle Funktion auf ( sqrtf , sqrt , sqrtl ). Wenn z imaginär ist, wird die entsprechende komplexe Zahlenversion aufgerufen.

Inhaltsverzeichnis

Parameter

z - komplexes Argument

Rückgabewert

Wenn keine Fehler auftreten, wird die Quadratwurzel von z zurückgegeben, im Bereich der rechten Halbebene, einschließlich der imaginären Achse ( [0; +∞) entlang der reellen Achse und (−∞; +∞) entlang der imaginären Achse.)

Fehlerbehandlung und spezielle Werte

Fehler werden gemeldet konsistent mit math_errhandling

Wenn die Implementierung IEEE-Gleitkommaarithmetik unterstützt,

  • Die Funktion ist entlang des Verzweigungsschnitts stetig unter Berücksichtigung des Vorzeichens des Imaginärteils
  • csqrt ( conj ( z ) ) == conj ( csqrt ( z ) )
  • Wenn z ±0+0i ist, ist das Ergebnis +0+0i
  • Wenn z x+∞i ist, ist das Ergebnis +∞+∞i selbst wenn x NaN ist
  • Wenn z x+NaNi ist, ist das Ergebnis NaN+NaNi (sofern x nicht ±∞ ist) und FE_INVALID kann ausgelöst werden
  • Wenn z -∞+yi ist, ist das Ergebnis +0+∞i für endliches positives y
  • Wenn z +∞+yi ist, ist das Ergebnis +∞+0i) für endliches positives y
  • Wenn z -∞+NaNi ist, ist das Ergebnis NaN±∞i (Vorzeichen des Imaginärteils nicht spezifiziert)
  • Wenn z +∞+NaNi ist, ist das Ergebnis +∞+NaNi
  • Wenn z NaN+yi ist, ist das Ergebnis NaN+NaNi und FE_INVALID kann ausgelöst werden
  • Wenn z NaN+NaNi ist, ist das Ergebnis NaN+NaNi

Beispiel

#include <stdio.h>
#include <complex.h>
int main(void)
{
    double complex z1 = csqrt(-4);
    printf("Square root of -4 is %.1f%+.1fi\n", creal(z1), cimag(z1));
    double complex z2 = csqrt(conj(-4)); // or, in C11, CMPLX(-4, -0.0)
    printf("Square root of -4-0i, the other side of the cut, is "
           "%.1f%+.1fi\n", creal(z2), cimag(z2));
}

Ausgabe:

Square root of -4 is 0.0+2.0i
Square root of -4-0i, the other side of the cut, is 0.0-2.0i

Referenzen

  • C11-Standard (ISO/IEC 9899:2011):
  • 7.3.8.3 The csqrt functions (S. 196)
  • 7.25 Type-generic math <tgmath.h> (S. 373-375)
  • G.6.4.2 The csqrt functions (S. 544)
  • G.7 Type-generic math <tgmath.h> (S. 545)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.3.8.3 The csqrt functions (S. 178)
  • 7.22 Type-generic math <tgmath.h> (S. 335-337)
  • G.6.4.2 The csqrt functions (S. 479)
  • G.7 Type-generic math <tgmath.h> (S. 480)

Siehe auch

(C99) (C99) (C99)
berechnet die komplexe Potenzfunktion
(Funktion)
(C99) (C99)
berechnet Quadratwurzel ( x )
(Funktion)