C atan() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

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.

C
atan(1.0);
CallWhat 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
C
double atan(double x);
float atanf(float x);
long double atanl(long double x);

Parameters

ParameterDescription
xRequired. Any real double.

Return Value

Return ValueDescription
RadiansThe angle between -π/2 and π/2 whose tangent is x.

C Examples

Example 1 — Common atan Values

Print radians for a few familiar tangent ratios.

C
#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;
}

How It Works

  1. Include math.h. Declares atan; link with -lm on GCC.
  2. Zero stays zero. atan(0) is the angle with tangent 0.
  3. Unit slope. atan(1) is π/4 radians (45°).
  4. 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.

C
#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;
}

How It Works

  1. Get radians first. atan(1) ≈ 0.7854.
  2. Get π portably. acos(-1.0) equals π without needing M_PI.
  3. Scale to degrees. Multiply by 180.0 / pi → 45.
  4. 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.

C
#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;
}

How It Works

  1. Build the ratio. 3 / 4 = 0.75 is the tangent of the angle.
  2. Call atan. That returns the angle in radians.
  3. Convert for display. Degrees are easier to read for people.
  4. 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.

Next: atan2()

Get a full-quadrant angle from two coordinates.

atan2() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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