# C Programming/complex.h/carg

(Redirected from C Programming/C Reference/complex.h/carg)

## PrototypesEdit

```double carg(double complex z);
float cargf(float complex z);
long double cargl(long double complex z);
```

## DescriptionEdit

carg is a standard library function which calculates the argument (phase angle) of a complex number. It takes a single parameter and returns the phase angle of that value (converted if necessary to a complex number) within the range [π, −π].

This function takes a single parameter of type complex and returns a result of type double.

A complex number can be represented:

• in rectangular co-ordinates as ${\displaystyle Z=A+Bi}$
• in polar co-ordinates as ${\displaystyle z=re^{ia}}$

where:

• A = creal(Z) is the real part
• B = cimag(Z) is the imaginary part
• r = cabs(z) is the radius
• a = carg(z) is the phase (angle or the argument)

Hence this function returns phase of complex number Z used in polar co-ordinates. The return value is in radians, in the range [π, -π]. When we use this function, we must include the <complex.h> header file.

## SynopsisEdit

[1]

```#include <complex.h>
double carg(double complex z);
float cargf(float complex z);
long double cargl(long double complex z);
```

## Example 1Edit

``` /* conversion of a real number from its Cartesian to polar form */

#include <stdio.h>
#include <complex.h>

int main() {
double complex z = -4.4 + 3.3 * I;
double x = creal(z);
double y = cimag(z);

double radius = cabs(z);
double argument = carg(z);

printf("cartesian(x, y): (%4.1f, %4.1f)\n", x, y);
printf("polar(r, theta): (%4.1f, %4.1f)\n", radius, argument);
return 0;
}
```

Output: [2]

``` Cartesian(x, y): (-4.4, 3.3)
polar(r, theta): (5.5, 2.5)
```