PHP Function Reference

PHP tanh() Function



The PHP tanh() function returns hyperbolic tangent of a value. The hyperbolic tangent of x is defined as:

tanh

where e is an Euler's number.

In special cases it returns the following:

  • If the argument is NAN, then the result is NAN.
  • If the argument is positive infinity, then the result is +1.0.
  • If the argument is negative infinity, then the result is -1.0.

Syntax

tanh(number)

Parameters

number Required. Specify the value.

Return Value

Returns the hyperbolic tangent of a value.

Example:

In the example below, tanh() function is used to find out the hyperbolic tangent of a value.

<?php
echo "tanh(-2) = ".tanh(-2)."\n";
echo "tanh(-1) = ".tanh(-1)."\n";
echo "tanh(0) = ".tanh(0)."\n";
echo "tanh(1) = ".tanh(1)."\n";
echo "tanh(2) = ".tanh(2)."\n";
echo "tanh(INF) = ".tanh(INF)."\n";
echo "tanh(-INF) = ".tanh(-INF)."\n";
echo "tanh(NAN) = ".tanh(NAN)."\n";
?>

The output of the above code will be:

tanh(-2) = -0.96402758007582
tanh(-1) = -0.76159415595576
tanh(0) = 0
tanh(1) = 0.76159415595576
tanh(2) = 0.96402758007582
tanh(INF) = 1
tanh(-INF) = -1
tanh(NAN) = NAN

❮ PHP Math Reference