Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <b>cabs() calculate absolute value of complex number</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
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 */
         }

See Also: abs() fabs() labs()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson