Name

csqrt

Synopsis

Calculates the square root of a complex number

#include <complex.h>
double complexcsqrt( double complex z );
float complex csqrtf( float complex z );
long double complex csqrtl( long double complex z );

The csqrt() function returns the complex square root of its complex number argument.

Example

double complex z = 1.35 − 2.46 * I;
double complex c, d;

c =csqrt( z );
d = c * c;

printf("If the square root of %.2f %+.2f \xD7 I equals %.2f %+.2f \xD7 I,"
       "\n", creal(z), cimag(z), creal(c), cimag(c) );
printf("then %.2f %+.2f \xD7 I squared should equal %.2f %+.2f \xD7 I.\n",
       creal(c), cimag(c), creal(d), cimag(d) );

This code produces the following output:

If the square root of 1.35 -2.46 × I equals 1.44 -0.85 × I,
then 1.44 -0.85 × I squared should equal 1.35 -2.46 × I.

See Also

cexp(), clog(), cpow(), csqrt()

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.