C in a Nutshell (In a Nutshell (OReilly))

csqrt

Calculates the square root of a complex number

#include <complex.h> double complex csqrt ( 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 x I equals 1.44 -0.85 x I, then 1.44 -0.85 x I squared should equal 1.35 -2.46 x I.

See Also

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

Категории