cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cmath (math.h) : atan2
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cmath (math.h)
functions:
· acos
· asin
· atan
· atan2
· ceil
· cos
· cosh
· exp
· fabs
· floor
· fmod
· frexp
· ldexp
· log
· log10
· modf
· pow
· sin
· sinh
· sqrt
· tan
· tanh
macro constants:
· HUGE_VAL

-

atan2 function
     double atan2 (      double y,      double x );
long double atan2 ( long double y, long double x );
      float atan2 (       float y,       float x );
<cmath>

Compute arc tangent with two parameters

Returns the principal value of the arc tangent of y/x, expressed in radians.

To compute the value, the function uses the sign of both arguments to determine the quadrant.

Parameters

y
Floating point value representing an y-coordinate.
x
Floating point value representing an x-coordinate.
If both arguments passed are zero, a domain error occurs, which sets the global variable ERRNO to the EDOM value.

Return Value

Principal arc tangent of y/x, in the interval [-pi,+pi] radians.

Portability

In C, only the double version of this function exists with this name.

Example

/* atan2 example */
#include <stdio.h>
#include <math.h>

#define PI 3.14159265

int main ()
{
  double x, y, result;
  x = -10.0;
  y = 10.0;
  result = atan2 (y,x) * 180 / PI;
  printf ("The arc tangent for (x=%lf, y=%lf) is %lf degrees\n", x, y, result );
  return 0;
}

Output:


The arc tangent for (x=-10.000000, y=10.000000) is 135.000000 degrees.

See also

atan Compute arc tangent (function)
tan Compute tangent (function)
sin Compute sine (function)
cos Compute cosine (function)
© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us