Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      csqrtf, csqrt, csqrtl

      From cppreference.com
      <c‎ |numeric‎ |complex
       
       
       
      Complex number arithmetic
      Types and the imaginary constant
      (C99)
      (C99)    
      (C11)
      (C99)
      Manipulation
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
      Power and exponential functions
      (C99)
      (C99)
      (C99)
      csqrt
      (C99)
      Trigonometric functions
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
      Hyperbolic functions
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
       
      Defined in header<complex.h>
      floatcomplex       csqrtf(floatcomplex z);
      (1)(since C99)
      doublecomplex      csqrt(doublecomplex z);
      (2)(since C99)
      longdoublecomplex csqrtl(longdoublecomplex z);
      (3)(since C99)
      Defined in header<tgmath.h>
      #define sqrt( z )
      (4)(since C99)
      1-3) Computes the complex square root ofz with branch cut along the negative real axis.
      4) Type-generic macro: Ifz has typelongdoublecomplex,csqrtl is called. ifz has typedoublecomplex,csqrt is called, ifz has typefloatcomplex,csqrtf is called. Ifz is real or integer, then the macro invokes the corresponding real function (sqrtf,sqrt,sqrtl). Ifz is imaginary, the corresponding complex number version is called.

      Contents

      [edit]Parameters

      z - complex argument

      [edit]Return value

      If no errors occur, returns the square root ofz, in the range of the right half-plane, including the imaginary axis ([0; +∞) along the real axis and(−∞; +∞) along the imaginary axis.)

      [edit]Error handling and special values

      Errors are reported consistent withmath_errhandling

      If the implementation supports IEEE floating-point arithmetic,

      • The function is continuous onto the branch cut taking into account the sign of imaginary part
      • csqrt(conj(z))==conj(csqrt(z))
      • Ifz is±0+0i, the result is+0+0i
      • Ifz isx+∞i, the result is+∞+∞i even if x is NaN
      • Ifz isx+NaNi, the result isNaN+NaNi (unless x is ±∞) andFE_INVALID may be raised
      • Ifz is-∞+yi, the result is+0+∞i for finite positive y
      • Ifz is+∞+yi, the result is+∞+0i) for finite positive y
      • Ifz is-∞+NaNi, the result isNaN±∞i (sign of imaginary part unspecified)
      • Ifz is+∞+NaNi, the result is+∞+NaNi
      • Ifz isNaN+yi, the result isNaN+NaNi andFE_INVALID may be raised
      • Ifz isNaN+NaNi, the result isNaN+NaNi

      [edit]Example

      Run this code
      #include <stdio.h>#include <complex.h> int main(void){doublecomplex z1= csqrt(-4);printf("Square root of -4 is %.1f%+.1fi\n",creal(z1),cimag(z1)); doublecomplex 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));}

      Output:

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

      [edit]References

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

      [edit]See also

      (C99)(C99)(C99)
      computes the complex power function
      (function)[edit]
      (C99)(C99)
      computes square root (\(\small{\sqrt{x} }\)x)
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/complex/csqrt&oldid=96381"

      [8]ページ先頭

      ©2009-2025 Movatter.jp