Name
cabs - Calculates the absolute value of a complex number.
Syntax
#include <math.h>
double cabs(z)
struct complex {
double x; /* Real component */
double y; /* Imaginary component */
} z;
Description
The cabs function calculates the absolute value of a complex
number, which must be a structure of type complex. A call to
cabs is equivalent to the following:
sqrt(z.x * z.x + z.y * z.y)
Return Value
On overflow, cabs calls matherr, returns HUGE_VAL, and sets
errno to ERANGE.
See Also
abs(S), fabs(S), labs(DOS)
Example
#include <math.h> #include <stdio.h>
main() {
struct complex number;
double d;
number.x = 3.0;
number.y = 4.0;
d = cabs(number);
printf("The absolute value of 'number' is %f\n", d);
}
Using cabs, this program assigns the absolute value of
complex number value to d.
(printed 6/18/89)