Python math.atan() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math module

Definition

math.atan(x) returns the arc tangent (inverse tangent) of x in radians, within [-pi / 2, pi / 2].

Unlike math.asin() and math.acos(), math.atan() accepts every real number including inf and -inf. When you have separate dy and dx coordinates, prefer math.atan2() to keep all four quadrants apart.

math.atan() is a function in Python's standard math module: import it with import math and call math.atan(...), or import the name directly with from math import atan.

Syntax

Import math and pass any slope or real number.

python
import math

angle_rad = math.atan(slope)
CallWhat it does
math.atan(0)Returns 0.0.
math.atan(1)Returns approximately 0.785398... (pi / 4).
math.atan(float("inf"))Returns approximately 1.570796... (pi / 2).
math.atan(float("-inf"))Returns approximately -1.570796... (-pi / 2).

Because (-dy) / (-dx) == dy / dx, calling atan(dy / dx) loses the quadrant sign and fails when dx == 0; use math.atan2(dy, dx) instead.

Function signatures
python
math.atan(x, /)
# returns: float arc tangent in [-pi/2, pi/2]

Parameters

ParameterDescription
xRequired positional real number (int or float), unrestricted range including infinities.

Return Value

Return ValueDescription
floatAngle in radians inside [-pi / 2, pi / 2]; returns nan for nan.

Python Examples

Example 1 — Compute Camera Field of View From Focal Length

Use 2 * math.degrees(math.atan(width / (2 * focal))) for camera lenses.

python
import math

sensor_mm = 36.0
for focal_mm in [24.0, 35.0, 50.0, 85.0]:
    fov = 2.0 * math.degrees(math.atan(sensor_mm / (2.0 * focal_mm)))
    print(f"{focal_mm:>4.0f}mm lens -> {fov:>5.2f} deg FOV")

How It Works

  1. Half-sensor right triangle. Half the sensor width divided by focal length gives the tangent of half the horizontal field angle.
  2. Double for full FOV. Multiplying the arc tangent by two converts half-angle into total horizontal view.
  3. Longer lenses narrow view. Stepping from 24mm wide angle to 85mm portrait narrows the view from 73.74 to 23.91 degrees.

Example 2 — See Why atan(y / x) Loses Opposite Quadrants

Compare math.atan(y / x) with math.atan2(y, x) on opposite points (1, 1) and (-1, -1).

python
import math

for y, x in [(1, 1), (-1, -1)]:
    a1 = math.degrees(math.atan(y / x))
    a2 = math.degrees(math.atan2(y, x))
    print(f"({y:>2}, {x:>2}) -> atan={a1:>5.1f} atan2={a2:>6.1f}")

How It Works

  1. Signs cancel in division. Dividing -1 / -1 yields 1.0, so atan() sees no difference from (1, 1).
  2. Both report 45.0. atan() collapses the third-quadrant point back into the first quadrant.
  3. atan2 preserves quadrant. Passing y and x separately gives the true -135.0 degree heading.

Example 3 — Verify Asymptotes at Infinity and Machin Pi Identity

Test atan(inf), atan(-inf), and check 4 * math.atan(1) against math.pi.

python
import math

print(math.atan(0))
print(math.isclose(4.0 * math.atan(1), math.pi))
print(round(math.degrees(math.atan(float("inf"))), 1))
print(round(math.degrees(math.atan(float("-inf"))), 1))

How It Works

  1. Origin stays zero. Zero slope gives 0.0 radians.
  2. Classic pi identity. Since tan(pi / 4) = 1, four times atan(1) matches math.pi.
  3. Asymptotes at ±90 degrees. Positive and negative infinity converge cleanly to 90.0 and -90.0 degrees.

Frequently Asked Questions

math.atan(x) takes one slope value and returns [-pi/2, pi/2]. math.atan2(y, x) takes two coordinates separately, handles x == 0 without division by zero, and returns the full [-pi, pi] range.
Not on real numbers or infinities. Unlike asin() and acos(), atan() accepts the entire real line plus inf and -inf.
math.pi / 2 (~1.5708 radians, or 90 degrees).
Wrap the call with math.degrees(math.atan(x)).
Because tan(pi / 4) is 1, so atan(1) is pi / 4.

Next: math.atan2()

Return atan(y / x) in radians using signs of both arguments.

atan2() →

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.

12 people found this page helpful