- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP tan() Function
Definition and Usage
The tan() function returns the tangent ratio of given angle in radians. In trigonometry, tangent of an angle is defined as ratio of lengths of opposite side and adjacent side.
tan(x) = opposite/adjacent
tangent of an angle is also defined as ratio of its sine and cosine
tan(x) = sin(x)/cos(x)
If x=45 degree, tan(x) = 1 as in a right angled traingle, opposite and adjacent sides are qual.
This function returns a float value.
Syntax
tan ( float $arg ) : float
Parameters
Sr.No | Parameter & Description |
---|---|
1 | arg A floating point value that represents angle in radians |
Return Values
PHP tan() function returns tangent ratio of given parameter.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example calculates tan(pi/2) and returns 1.6331239353195E+16 (very large number). tngent ratio of 90 deg is infinity −
<?php $arg=M_PI/2; //90 degree $val=tan($arg); echo "tan(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
tan(1.5707963267949) = 1.6331239353195E+16
Example
Following example uses deg2rad() function to convert degrees to radians and then computes tan(60). Result is 1.7320508075689 which is sqrt(3) −
<?php $arg=deg2rad(60); $val=tan($arg); echo "tan(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
tan(1.0471975511966) = 1.7320508075689
Example
Let's check find out tan(45) degrees. It returns 1 −
<?php $arg=M_PI/4; //45 deg $val=tan($arg); echo "tan(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
tan(0.78539816339745) = 1
Example
Following example computes tan(0) and returns 0
<?php $arg=0; $val=tan($arg); echo "tan(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
tan(0) = 0