
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library function - atan2()
Description
The C library function double atan2(double y, double x) returns the arc tangent in radians of y/x based on the signs of both values to determine the correct quadrant.
Declaration
Following is the declaration for atan2() function.
double atan2(double y, double x)
Parameters
x − This is the floating point value representing an x-coordinate.
y − This is the floating point value representing a y-coordinate.
Return Value
This function returns the principal arc tangent of y/x, in the interval [-pi,+pi] radians.
Example
The following example shows the usage of atan2() function.
#include <stdio.h> #include <math.h> #define PI 3.14159265 int main () { double x, y, ret, val; x = -7.0; y = 7.0; val = 180.0 / PI; ret = atan2 (y,x) * val; printf("The arc tangent of x = %lf, y = %lf ", x, y); printf("is %lf degrees\n", ret); return(0); }
Let us compile and run the above program that will produce the following result −
The arc tangent of x = -7.000000, y = 7.000000 is 135.000000 degrees
math_h.htm
Advertisements