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>atan2() calculate arc tangent of y/x</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 atan2()                 Calculate Arc Tangent of y/x

 #include <math.h>

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

    atan2() returns the arc tangent of 'y'/'x' in radians.  The value
    returned is in the range -pi to pi.  'x' and 'y' cannot both be 0.0.

       Returns:     Arc tangent 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 <errno.h>) is set to EDOM (defined in
                    math.h); and 0.0 is returned.

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

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

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

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

           main()
           {
               double arc_tan;

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


See Also: atan() matherr() _matherr() sin() tan()

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