Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with 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, the value
                    HUGE_VAL is returned and  'errno' (defined in
                    <errno.h>) is set to ERANGE (defined in <math.h>).

         Notes:     You can modify error handling with the matherr()
                    routine.

                    If <math.h> is included and #undef cabs() has not
                    been added to <math.h>, then cabs() will be treated
                    as a macro.

   -------------------------------- 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