C++ Standard Library C++ STL Library

C++ <cmath> - tanh() Function



The C++ <cmath> tanh() function returns hyperbolic tangent of a value. The hyperbolic tangent of x is defined as:

tanh

where e is an Euler's number.

Syntax

double tanh (double x);
float tanh (float x);
long double tanh (long double x);
double tanh (double x);
float tanh (float x);
long double tanh (long double x);
//additional overloads for integral types
double tanh (T x);           

Parameters

x 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.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  cout<<tanh(0)<<"\n";
  cout<<tanh(2)<<"\n";
  cout<<tanh(4)<<"\n";
  return 0;
}

The output of the above code will be:

0
0.964028
0.999329

❮ C++ <cmath> Library