Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


Calculates the absolute value of a complex number.

double _cabs( 
   struct _complex z 


Complex number.

Return Value

_cabs returns the absolute value of its argument if successful. On overflow, _cabs returns HUGE_VAL and sets errno to ERANGE. You can change error handling with _matherr.


The _cabs function calculates the absolute value of a complex number, which must be a structure of type _complex. The structure z is composed of a real component x and an imaginary component y. A call to _cabs produces a value equivalent to that of the expression sqrt( z.x*z.x + z.y*z.y ).


Routine Required header Compatibility
_cabs <math.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// crt_cabs.c
/* Using _cabs, this program calculates
 * the absolute value of a complex number.
#include <math.h>
#include <stdio.h>

int main( void )
   struct _complex number = { 3.0, 4.0 };
   double d;

   d = _cabs( number );
   printf( "The absolute value of %f + %fi is %f\n",
           number.x, number.y, d );


The absolute value of 3.000000 + 4.000000i is 5.000000

See Also

Floating-Point Support Routines | abs | fabs | labs | Run-Time Routines and .NET Framework Equivalents

© 2016 Microsoft