PHP tanh() Function

PHPServer Side ProgrammingProgramming

Definition and Usage

The tanh() function returns the hyperbolic tangent ratio of given angle in radians. In trigonometry, hyperbolic tangent ratio is defined as.

tanh(x) = sinh()/tanh()

This function returns a float value .

Syntax

tanh ( float $arg ) : float

Parameters

Sr.NoParameter & Description
1arg
A floating point value that represents angle in radians

Return Values

PHP tanh() function returns hyperbolic 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 tanh(pi/2) and returns 2.5091784786581 which is also the result of formula (ex + e-x))/2 −

<?php
   $arg=M_PI_2;
   $res=tanh($arg);
   echo "tanh(pi) = " . $res . "\n";
   echo "using formula = " . sinh($arg)/cosh($arg);
?>

Output

This will produce following result −

tanh(pi) = 0.91715233566727
using formula = 0.91715233566727

Example

 Live Demo

Following example uses deg2rad() function to convert degrees to radians and then uses tanh(60). Result is 0.78071443535927 −

<?php
   $arg=deg2rad(60);
   $val=tanh($arg);
   echo "tanh(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

tanh(1.0471975511966) = 0.78071443535927

Example

 Live Demo

Let's check find out tanh(0). It returns 0 −

<?php
   $arg=0;
   $val=tanh($arg);
   echo "tanh(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

tanh(0) = 0

Example

 Live Demo

Following example computes tanh(pi) which is approximately equal to 0

<?php
   $arg=M_PI;
   $val=tanh($arg);
   echo "tanh(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

tanh(3.1415926535898) = 0.99627207622075
raja
Published on 30-Jun-2020 11:04:05
Advertisements