The atan() function computes the arc tangent (inverse tangent) of a number. Given a slope or tangent ratio, it returns the angle in radians whose tangent equals that value—ideal for line angles, ramps, and graphics.
01
Inverse tan
Angle from slope.
02
math.h
Link with -lm.
03
Any real x
Full domain.
04
Range
[−π/2, π/2].
05
Radians out
Not degrees.
06
vs atan2
Quadrants.
Fundamentals
Definition and Usage
atan (arc tangent) answers: “What angle has this tangent?” If tan(θ) = x, then atan(x) = θ (in radians, principal value).
On a right triangle, tangent is opposite ÷ adjacent (rise over run). If a hill rises 3 units for every 4 units forward, the slope is 3/4 and atan(3.0/4.0) gives the incline angle.
💡
Beginner Tip
The input x is a ratio (tangent value), not an angle. The output is the angle in radians. For a point (x, y) in any quadrant, use atan2(y, x) instead.
atan(rise/run) converts a slope ratio into an angle. This pattern appears in road grades, roof pitch, and 2D game rotation when you know vertical and horizontal displacement.
Example 4 — Verify atan() with tan()
Inverse and forward tangent undo each other on valid inputs.
C
#include <stdio.h>
#include <math.h>
int main(void) {
double values[] = { -2.0, -0.5, 0.0, 0.5, 2.0 };
size_t i;
for (i = 0; i < sizeof values / sizeof values[0]; i++) {
double x = values[i];
double angle = atan(x);
double back = tan(angle);
printf("x=%5.1f atan(x)=%.4f tan(atan(x))=%.6f\n",
x, angle, back);
}
return 0;
}
Point A (4, -3):
atan(y/x) = -0.64 rad
atan2(y,x) = -0.64 rad
Point B (-4, 3):
atan(y/x) = -0.64 rad
atan2(y,x) = 2.50 rad
How It Works
atan(y/x) loses quadrant information. atan2(y, x) uses both signs to return the correct angle in (−π, π]. Learn more on the atan2() tutorial page.
Applications
🚀 Common Use Cases
Line and slope angles — convert rise/run into an incline angle.
2D graphics — rotation from a known tangent when quadrant is fixed.
Robotics — heading adjustments from velocity component ratios.
Geometry — find angles in right triangles via opposite/adjacent.
Pair with tan() — forward and inverse tangent operations.
🧠 How atan() Works
1
Receive ratio x
Any real tangent value (slope) is accepted.
Input
2
Invert tangent
Find θ such that tan(θ) = x.
Compute
3
Principal value
Return angle in [−π/2, π/2].
Range
=
📐
Angle in radians
Use with tan(), rotation, or degree conversion.
Important
📝 Notes
Input x is a tangent ratio, not an angle in radians.
Output is in [−π/2, π/2] radians—limited to one half of the circle.
For points in all four quadrants, use atan2(y, x) instead of atan(y/x).
Link with -lm when using GCC/Clang on Unix-like systems.
Use atanf or atanl for float or long double data.
Performance
⚡ Optimization
atan() is implemented in the platform math library and is already optimized. Prefer atan2(y, x) over atan(y/x) when you have separate coordinates—it avoids a division and handles x = 0 safely while preserving quadrant information.
Wrap Up
Conclusion
atan() turns a tangent ratio into an angle in radians. Remember the input is a slope, not an angle, and reach for atan2() when you need full-circle direction from (x, y).
Next up: atan2() for quadrant-aware angles, or explore tan() for the forward tangent function.
atan() returns the arc tangent (inverse tangent) of x—the angle in radians whose tangent equals x. For example, atan(1) is pi/4 (45 degrees) because tan(45°) = 1.
Include <math.h> and link with -lm on many systems: gcc program.c -o program -lm. The function is declared as double atan(double x).
No. The argument x is a tangent ratio (rise over run), not an angle. The return value is the angle in radians. The old misconception 'x in radians' is incorrect.
The result is always between -pi/2 and pi/2 radians (about -90° to 90°). atan(0) is 0; atan(1) is pi/4; atan(-1) is -pi/4.
atan(x) takes one ratio and returns an angle in [-pi/2, pi/2]. atan2(y, x) takes two coordinates, handles all four quadrants, and returns an angle in (-pi, pi]. Use atan2 for (x, y) direction vectors.
tan() takes an angle in radians and returns its tangent. atan() does the reverse: it takes a tangent value and returns the angle. They are inverse operations.
Did you know?
Because tangent is not one-to-one over all angles, atan() returns only the principal value between −90° and 90°. That is why two different directions in the plane can share the same y/x ratio but need different angles—atan2 was designed exactly for that job.