C atan() Function

Definition
In C, atan() returns the angle whose tangent is x. The angle is in radians, between -π/2 and π/2. atan(0) is 0, and atan(1) is π/4.
You pass one double. Any real number is allowed. The result is a double in radians, not degrees. Include <math.h>.
Syntax
Pass any real number. Start with this call.
| Call | What it does |
|---|
atan(1.0) | Returns π/4, the angle whose tangent is 1. |
Include <math.h>. On GCC, link with -lm. The result is radians. For a point (x, y), use atan2().
Library declarations
double atan(double x);
float atanf(float x);
long double atanl(long double x);
Parameters
| Parameter | Description |
|---|
| x | Required. Any real double. |
Return Value
| Return Value | Description |
|---|
| Radians | The angle between -π/2 and π/2 whose tangent is x. |
C Examples
Example 1 — Common atan Values
Print radians for a few familiar tangent ratios.
#include <math.h>
#include <stdio.h>
int main(void) {
printf("atan(0) = %.4f\n", atan(0.0));
printf("atan(1) = %.4f\n", atan(1.0));
printf("atan(-1) = %.4f\n", atan(-1.0));
return 0;
}
atan(0) = 0.0000
atan(1) = 0.7854
atan(-1) = -0.7854
How It Works
- Include math.h. Declares
atan; link with -lm on GCC. - Zero stays zero.
atan(0) is the angle with tangent 0. - Unit slope.
atan(1) is π/4 radians (45°). - Odd function. Negative ratios give negative angles:
atan(-1) = -atan(1).
Example 2 — Convert Radians to Degrees
Multiply by 180 / π when you want a degree reading.
#include <math.h>
#include <stdio.h>
int main(void) {
double x = 1.0;
double rad = atan(x);
double pi = acos(-1.0);
double deg = rad * 180.0 / pi;
printf("atan(%.1f) = %.4f rad\n", x, rad);
printf(" = %.2f deg\n", deg);
return 0;
}
atan(1.0) = 0.7854 rad
= 45.00 degHow It Works
- Get radians first.
atan(1) ≈ 0.7854. - Get π portably.
acos(-1.0) equals π without needing M_PI. - Scale to degrees. Multiply by
180.0 / pi → 45. - Keep rad for math. Pass radians into
tan/sin; use degrees only for display.
Example 3 — Angle of a Slope
A slope is rise over run. Feed that ratio to atan to get the inclination angle.
#include <math.h>
#include <stdio.h>
int main(void) {
double rise = 3.0;
double run = 4.0;
double slope = rise / run;
double rad = atan(slope);
double deg = rad * 180.0 / acos(-1.0);
printf("slope = %.2f\n", slope);
printf("angle = %.2f deg\n", deg);
return 0;
}
slope = 0.75
angle = 36.87 deg
How It Works
- Build the ratio.
3 / 4 = 0.75 is the tangent of the angle. - Call atan. That returns the angle in radians.
- Convert for display. Degrees are easier to read for people.
- Need a full plane? With signed
x and y, switch to atan2(y, x).
Frequently Asked Questions
atan() returns the angle, in radians, whose tangent is x. atan(1) is π/4.
x is required. Any real double is allowed.
A double in radians, between -π/2 and π/2.
Include <math.h>. On GCC, link with -lm.
Use atan2(y, x) when you have both coordinates and need the correct quadrant.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful