MySQL ATAN() Function
MySQL ATAN() Function: Computing Arctangent with One or Two Arguments
The ATAN() function returns the arc tangent (inverse tangent) of one or two numbers in MySQL. Unlike ASIN() and ACOS(), ATAN() accepts any real number without domain bounds.
With one argument ATAN(x), it returns an angle in radians between -PI()/2 and PI()/2. With two arguments ATAN(y, x), it computes the angle of coordinates (x, y) across all four quadrants from -PI() to PI().
Syntax
ATAN(x)
ATAN(y, x)
x: Any numeric expression for the single-argument form.y, x: Two numeric expressions whereycomes first andxcomes second.
Practical Example
Suppose demo_employees logs field technician displacement (delta_y, delta_x) from a service depot. You can inspect both the single-slope angle and the full-quadrant bearing in degrees.
SELECT
employee_id,
full_name,
delta_y,
delta_x,
ROUND(ATAN(delta_y / NULLIF(delta_x, 0)), 4) AS single_arg_rad,
ROUND(DEGREES(ATAN(delta_y, delta_x)), 2) AS full_bearing_deg
FROM demo_employees
WHERE employee_id IN (11, 12, 13);
| employee_id | full_name | delta_y | delta_x | single_arg_rad | full_bearing_deg |
|---|---|---|---|---|---|
| 11 | Nora Patel | 10 | 10 | 0.7854 | 45.00 |
| 12 | Leo Vance | -10 | -10 | 0.7854 | -135.00 |
| 13 | Mia Chen | 10 | 0 | NULL | 90.00 |
Notice the difference on row 12: dividing -10 / -10 gives +1, so 1-argument ATAN() returns 45 degrees. Two-argument ATAN(-10, -10) preserves both signs and returns -135.00 degrees.
Common Mistakes & NULL Behavior
- Swapping Y and X in 2-arg form:
ATAN(y, x)expects the vertical coordinateyfirst and horizontalxsecond, matchingATAN2(y, x). Reversing them rotates your bearing by 90 degrees. - Dividing before calling ATAN(): Computing
ATAN(y / x)fails onx = 0and loses quadrant signs. PreferATAN(y, x)whenever both components exist. - NULL propagation: If either argument in
ATAN(y, x)isNULL, MySQL returnsNULL.
Frequently Asked Questions
What happens when I pass zero to ATAN(0, 0)?
In MySQL, ATAN(0, 0) does not error or return NULL. It returns 0 radians cleanly.
How does 2-argument ATAN(y, x) differ from ATAN2(y, x)?
They behave identically in MySQL and produce the exact same result for all valid numbers, including signs across quadrants.
Can ATAN(x) return NULL for large numbers?
No. Any finite real number is valid for ATAN(x), so only NULL inputs (or non-numeric errors in strict mode) produce NULL.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.