PHP atan() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

The PHP atan() function returns the arc tangent of a number, which is the angle whose tangent is that number.

The result is in radians and is always between -pi/2 and pi/2, and any number is allowed as input.

Syntax

Call atan() with the values you need. Start with this line.

PHP
$angle = atan($num);
CallWhat it does
atan(0)Returns 0 because tan(0) is 0.
atan(1)Returns about 0.7854 (pi / 4, or 45 degrees).
atan(-1)Returns about -0.7854.

atan() only sees a single number, so it cannot tell which quarter of the circle you are in. Use atan2() when you have x and y.

Library declarations
PHP
atan(float $num): float

Parameters

ParameterDescription
numRequired. The tangent value (for example a slope). Any real number, including INF, is allowed.

Return Value

Return ValueDescription
floatThe arc tangent of $num in radians, between -pi/2 and pi/2.

PHP Examples

Example 1 — Basic atan() usage

This example prints the arc tangent of zero, one and minus one.

PHP
<?php
echo atan(0) . PHP_EOL;
echo round(atan(1), 4) . PHP_EOL;
echo round(atan(-1), 4) . PHP_EOL;
echo round(atan(0.5), 4) . PHP_EOL;

How It Works

  1. atan(0) is 0 because the tangent of 0 is 0.
  2. atan(1) is pi / 4, which rounds to 0.7854.
  3. atan(-1) is the negative of atan(1), so it is -0.7854.
  4. atan(0.5) is about 0.4636 radians, which is smaller because the slope is gentler.

Example 2 — Infinity as input

Tangent grows without limit near 90 degrees, so atan() levels off at pi/2 when you give it INF.

PHP
<?php
echo round(atan(INF), 4) . PHP_EOL;
echo round(atan(-INF), 4) . PHP_EOL;
echo round(atan(1000000), 4) . PHP_EOL;

How It Works

  1. atan(INF) approaches pi / 2, which rounds to 1.5708.
  2. atan(-INF) approaches -pi / 2, which is -1.5708.
  3. A very big number like 1000000 is already extremely close to pi / 2.
  4. This is why atan() never goes beyond the range -pi/2 to pi/2.

Example 3 — Slope to angle in degrees

If you know the slope of a line, atan() can turn it into an angle in degrees.

PHP
<?php
$slopes = [0.5, 1, 2];

foreach ($slopes as $slope) {
    $degrees = rad2deg(atan($slope));
    echo "Slope $slope = " . round($degrees, 2) . " degrees" . PHP_EOL;
}

How It Works

  1. The $slopes array holds three slope values.
  2. For each slope, atan() returns the angle in radians.
  3. rad2deg() converts that angle into degrees.
  4. round(..., 2) keeps two decimals, so a slope of 1 gives exactly 45 degrees.

Frequently Asked Questions

It returns the arc tangent of a number as a float in radians, between -pi/2 and pi/2.
atan() takes one value and cannot tell the quadrant. atan2() takes y and x separately and returns the full angle from -pi to pi.
Yes. atan(INF) returns pi / 2 and atan(-INF) returns -pi / 2.
Use rad2deg(atan($value)). For example, rad2deg(atan(1)) is 45.
Only when the input itself is NAN. All other numbers give a valid result.

Next: atan2()

atan2() function returns the angle, in radians, between the positive x-axis and the point .

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.

8 people found this page helpful