Friday, December 20, 2024

MySQL TAN() Function

 The TAN() function in MySQL is used to return the tangent of an angle, which is expressed in radians. The formula for the tangent of an angle is:

tan(θ)=sin(θ)cos(θ)\tan(\theta) = \frac{\sin(\theta)}{\cos(\theta)}

Syntax:

TAN(angle)
  • angle: The angle in radians for which you want to calculate the tangent.

Example:

SELECT TAN(PI()/4); 

This will return the tangent of π4\frac{\pi}{4} radians (which is 1).

Notes:

  • The input to TAN() must be in radians. If you have an angle in degrees, you can convert it to radians using the RADIANS() function.
  • If you input 0, TAN(0) will return 0.
  • If you input PI()/2 (90 degrees), the tangent will result in a very large number (as it approaches infinity). Similarly, for angles like -PI()/2, TAN() can return a large negative number.

Example with degrees:

To convert degrees to radians and find the tangent:

SELECT TAN(RADIANS(45));  -- Returns 1, since tan(45 degrees) = 1

No comments:

Post a Comment