C complex.h csqrt,csqrtf and csqrtl


The C <complex.h> csqrt,csqrtf and csqrtl function compute the square root of the complex number.The declaration of the function is given below.

1 double complex csqrt(double complex z);
2 float complex csqrtf(float complex z);
3 long double complex csqrtl(long double complex z);

All the three functions compute the same value,the only difference between them is in their return type:

i)The ‘csqrt’ return the square root of complex number as double complex type.
ii)The ‘csqrtf’ return the square root of complex number as float complex type and
iii)The ‘csqrtl’ return the square root of complex number as long double complex type.

Some points to note:

i) csqrt(z),csqrtf(z) and csqrtl(z) is same as computing √z or (z)½.

ii)The branch of the function cut along the negative real axis.

iii)The functions return the complex square root value, in the range of the right half-lane (including the imaginary axis).

double complex csqrt(double complex z);

Parameters:
z – The complex number whose square root is to be computed

Return type
double complex -The square root return as double type.

Code example

double complex c1=11.22 + I*44.44 ,
c2 ;

c2=csqrt( c1 ) ;

printf( “Real part of c2=%lf”, creal(c3) ) ;
printf( “\nImaginary part of c2=%lf”, cimag(c3) ) ;

Output in Code::Blocks,

Real part of c2=5.341091
Imaginary part of c2=4.160199






float complex csqrtf(float complex z);

This function return the square root as float type.

Parameters:
z – The complex number whose square root is to be computed

Return type
float complex -The square root return as float type.

Code example

float complex c1=11.22 + I*44.44 ,
c2 ;

c2=csqrtf( c1 ) ;

printf( “Real part of c2=%f”, crealf(c3) ) ;
printf( “\nImaginary part of c2=%f”, cimagf(c3) ) ;

Output in Code::Blocks,

Real part of c2=5.341091
Imaginary part of c2=4.160199

Link : C complex.h creal,crealf and creall
Link : C complex.h cimag,cimagf and cimagl


long double complex csqrtl(long double complex z);

This function return the square root as long double type.

Parameters:
z – The complex number whose square root is to be computed

Return type
long double complex -The square root return as long double type.

Code example

long double complex c1=11.22 + I*44.44 ,
c2 ;

c2=csqrtl( c1 ) ;

printf( “Real part of c2=%Lf”, creall(c3) ) ;
printf( “\nImaginary part of c2=%Lf”, cimagl(c3) ) ;

Output in Code::Blocks,

Real part of c2=5.341091
Imaginary part of c2=4.160199


*Side Note

Some facts about csqrt,csqrtf and csqrtl

  ➥csqrt(conj(z))=conj(csqrt(z)).

  ➥csqrt(±0 + i0) returns +0+i0.

  ➥csqrt(x + i∞) returns +∞+i∞,for all x(including NaN)

  ➥csqrt(x + iNaN) returns NaN+iNaN and optionally raises the invalid floating-point exception, for finite x.

  ➥csqrt(−∞ + iy) returns +0+i∞,for finite positive-signed y.

  ➥csqrt(+∞ + iy) returns +∞+i0, for finite positive-signed y.

  ➥csqrt(−∞ + iNaN) returns NaN±i∞ (where the sign of the imaginary part of the result is unspecified).

  ➥csqrt(+∞ + iNaN) returns +∞+iNaN.

  ➥csqrt(NaN + iy) returns NaN+iNaN and optionally raises the invalid floating-point exception, for finite y.

  ➥csqrt(NaN + iNaN) returns NaN+iNaN.

Link :C complex.h conj,conjf and conjl