compute the absolute value of a complex number
#include <math.h>
double cabs( struct _complex value );
struct _complex {
double x; /* real part */
double y; /* imaginary part */
};
The cabs() function computes the absolute value of the complex number value, by a calculation that's equivalent to
sqrt( (value.x*value.x) + (value.y*value.y) )
In certain cases, overflow errors may occur, which will cause the matherr() routine to be invoked.
The absolute value.
#include <stdio.h>
#include <math.h>
struct _complex c = { -3.0, 4.0 };
void main()
{
printf( "%f\n", cabs( c ) );
}
produces the output:
5.000000
WATCOM
| Safety: | |
|---|---|
| Interrupt handler | No |
| Signal handler | No |
| Thread | Yes |