cabs() Calculate Absolute Value of Complex Number
#include <math.h>
double cabs(z); Absolute value
struct complex z; Contains real and imaginary parts
cabs() returns the absolute value of the complex number 'z'. The
structure 'complex' (defined in <math.h>) is:
struct complex {
double x,y; /*real and imaginary parts */
};
A call to cabs() is equivalent to the statement:
sqrt(z.x * z.x + z.y * z.y);
Returns: Absolute value of 'z'. On overflow, matherr() is called
with an OVERFLOW error; 'errno' (defined in <stdlib.h>)
is set to ERANGE (defined in <math.h>), and the value
HUGE is returned.
Notes: Error handling can be modified by using the matherr()
routine.
-------------------------------- Example ---------------------------------
The following statements calculate the absolute value of a complex
number with a real part of 5.0 and an imaginary part of 12.0.
#include <math.h> /* for cabs() and struct complex */
main()
{
struct complex z;
double a;
z.x = 5.0; /* set real part of 'z' */
z.y = 12.0; /* set imaginary part of 'z' */
a = cabs(z); /* x = 13.0 */
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster