Calculate the absolute value of a complex number.
#include <math.h>
double _cabs( struct _complex z );
long double _cabsl( struct _complexl z );
z | Complex number |
The _cabs and _cabsl functions calculate the absolute value of a complex number, which must be a structure of type _complex (or _complexl). The structure z is composed of a real component x and an imaginary component y. A call to one of the _cabs routines is equivalent to the following:
sqrt( z.x*z.x + z.y*z.y )
The _cabsl function is the 80-bit counterpart and it uses the 80-bit, 10-byte coprocessor form of arguments and return values. See the reference page on the long double functions for more details on this data type.
On overflow, these functions call _matherr or _matherrl, return HUGE_VAL, and set errno to ERANGE.
_cabs
Standards:UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
Use _cabs for compatibility with ANSI naming conventions of non-ANSI functions. Use cabs and link with OLDNAMES.LIB for UNIX compatibility._cabsl
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
/* CABS.C: Using _cabs, this program calculates the absolute value of
* a complex number.
*/
#include <math.h>
#include <stdio.h>
void 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