Calculates the inverse tangent of a quotient #include <math.h> double atan2 ( double y , double x ); float atan2f ( float y , float x ); (C99) long double atan2l ( long double y , long double x ); (C99) The atan2( ) function divides the first argument by the second and returns the arc tangent of the result, or arctan(y/x). The return value is given in radians, and is in the range -p atan2(y,x) p. The signs of x and y determine the quadrant of the result:
If both arguments are zero, then the function may incur a domain error. Example/* * Calculate an acute angle of a right triangle, given * the adjacent and opposite sides. */ #define PI 3.141593 #define DEG_PER_RAD (180.0/PI) double adjacent = 3.0; double opposite = 4.0; double angle = atan2( opposite, adjacent ) * DEG_PER_RAD; printf( "The acute angles of a 3-4-5 right triangle are %4.2f\xB0 " "and %4.2f\xB0.\n", angle, 90.0 - angle ); This code produces the following output: The acute angles of a 3-4-5 right triangle are 53.13° and 36.87°. See AlsoThe arc tangent function for a single argument: atan( ) |