| Types and the imaginary constant | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
| Manipulation | |||||||||||||||||||||||||||||||
| Power and exponential functions | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
| Trigonometric functions | |||||||||||||||||||||||||||||||
| Hyperbolic functions | |||||||||||||||||||||||||||||||
Defined in header <complex.h> | ||
| (1) | (since C99) | |
| (2) | (since C99) | |
| (3) | (since C99) | |
Defined in header <tgmath.h> | ||
#define sqrt( z ) | (4) | (since C99) |
z with branch cut along the negative real axis.z 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 |
| z | - | complex argument |
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.)
Errors are reported consistent withmath_errhandling
If the implementation supports IEEE floating-point arithmetic,
z is±0+0i, the result is+0+0iz isx+∞i, the result is+∞+∞i even if x is NaNz isx+NaNi, the result isNaN+NaNi (unless x is ±∞) andFE_INVALID may be raisedz is-∞+yi, the result is+0+∞i for finite positive yz is+∞+yi, the result is+∞+0i) for finite positive yz is-∞+NaNi, the result isNaN±∞i (sign of imaginary part unspecified)z is+∞+NaNi, the result is+∞+NaNiz isNaN+yi, the result isNaN+NaNi andFE_INVALID may be raisedz isNaN+NaNi, the result isNaN+NaNi#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
(C99)(C99)(C99) | computes the complex power function (function)[edit] |
(C99)(C99) | computes square root (\(\small{\sqrt{x} }\)√x) (function)[edit] |
C++ documentation forsqrt | |