6.2.6 cabs Function
Calculates the complex absolute value of a double precision complex value.
Attention: This function is implemented only by MPLAB XC32 C
compilers.
Include
<complex.h>
Prototype
double complex cabs(double complex z);
Argument
z
- value for which to return the complex absolute value
Return Value
Returns the complex absolute value (also known as the magnitude, modulus, or norm) of
z
.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <stdio.h>
#include <complex.h>
int main(void)
{
double complex x, y;
x = -2.0 + 1.0*I;
y = cabs(x);
printf("The complex absolute value of %f + %fi is %f + %fi\n", creal(x), cimag(x), creal(y), cimag(y));
}
Example Output
The complex absolute value of -2.000000 + 1.000000i is 2.236068 + 0.000000i