Lesson

MySQL TAN() Function

10 min reading
Free Course

MySQL TAN() Function: Calculating Trigonometric Tangents

The TAN() function returns the tangent of an angle specified in radians (SIN(x) / COS(x)). It returns a DOUBLE floating-point number for valid numeric inputs.

Engineers use TAN() to compute slope grades from elevation angles, projection offsets in mapping tiles, and triangulation heights. Because MySQL expects radians, degree angles must pass through RADIANS() first.

Syntax

TAN(x)
  • x: Numeric expression representing an angle in radians.

Practical Example

Suppose demo_employees logs warehouse loading dock ramp angles (incline_deg) and horizontal ramp lengths (run_meters). You can calculate the vertical rise height using run_meters * TAN(RADIANS(incline_deg)).

SELECT
    employee_id,
    dock_code,
    incline_deg,
    run_meters,
    ROUND(run_meters * TAN(RADIANS(incline_deg)), 2) AS rise_meters
FROM demo_employees
WHERE dock_code IS NOT NULL;
employee_id dock_code incline_deg run_meters rise_meters
51 DOCK-1 15.0 10.0 2.68
52 DOCK-2 45.0 4.0 4.00
53 DOCK-3 0.0 8.0 0.00

At 45.0 degrees (PI()/4 radians), TAN(RADIANS(45)) equals 1, so a 4.0-meter run rises 4.00 meters.

Common Mistakes & NULL Behavior

  • Using degrees without RADIANS(): Calling TAN(45) returns 1.6198 (tangent of 45 radians), not 1.0. Always wrap degree values with RADIANS().
  • Calling TAN(PI() / 2): Mathematically, tangent approaches infinity at 90 degrees (PI() / 2). In MySQL, because PI() is a finite DOUBLE, TAN(PI() / 2) does not error—it returns a huge number (1.633123935319537e16). Filter out 90-degree angles before multiplying.
  • NULL inputs: Passing NULL to TAN(NULL) returns NULL.

Frequently Asked Questions

Does TAN(PI() / 2) raise an error in MySQL?

No. Due to finite floating-point representation of PI(), COS(PI() / 2) is tiny (6.12e-17) rather than exact 0, so TAN(PI() / 2) returns a very large DOUBLE instead of an error.

How do I reverse TAN() back into an angle?

Pass the tangent ratio into ATAN(ratio) to get radians, or DEGREES(ATAN(ratio)) to recover degrees.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
MySQL Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum