Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

cabs - Absolute value of a complex number

&pagelevel(4)&pagelevel

Definition

#include <math.h>

double cabs(_ _complex z);

cabs calculates the absolute value of the complex number z with real part x and imaginary part y.

__complex is a type predefined in the header <math.h>:

#typdef struct{double x, y;} __complex

Return val.

sqrt(z.x * z.x + z.y * z.y)

i.e. the absolute value of the complex number z.

In the case of an overflow, the program aborts (signal SIGFPE)!

Example

The following program calculates the absolute value of a complex number.

#include <stdio.h>
#include <math.h>
int main(void)
{
 __complex z;
 if (scanf("%f %f", &z.x, &z.y) == 2)
     printf("%f : Absolute value\n", cabs(z));
 return 0;
}

See also

abs, fabs, labs, llabs, sqrt