Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>atan2() calculate arctangent of y/x</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 atan2()                 Calculate Arctangent of y/x

 #include <math.h>

 double     atan2(y,x);                  Arctangent (in radians)
 double     y;                           y coordinate value
 double     x;                           x coordinate value

    atan2() returns the arctangent of 'y'/'x' in radians.  The return
    value will be in the range -pi to pi.  'x' and 'y' cannot both be
    0.0.

    Returns:    Arctangent of y/x.  If both x and y are 0.0, then
                matherr() is called with a DOMAIN error; a domain error
                message is printed to 'stderr'; 'errno' (defined in
                <stdlib.h>) is set to EDOM (defined in math.h), and 0.0
                is returned.

      Notes:    Error handling can be modified with the matherr()
                routine.


   -------------------------------- Example ---------------------------------

    The following statements print the arctangent of 20.0/0.0 and try to
    calculate the arctangent of 0.0/0.0, which causes an EDOM error.

           #include <math.h>        /* for atan2() and EDOM */
           #include <stdio.h>       /* for printf() */
           #include <stdlib.h>      /* for errno */

           main()
           {
               double arc_tan;

               arc_tan = atan2(20.0, 0.0);  /* arc_tan = pi/2 (1.570796) */
               printf("arctangent of 20/0 is %.6f radians\n", arc_tan);
               errno = 0;
               arc_tan = atan2(0.0, 0.0);  /* arc_tan=0.0, causes an error */
               /* a DOMAIN error message is also printed to stderr */
               if (errno == EDOM)
                   printf("DOMAIN error in atan2()\n");
           }


See Also: acos() asin() atan() cos() matherr() sin() tan()

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