PHP tan() Function

PHPServer Side ProgrammingProgramming

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.NoParameter & Description
1arg
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

 Live Demo

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

 Live Demo

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

 Live Demo

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

 Live Demo

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
raja
Published on 30-Jun-2020 11:01:07
Advertisements