cabs(), cabsf(), cabsl() — Calculate the complex absolute value

Standards

Standards / Extensions C or C++ Dependencies

C99
Single UNIX Specification, Version 3

both

z/OS V1R7
a compiler that is designed
to support C99

Format

#include <complex.h>

double cabs(double complex z);
float cabsf(float complex z);
long double cabsl(long double complex z);

General description

The cabs() family of functions compute the complex absolute value (also called norm, modules, or magnitude) of z.
Note: The following table shows the viable formats for these functions. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.
Function Hex IEEE
cabs X X
cabsf X X
cabsl X X

Returned value

The cabs functions return the complex absolute value.

Example

/*
 * This example calculates the complex absolute 
 * value of complex number 'z' 
 */
#include <complex.h>
#include <stdio.h>

void main()
{
   double complex z=3.5 + I*2.21;
   double res;

   res = cabs(z);
   printf("cabs(%f + I*%f) = %f\n",creal(z), cimag(z),res);
}
	
/*
 * Output:
 * cabs(3.5 + I*2.21) = 4.139336
 */

Related information